Module: Descope::Api::V1::Management::Authz

Includes:
Common
Included in:
Descope::Api::V1::Management
Defined in:
lib/descope/api/v1/management/authz.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

#authz_create_relations(relations = nil) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/descope/api/v1/management/authz.rb', line 91

def authz_create_relations(relations = nil)
  # Create the given relations based on the existing schema
  #  relations (Array[]): the relations to create. Each in the following format:
  #   {
  #       "resource": "id of the resource that has the relation",
  #       "relationDefinition": "the relation definition for the relation",
  #       "namespace": "namespace for the relation definition",
  #       "target": "the target that has the relation - usually users or other resources",
  #       "targetSetResource": "if the target is a group that has another relation",
  #       "targetSetRelationDefinition": "the relation definition for the targetSet group",
  #       "targetSetRelationDefinitionNamespace": "the namespace for the relation definition for the targetSet group",
  #       "query": {
  #           "tenants": ["t1", "t2"],
  #           "roles": ["r1", "r2"],
  #           "text": "full-text-search",
  #           "statuses": ["enabled|disabled|invited"],
  #           "ssoOnly": True|False,
  #           "withTestUser": True|False,
  #           "customAttributes": {
  #               "key": "value",
  #               ...
  #           }
  #       }
  #   }
  #   Each relation should have exactly one of: target, targetSet, query
  #   Regarding query above, it should be specified if the target is a set of users that matches the query - all fields are optional
  post(AUTHZ_RE_CREATE, { relations: })
end

#authz_delete_namespace(name: nil, schema_name: nil) ⇒ Object



65
66
67
68
69
70
# File 'lib/descope/api/v1/management/authz.rb', line 65

def authz_delete_namespace(name: nil, schema_name: nil)
  # Delete the given namespace
  request_params = { name: name }
  request_params[:schemaName] = schema_name unless schema_name.nil?
  post(AUTHZ_NS_DELETE, request_params)
end

#authz_delete_relation_definition(name: nil, namespace: nil, schema_name: nil) ⇒ Object



84
85
86
87
88
89
# File 'lib/descope/api/v1/management/authz.rb', line 84

def authz_delete_relation_definition(name: nil, namespace: nil, schema_name: nil)
  # Delete the given relation definition
  request_params = { name: , namespace:  }
  request_params[:schemaName] = schema_name unless schema_name.nil?
  post(AUTHZ_RD_DELETE, request_params)
end

#authz_delete_relations(relations = nil) ⇒ Object



120
121
122
123
# File 'lib/descope/api/v1/management/authz.rb', line 120

def authz_delete_relations(relations = nil)
  # Delete the given relations based on the existing schema
  post(AUTHZ_RE_DELETE, { relations: })
end

#authz_delete_relations_for_resources(resources = nil) ⇒ Object



125
126
127
128
# File 'lib/descope/api/v1/management/authz.rb', line 125

def authz_delete_relations_for_resources(resources = nil)
  # Delete all relations for the given resources
  post(AUTHZ_RE_DELETE_RESOURCES, { resources: })
end

#authz_delete_schemaObject



46
47
48
49
# File 'lib/descope/api/v1/management/authz.rb', line 46

def authz_delete_schema
  # Delete the schema for the project which will also delete all relations.
  post(AUTHZ_SCHEMA_DELETE)
end

#authz_has_relations?(relation_queries = nil) ⇒ Boolean

Returns:

  • (Boolean)


130
131
132
133
# File 'lib/descope/api/v1/management/authz.rb', line 130

def authz_has_relations?(relation_queries = nil)
  # Queries the given relations to see if they exist returning true if they do
  post(AUTHZ_RE_HAS_RELATIONS, { relationQueries: relation_queries })
end

#authz_load_schemaObject



51
52
53
54
# File 'lib/descope/api/v1/management/authz.rb', line 51

def authz_load_schema
  # Load the schema for the project.
  post(AUTHZ_SCHEMA_LOAD)
end

#authz_resource_relations(resources: nil) ⇒ Object



145
146
147
# File 'lib/descope/api/v1/management/authz.rb', line 145

def authz_resource_relations(resources: nil)
  post(AUTHZ_RE_RESOURCE, { resources: })
end

#authz_save_namespace(namespace: nil, old_name: nil, schema_name: nil) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/descope/api/v1/management/authz.rb', line 56

def authz_save_namespace(namespace: nil, old_name: nil, schema_name: nil)
  # Create or update the given namespace
  # Will not delete relation definitions not mentioned in the namespace.
  request_params = { namespace: namespace }
  request_params[:oldName] = old_name unless old_name.nil?
  request_params[:schemaName] = schema_name unless schema_name.nil?
  post(AUTHZ_NS_SAVE, request_params)
end

#authz_save_relation_definition(relation_definition: nil, namespace: nil, old_name: nil, schema_name: nil) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/descope/api/v1/management/authz.rb', line 72

def authz_save_relation_definition(relation_definition: nil, namespace: nil, old_name: nil, schema_name: nil)
  # Create or update the given relation definition
  #  Will not delete relation definitions not mentioned in the namespace.
  request_params = {
    relationDefinition: relation_definition,
    namespace:
  }
  request_params[:old_name] = old_name unless old_name.nil?
  request_params[:schemaName] = schema_name unless schema_name.nil?
  post(AUTHZ_RD_SAVE, request_params)
end

#authz_save_schema(schema: nil, upgrade: false) ⇒ 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
# File 'lib/descope/api/v1/management/authz.rb', line 11

def authz_save_schema(schema: nil, upgrade: false)
  #  Create or update the ReBAC schema.
  #  In case of update, will update only given namespaces and will not delete namespaces unless upgrade flag is true.
  #  Args:
  #  schema (dict): the schema dict with format
  #       {
  #           "name": "name-of-schema",
  #           "namespaces": [
  #               {
  #                   "name": "name-of-namespace",
  #                   "relationDefinitions": [
  #                       {
  #                           "name": "name-of-relation-definition",
  #                           "complexDefinition": {
  #                               "nType": "one of child|union|intersect|sub",
  #                               "children": "optional list of node children - same format as complexDefinition",
  #                               "expression": {
  #                                   "neType": "one of self|targetSet|relationLeft|relationRight",
  #                                   "relationDefinition": "name of relation definition for relationLeft and relationRight",
  #                                   "relationDefinitionNamespace": "the namespace for the rd above",
  #                                   "targetRelationDefinition": "relation definition for targetSet and relationLeft/right",
  #                                   "targetRelationDefinitionNamespace": "the namespace for above"
  #                               }
  #                           }
  #                       }
  #                   ]
  #               }
  #           ]
  #       }
  #   Schema name can be used for projects to track versioning.
  #  @see https://docs.descope.com/api/openapi/authz/operation/SaveSchema/
  request_params = { schema:, upgrade: }
  post(AUTHZ_SCHEMA_SAVE, request_params)
end

#authz_target_relations(targets: nil) ⇒ Object



149
150
151
152
# File 'lib/descope/api/v1/management/authz.rb', line 149

def authz_target_relations(targets: nil)
  # Returns the list of all defined relations (not recursive) for the given targets.
  post(AUTHZ_RE_TARGETS, { targets: })
end

#authz_what_can_target_access?(target: nil) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



154
155
156
157
158
159
160
# File 'lib/descope/api/v1/management/authz.rb', line 154

def authz_what_can_target_access?(target: nil)
  # Returns the list of all relations for the given target including derived relations from the schema tree.
  res = post(AUTHZ_RE_TARGET_ALL, { target: })
  raise Descope::AuthException, "could not get relation for target: #{res}" if res['relations'].nil?

  res['relations']
end

#authz_who_can_access?(resource: nil, relation_definition: nil, namespace: nil) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
138
139
140
141
142
143
# File 'lib/descope/api/v1/management/authz.rb', line 135

def authz_who_can_access?(resource: nil, relation_definition: nil, namespace: nil)
  #  Finds the list of targets (usually users) who can access the given resource with the given RD
  request_params = {
    resource:,
    relationDefinition: relation_definition,
    namespace:
  }
  post(AUTHZ_RE_WHO, request_params)
end