Module: Descope::Api::V1::Management::Audit

Includes:
Common
Included in:
Descope::Api::V1::Management
Defined in:
lib/descope/api/v1/management/audit.rb

Overview

Management API calls

Constant Summary

Constants included from Common

Common::ACCESS_KEYS_SEARCH_PATH, Common::ACCESS_KEY_ACTIVATE_PATH, Common::ACCESS_KEY_CREATE_PATH, Common::ACCESS_KEY_DEACTIVATE_PATH, Common::ACCESS_KEY_DELETE_PATH, Common::ACCESS_KEY_LOAD_PATH, Common::ACCESS_KEY_UPDATE_PATH, Common::AUDIT_CREATE_EVENT, Common::AUDIT_SEARCH, Common::AUTHZ_NS_DELETE, Common::AUTHZ_NS_SAVE, Common::AUTHZ_RD_DELETE, Common::AUTHZ_RD_SAVE, Common::AUTHZ_RE_CREATE, Common::AUTHZ_RE_DELETE, Common::AUTHZ_RE_DELETE_RESOURCES, Common::AUTHZ_RE_HAS_RELATIONS, Common::AUTHZ_RE_RESOURCE, Common::AUTHZ_RE_TARGETS, Common::AUTHZ_RE_TARGET_ALL, Common::AUTHZ_RE_WHO, Common::AUTHZ_SCHEMA_DELETE, Common::AUTHZ_SCHEMA_LOAD, Common::AUTHZ_SCHEMA_SAVE, Common::FLOW_EXPORT_PATH, Common::FLOW_IMPORT_PATH, Common::FLOW_LIST_PATH, Common::GROUP_LOAD_ALL_FOR_MEMBER_PATH, Common::GROUP_LOAD_ALL_GROUP_MEMBERS_PATH, Common::GROUP_LOAD_ALL_PATH, Common::PASSWORD_SETTINGS_PATH, Common::PERMISSION_CREATE_PATH, Common::PERMISSION_DELETE_PATH, Common::PERMISSION_LOAD_ALL_PATH, Common::PERMISSION_UPDATE_PATH, Common::PROJECT_CLONE, Common::PROJECT_DELETE_PATH, Common::PROJECT_EXPORT_PATH, Common::PROJECT_IMPORT_PATH, Common::PROJECT_UPDATE_NAME, Common::ROLE_CREATE_PATH, Common::ROLE_DELETE_PATH, Common::ROLE_LOAD_ALL_PATH, Common::ROLE_SEARCH_PATH, Common::ROLE_UPDATE_PATH, Common::SCIM_GROUPS_PATH, Common::SCIM_RESOURCE_TYPES_PATH, Common::SCIM_SERVICE_PROVIDER_CONFIG_PATH, Common::SCIM_USERS_PATH, Common::SSO_APPLICATION_DELETE_PATH, Common::SSO_APPLICATION_LOAD_ALL_PATH, Common::SSO_APPLICATION_LOAD_PATH, Common::SSO_APPLICATION_OIDC_CREATE_PATH, Common::SSO_APPLICATION_OIDC_UPDATE_PATH, Common::SSO_APPLICATION_SAML_CREATE_PATH, Common::SSO_APPLICATION_SAML_UPDATE_PATH, Common::SSO_CONFIGURE_OIDC_SETTINGS_PATH, Common::SSO_CONFIGURE_SAML_METADATA_PATH, Common::SSO_CONFIGURE_SAML_SETTINGS_PATH, Common::SSO_LOAD_SETTINGS_PATH, Common::SSO_MAPPING_PATH, Common::SSO_METADATA_PATH, Common::SSO_OIDC_PATH, Common::SSO_SETTINGS_PATH, Common::TENANT_CREATE_PATH, Common::TENANT_DELETE_PATH, Common::TENANT_LOAD_ALL_PATH, Common::TENANT_LOAD_PATH, Common::TENANT_SEARCH_ALL_PATH, Common::TENANT_UPDATE_PATH, Common::TEST_USERS_SEARCH_PATH, Common::TEST_USER_CREATE_PATH, Common::THEME_EXPORT_PATH, Common::THEME_IMPORT_PATH, Common::UPDATE_JWT_PATH, Common::USERS_SEARCH_PATH, Common::USER_ADD_ROLE_PATH, Common::USER_ADD_TENANT_PATH, Common::USER_CREATE_BATCH_PATH, Common::USER_CREATE_PATH, Common::USER_DELETE_ALL_TEST_USERS_PATH, Common::USER_DELETE_PATH, Common::USER_EXPIRE_PASSWORD_PATH, Common::USER_GENERATE_EMBEDDED_LINK_PATH, Common::USER_GENERATE_ENCHANTED_LINK_FOR_TEST_PATH, Common::USER_GENERATE_MAGIC_LINK_FOR_TEST_PATH, Common::USER_GENERATE_OTP_FOR_TEST_PATH, Common::USER_GET_PROVIDER_TOKEN, Common::USER_LOAD_PATH, Common::USER_LOGOUT_PATH, Common::USER_PATCH_PATH, Common::USER_REMOVE_ROLE_PATH, Common::USER_REMOVE_TENANT_PATH, Common::USER_SEARCH_PATH, Common::USER_SET_ACTIVE_PASSWORD_PATH, Common::USER_SET_PASSWORD_PATH, Common::USER_SET_TEMPORARY_PASSWORD_PATH, Common::USER_UPDATE_CUSTOM_ATTRIBUTE_PATH, Common::USER_UPDATE_EMAIL_PATH, Common::USER_UPDATE_LOGIN_ID_PATH, Common::USER_UPDATE_NAME_PATH, Common::USER_UPDATE_PATH, Common::USER_UPDATE_PHONE_PATH, Common::USER_UPDATE_PICTURE_PATH, Common::USER_UPDATE_STATUS_PATH

Instance Method Summary collapse

Methods included from Common

#associated_tenants_to_hash_array

Instance Method Details

#audit_create_event(action: nil, type: nil, data: nil, user_id: nil, actor_id: nil, tenant_id: nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/descope/api/v1/management/audit.rb', line 61

def audit_create_event(action: nil, type: nil, data: nil, user_id: nil, actor_id: nil, tenant_id: nil)
  # Create an audit event
  unless %w[info warn error].include?(type)
    raise Descope::AuthException, 'type must be either info, warn or error'
  end

  # validation
  raise Descope::AuthException, 'data must be provided as a key, value Hash' unless data.is_a?(Hash)
  raise Descope::AuthException, 'action must be provided' if action.nil?
  raise Descope::AuthException, 'actor_id must be provided' if actor_id.nil?
  raise Descope::AuthException, 'tenant_id must be provided' if tenant_id.nil?

  request_params = {
    action:,
    tenantId: tenant_id,
    type:,
    actorId: actor_id,
    data:
  }
  request_params[:userId] = user_id unless user_id.nil?

  post(AUDIT_CREATE_EVENT, request_params)
end

#audit_search(user_ids: nil, actions: nil, exclude_actions: nil, devices: nil, methods: nil, geos: nil, remote_addresses: nil, login_ids: nil, tenants: nil, no_tenants: false, text: nil, from_ts: nil, to_ts: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/descope/api/v1/management/audit.rb', line 11

def audit_search(
  user_ids: nil,
  actions: nil,
  exclude_actions: nil,
  devices: nil,
  methods: nil,
  geos: nil,
  remote_addresses: nil,
  login_ids: nil,
  tenants: nil,
  no_tenants: false,
  text: nil,
  from_ts: nil,
  to_ts: nil
)
  # Search the audit trail up to last 30 days based on given parameters
  # user_ids (Array): Optional list of user IDs to filter by
  # actions (Array): Optional list of actions to filter by
  # excluded_actions (Array): Optional list of actions to exclude
  # devices (Array): Optional list of devices to filter by. Current devices supported are "Bot"/"Mobile"/"Desktop"/"Tablet"/"Unknown"
  # methods (Array): Optional list of methods to filter by. Current auth methods are "otp"/"totp"/"magiclink"/"oauth"/"saml"/"password"
  # geos (Array): Optional list of geos to filter by. Geo is currently country code like "US", "IL", etc.
  # remote_addresses (Array): Optional list of remote addresses to filter by
  # login_ids (Array): Optional list of login IDs to filter by
  # tenants (Array): Optional list of tenants to filter by
  # no_tenants (bool): Should audits without any tenants always be included
  # text (str): Free text search across all fields
  # from_ts (datetime): Retrieve records newer than given time but not older than 30 days
  # to_ts (datetime): Retrieve records older than given time
  request_params = {
    noTenants: no_tenants
  }
  request_params[:userIds] = user_ids unless user_ids.nil?
  request_params[:actions] = actions unless actions.nil?
  request_params[:excludeActions] = exclude_actions unless exclude_actions.nil?
  request_params[:devices] = devices unless devices.nil?
  request_params[:methods] = methods unless methods.nil?
  request_params[:geos] = geos unless geos.nil?
  request_params[:remoteAddresses] = remote_addresses unless remote_addresses.nil?
  request_params[:externalIds] =  unless .nil?
  request_params[:tenants] = tenants unless tenants.nil?
  request_params[:text] = text unless text.nil?
  request_params[:from] = from_ts.to_i * 1000 unless from_ts.nil?
  request_params[:to] = to_ts.to_i * 1000 unless to_ts.nil?
  res = post(AUDIT_SEARCH, request_params)
  raise Descope::AuthException, "could not get audits: #{res}" if res['audits'].nil?

  { 'audits' => res['audits'].map { |audit| convert_audit_record(audit) } }
end