Skip to content

policies

ArkIdentityPoliciesService

Bases: ArkIdentityBaseService

Source code in ark_sdk_python/services/identity/policies/ark_identity_policies_service.py
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
class ArkIdentityPoliciesService(ArkIdentityBaseService):
    def add_authentication_profile(
        self, add_authentication_profile: ArkIdentityAddAuthenticationProfile
    ) -> ArkIdentityAuthenticationProfile:
        """
        Adds a new authentication profile

        Args:
            add_authentication_profile (ArkIdentityAddAuthenticationProfile): _description_

        Returns:
            ArkIdentityAuthenticationProfile: _description_
        """
        self._logger.info(f'Adding authentication profile [{add_authentication_profile.auth_profile_name}]')
        data = {
            'settings': {
                'Name': add_authentication_profile.auth_profile_name,
                'Challenges': [','.join(add_authentication_profile.first_challenges)],
                'DurationInMinutes': add_authentication_profile.duration_in_minutes,
            }
        }
        if add_authentication_profile.second_challenges:
            data['settings']['Challenges'].append(','.join(add_authentication_profile.second_challenges))
        if add_authentication_profile.additional_data:
            data['settings']['AdditionalData'] = add_authentication_profile.additional_data
        response: Response = self._client.post(f'{self._url_prefix}{SAVE_PROFILE_URL}', json=data)
        try:
            result = response.json()
            if response.status_code != HTTPStatus.OK or not result['success']:
                raise ArkServiceException(f'Failed to add authentication profile [{response.text}] - [{response.status_code}]')
            return ArkIdentityAuthenticationProfile.parse_obj(result['Result'])
        except (ValidationError, JSONDecodeError, KeyError) as ex:
            self._logger.exception(f'Failed to parse add authentication profile response [{str(ex)}] - [{response.text}]')
            raise ArkServiceException(f'Failed to parse add authentication profile response [{str(ex)}]') from ex

    def remove_authentication_profile(self, remove_authentication_profile: ArkIdentityRemoveAuthenticationProfile) -> None:
        """
        Removes an authentication profile by name or id

        Args:
            remove_authentication_profile (ArkIdentityRemoveAuthenticationProfile): _description_
        """
        if remove_authentication_profile.auth_profile_name and not remove_authentication_profile.auth_profile_id:
            remove_authentication_profile.auth_profile_id = self.authentication_profile(
                ArkIdentityGetAuthenticationProfile(auth_profile_name=remove_authentication_profile.auth_profile_name)
            ).uuid
        self._logger.info(f'Removing authentication profile [{remove_authentication_profile.auth_profile_id}]')
        response: Response = self._client.post(
            f'{self._url_prefix}{DELETE_PROFILE_URL}', json={'uuid': remove_authentication_profile.auth_profile_id}
        )
        try:
            if response.status_code != HTTPStatus.OK or not response.json()['success']:
                raise ArkServiceException(f'Failed to remove authentication profile [{response.text}] - [{response.status_code}]')
        except (ValidationError, JSONDecodeError, KeyError) as ex:
            self._logger.exception(f'Failed to parse remove authentication profile response [{str(ex)}] - [{response.text}]')
            raise ArkServiceException(f'Failed to parse remove authentication profile response [{str(ex)}]') from ex

    def list_authentication_profiles(self) -> List[ArkIdentityAuthenticationProfile]:
        """
        List available authentication profiles

        Raises:
            ArkServiceException: _description_

        Returns:
            List[ArkIdentityAuthenticationProfile]: _description_
        """
        self._logger.info('Listing authentication profiles')
        response: Response = self._client.post(f'{self._url_prefix}{GET_PROFILES_URL}')
        try:
            result = response.json()
            if response.status_code != HTTPStatus.OK or not result['success']:
                raise ArkServiceException(f'Failed to list authentication profiles [{response.text}] - [{response.status_code}]')
            return parse_obj_as(List[ArkIdentityAuthenticationProfile], [r['Row'] for r in result['Result']['Results']])
        except (ValidationError, JSONDecodeError, KeyError) as ex:
            self._logger.exception(f'Failed to parse list authentication profiles response [{str(ex)}] - [{response.text}]')
            raise ArkServiceException(f'Failed to parse list authentication profiles response [{str(ex)}]') from ex

    def authentication_profile(self, get_authentication_profile: ArkIdentityGetAuthenticationProfile) -> ArkIdentityAuthenticationProfile:
        """
        Retrieve an authentication profile by id or name

        Args:
            get_authentication_profile (ArkIdentityGetAuthenticationProfile): _description_

        Raises:
            ArkServiceException: _description_

        Returns:
            ArkIdentityAuthenticationProfile: _description_
        """
        self._logger.info('Retrieving authentication profile')
        auth_profiles = self.list_authentication_profiles()
        if get_authentication_profile.auth_profile_id:
            auth_profiles = [p for p in auth_profiles if p.uuid == get_authentication_profile.auth_profile_id]
        if get_authentication_profile.auth_profile_name:
            auth_profiles = [p for p in auth_profiles if p.name == get_authentication_profile.auth_profile_name]
        if len(auth_profiles) == 0:
            raise ArkServiceException('Failed to find authentication profile')
        return auth_profiles[0]

    def add_policy(self, add_policy: ArkIdentityAddPolicy) -> ArkIdentityPolicy:
        """
        Adds a new policy

        Args:
            add_policy (ArkIdentityAddPolicy): _description_

        Returns:
            ArkIdentityPolicy: _description_
        """
        self._logger.info(f'Adding policy [{add_policy.policy_name}]')
        roles_service = ArkIdentityRolesService(self._isp_auth)
        policies_list = [p.dict(by_alias=True) for p in self.list_policies()]
        policy_name = f'/Policy/{add_policy.policy_name}'
        policy_link = {
            "Description": add_policy.description,
            "PolicySet": policy_name,
            "LinkType": "Role",
            "Priority": 1,
            "Params": [roles_service.role_id_by_name(ArkIdentityRoleIdByName(role_name=role_name)) for role_name in add_policy.role_names],
            "Filters": [],
            "Allowedpolicies": [],
        }
        policies_list.insert(0, policy_link)
        data = {
            "plinks": policies_list,
            "policy": {
                "Path": policy_name,
                "Version": 1,
                "Description": add_policy.description,
                "Settings": {
                    "AuthenticationEnabled": 'true',
                    "/Core/Authentication/AuthenticationRulesDefaultProfileId": self.authentication_profile(
                        ArkIdentityGetAuthenticationProfile(auth_profile_name=add_policy.auth_profile_name)
                    ).uuid,
                    "/Core/Authentication/CookieAllowPersist": 'false',
                    "/Core/Authentication/AuthSessionMaxConcurrent": 0,
                    "/Core/Authentication/AllowIwa": 'true',
                    "/Core/Authentication/IwaSetKnownEndpoint": 'false',
                    "/Core/Authentication/IwaSatisfiesAllMechs": 'false',
                    "/Core/Authentication/AllowZso": 'true',
                    "/Core/Authentication/ZsoSkipChallenge": 'true',
                    "/Core/Authentication/ZsoSetKnownEndpoint": 'false',
                    "/Core/Authentication/ZsoSatisfiesAllMechs": 'false',
                    "/Core/Authentication/NoMfaMechLogin": 'false',
                    "/Core/Authentication/FederatedLoginAllowsMfa": 'false',
                    "/Core/Authentication/FederatedLoginSatisfiesAllMechs": 'false',
                    "/Core/MfaRestrictions/BlockMobileMechsOnMobileLogin": 'false',
                    "/Core/Authentication/ContinueFailedSessions": 'true',
                    "/Core/Authentication/SkipMechsInFalseAdvance": 'true',
                    "/Core/Authentication/AllowLoginMfaCache": 'false',
                },
                "Newpolicy": 'true',
            },
        }
        if add_policy.settings:
            data['policy']['Settings'].update(add_policy.settings)
        response: Response = self._client.post(f'{self._url_prefix}{SAVE_POLICY_URL}', json=data)
        try:
            if response.status_code != HTTPStatus.OK or not response.json()['success']:
                raise ArkServiceException(f'Failed to add policy [{response.text}] - [{response.status_code}]')
            return self.policy(ArkIdentityGetPolicy(policy_name=add_policy.policy_name))
        except (ValidationError, JSONDecodeError, KeyError) as ex:
            self._logger.exception(f'Failed to parse add policy response [{str(ex)}] - [{response.text}]')
            raise ArkServiceException(f'Failed to parse add policy response [{str(ex)}]') from ex

    def disable_default_policy(self) -> None:
        """
        Disables the default policy (makes it inactive)
        """
        self.disable_policy(
            disable_policy=ArkIdentityDisablePolicy(
                policy_name='/Policy/Default Policy',
            ),
        )

    def enable_default_policy(self) -> None:
        """
        Enables the default policy (makes it active)
        """
        self.enable_policy(
            enable_policy=ArkIdentityEnablePolicy(
                policy_name='/Policy/Default Policy',
            ),
        )

    def perform_action_on_policy(self, policy_operation: ArkIdentityPolicyOperation) -> None:
        """
        Performs operation on policy (enable/disable)

        Args:
            policy_operation (ArkIdentityPolicyOperation): _description_

        Raises:
            ArkServiceException: _description_
        """
        policy_name = policy_operation.policy_name
        policy = self.policy(get_policy=ArkIdentityGetPolicy(policy_name=policy_name))

        policies_list = [p.dict(by_alias=True) for p in self.list_policies()]
        for elem in policies_list:
            if elem['ID'] == policy_name:
                elem['LinkType'] = policy_operation.operation_type.value
        data = {
            "plinks": policies_list,
            "policy": {
                "Path": policy_name,
                "Version": 1,
                "Description": policy.description,
                "RevStamp": policy.rev_stamp,
                "Settings": policy.settings,
                "Newpolicy": False,
            },
        }
        response: Response = self._client.post(f'{self._url_prefix}{SAVE_POLICY_URL}', json=data)
        try:
            if response.status_code != HTTPStatus.OK or not response.json()['success']:
                raise ArkServiceException(f'Failed to add policy [{response.text}] - [{response.status_code}]')
        except (ValidationError, JSONDecodeError, KeyError) as ex:
            self._logger.exception(f'Failed to parse perform policy action response [{str(ex)}] - [{response.text}]')
            raise ArkServiceException(f'Failed to parse perform policy action response [{str(ex)}]') from ex

    def enable_policy(self, enable_policy: ArkIdentityEnablePolicy) -> None:
        """
        Enables a policy by name

        Args:
            enable_policy (ArkIdentityEnablePolicy): _description_

        """
        self._logger.info(f'Making Policy [{enable_policy.policy_name}] active')
        self.perform_action_on_policy(
            policy_operation=ArkIdentityPolicyOperation(
                policy_name=enable_policy.policy_name,
                operation_type=ArkIdentityPolicyOperationType.ENABLE,
            ),
        )

    def disable_policy(self, disable_policy: ArkIdentityDisablePolicy) -> None:
        """
        Disables a policy by name

        Args:
            disable_policy (ArkIdentityDisablePolicy): _description_

        """
        self._logger.info(f'Making Policy [{disable_policy.policy_name}] inactive')
        self.perform_action_on_policy(
            policy_operation=ArkIdentityPolicyOperation(
                policy_name=disable_policy.policy_name,
                operation_type=ArkIdentityPolicyOperationType.DISABLE,
            ),
        )

    def remove_policy(self, remove_policy: ArkIdentityRemovePolicy) -> None:
        """
        Removes a policy by name

        Args:
            remove_policy (ArkIdentityRemovePolicy): _description_

        Raises:
            ArkServiceException: _description_
        """
        self._logger.info(f'Removing policy [{remove_policy.policy_name}]')
        policy_name = remove_policy.policy_name
        if not policy_name.startswith('/Policy/'):
            policy_name = f'/Policy/{policy_name}'
        response: Response = self._client.post(f'{self._url_prefix}{DELETE_POLICY_URL}', json={'path': policy_name})
        try:
            if response.status_code != HTTPStatus.OK or not response.json()['success']:
                raise ArkServiceException(f'Failed to remove policy [{response.text}] - [{response.status_code}]')
        except (ValidationError, JSONDecodeError, KeyError) as ex:
            self._logger.exception(f'Failed to parse remove policy response [{str(ex)}] - [{response.text}]')
            raise ArkServiceException(f'Failed to parse remove policy response [{str(ex)}]') from ex

    def list_policies(self) -> List[ArkIdentityPolicyInfo]:
        """
        Lists all policies short info

        Returns:
            List[ArkIdentityPolicyInfo]: _description_
        """
        self._logger.info('Listing all policies')
        response: Response = self._client.post(f'{self._url_prefix}{LIST_POLICIES_URL}')
        try:
            result = response.json()
            if response.status_code != HTTPStatus.OK or not result['success']:
                raise ArkServiceException(f'Failed to list policies [{response.text}] - [{response.status_code}]')
            return parse_obj_as(List[ArkIdentityPolicyInfo], [p['Row'] for p in result['Result']['Results']])
        except (ValidationError, JSONDecodeError, KeyError) as ex:
            self._logger.exception(f'Failed to parse list policies response [{str(ex)}] - [{response.text}]')
            raise ArkServiceException(f'Failed to parse list policies response [{str(ex)}]') from ex

    def policy(self, get_policy: ArkIdentityGetPolicy) -> ArkIdentityPolicy:
        """
        Retrieves a policy full info by name

        Args:
            get_policy (ArkIdentityGetPolicy): _description_

        Returns:
            ArkIdentityPolicy: _description_
        """
        self._logger.info(f'Retrieving policy [{get_policy.policy_name}]')
        policy_name = get_policy.policy_name
        if not policy_name.startswith('/Policy/'):
            policy_name = f'/Policy/{policy_name}'
        response: Response = self._client.post(f'{self._url_prefix}{GET_POLICY_URL}', json={'name': policy_name})
        try:
            result = response.json()
            if response.status_code != HTTPStatus.OK or not result['success']:
                raise ArkServiceException(f'Failed to list policies [{response.text}] - [{response.status_code}]')
            return ArkIdentityPolicy.parse_obj(result['Result'])
        except (ValidationError, JSONDecodeError, KeyError) as ex:
            self._logger.exception(f'Failed to parse policy response [{str(ex)}] - [{response.text}]')
            raise ArkServiceException(f'Failed to parse policy response [{str(ex)}]') from ex

    @staticmethod
    @overrides
    def service_config() -> ArkServiceConfig:
        return SERVICE_CONFIG

add_authentication_profile(add_authentication_profile)

Adds a new authentication profile

Parameters:

Name Type Description Default
add_authentication_profile ArkIdentityAddAuthenticationProfile

description

required

Returns:

Name Type Description
ArkIdentityAuthenticationProfile ArkIdentityAuthenticationProfile

description

Source code in ark_sdk_python/services/identity/policies/ark_identity_policies_service.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def add_authentication_profile(
    self, add_authentication_profile: ArkIdentityAddAuthenticationProfile
) -> ArkIdentityAuthenticationProfile:
    """
    Adds a new authentication profile

    Args:
        add_authentication_profile (ArkIdentityAddAuthenticationProfile): _description_

    Returns:
        ArkIdentityAuthenticationProfile: _description_
    """
    self._logger.info(f'Adding authentication profile [{add_authentication_profile.auth_profile_name}]')
    data = {
        'settings': {
            'Name': add_authentication_profile.auth_profile_name,
            'Challenges': [','.join(add_authentication_profile.first_challenges)],
            'DurationInMinutes': add_authentication_profile.duration_in_minutes,
        }
    }
    if add_authentication_profile.second_challenges:
        data['settings']['Challenges'].append(','.join(add_authentication_profile.second_challenges))
    if add_authentication_profile.additional_data:
        data['settings']['AdditionalData'] = add_authentication_profile.additional_data
    response: Response = self._client.post(f'{self._url_prefix}{SAVE_PROFILE_URL}', json=data)
    try:
        result = response.json()
        if response.status_code != HTTPStatus.OK or not result['success']:
            raise ArkServiceException(f'Failed to add authentication profile [{response.text}] - [{response.status_code}]')
        return ArkIdentityAuthenticationProfile.parse_obj(result['Result'])
    except (ValidationError, JSONDecodeError, KeyError) as ex:
        self._logger.exception(f'Failed to parse add authentication profile response [{str(ex)}] - [{response.text}]')
        raise ArkServiceException(f'Failed to parse add authentication profile response [{str(ex)}]') from ex

add_policy(add_policy)

Adds a new policy

Parameters:

Name Type Description Default
add_policy ArkIdentityAddPolicy

description

required

Returns:

Name Type Description
ArkIdentityPolicy ArkIdentityPolicy

description

Source code in ark_sdk_python/services/identity/policies/ark_identity_policies_service.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
def add_policy(self, add_policy: ArkIdentityAddPolicy) -> ArkIdentityPolicy:
    """
    Adds a new policy

    Args:
        add_policy (ArkIdentityAddPolicy): _description_

    Returns:
        ArkIdentityPolicy: _description_
    """
    self._logger.info(f'Adding policy [{add_policy.policy_name}]')
    roles_service = ArkIdentityRolesService(self._isp_auth)
    policies_list = [p.dict(by_alias=True) for p in self.list_policies()]
    policy_name = f'/Policy/{add_policy.policy_name}'
    policy_link = {
        "Description": add_policy.description,
        "PolicySet": policy_name,
        "LinkType": "Role",
        "Priority": 1,
        "Params": [roles_service.role_id_by_name(ArkIdentityRoleIdByName(role_name=role_name)) for role_name in add_policy.role_names],
        "Filters": [],
        "Allowedpolicies": [],
    }
    policies_list.insert(0, policy_link)
    data = {
        "plinks": policies_list,
        "policy": {
            "Path": policy_name,
            "Version": 1,
            "Description": add_policy.description,
            "Settings": {
                "AuthenticationEnabled": 'true',
                "/Core/Authentication/AuthenticationRulesDefaultProfileId": self.authentication_profile(
                    ArkIdentityGetAuthenticationProfile(auth_profile_name=add_policy.auth_profile_name)
                ).uuid,
                "/Core/Authentication/CookieAllowPersist": 'false',
                "/Core/Authentication/AuthSessionMaxConcurrent": 0,
                "/Core/Authentication/AllowIwa": 'true',
                "/Core/Authentication/IwaSetKnownEndpoint": 'false',
                "/Core/Authentication/IwaSatisfiesAllMechs": 'false',
                "/Core/Authentication/AllowZso": 'true',
                "/Core/Authentication/ZsoSkipChallenge": 'true',
                "/Core/Authentication/ZsoSetKnownEndpoint": 'false',
                "/Core/Authentication/ZsoSatisfiesAllMechs": 'false',
                "/Core/Authentication/NoMfaMechLogin": 'false',
                "/Core/Authentication/FederatedLoginAllowsMfa": 'false',
                "/Core/Authentication/FederatedLoginSatisfiesAllMechs": 'false',
                "/Core/MfaRestrictions/BlockMobileMechsOnMobileLogin": 'false',
                "/Core/Authentication/ContinueFailedSessions": 'true',
                "/Core/Authentication/SkipMechsInFalseAdvance": 'true',
                "/Core/Authentication/AllowLoginMfaCache": 'false',
            },
            "Newpolicy": 'true',
        },
    }
    if add_policy.settings:
        data['policy']['Settings'].update(add_policy.settings)
    response: Response = self._client.post(f'{self._url_prefix}{SAVE_POLICY_URL}', json=data)
    try:
        if response.status_code != HTTPStatus.OK or not response.json()['success']:
            raise ArkServiceException(f'Failed to add policy [{response.text}] - [{response.status_code}]')
        return self.policy(ArkIdentityGetPolicy(policy_name=add_policy.policy_name))
    except (ValidationError, JSONDecodeError, KeyError) as ex:
        self._logger.exception(f'Failed to parse add policy response [{str(ex)}] - [{response.text}]')
        raise ArkServiceException(f'Failed to parse add policy response [{str(ex)}]') from ex

authentication_profile(get_authentication_profile)

Retrieve an authentication profile by id or name

Parameters:

Name Type Description Default
get_authentication_profile ArkIdentityGetAuthenticationProfile

description

required

Raises:

Type Description
ArkServiceException

description

Returns:

Name Type Description
ArkIdentityAuthenticationProfile ArkIdentityAuthenticationProfile

description

Source code in ark_sdk_python/services/identity/policies/ark_identity_policies_service.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
def authentication_profile(self, get_authentication_profile: ArkIdentityGetAuthenticationProfile) -> ArkIdentityAuthenticationProfile:
    """
    Retrieve an authentication profile by id or name

    Args:
        get_authentication_profile (ArkIdentityGetAuthenticationProfile): _description_

    Raises:
        ArkServiceException: _description_

    Returns:
        ArkIdentityAuthenticationProfile: _description_
    """
    self._logger.info('Retrieving authentication profile')
    auth_profiles = self.list_authentication_profiles()
    if get_authentication_profile.auth_profile_id:
        auth_profiles = [p for p in auth_profiles if p.uuid == get_authentication_profile.auth_profile_id]
    if get_authentication_profile.auth_profile_name:
        auth_profiles = [p for p in auth_profiles if p.name == get_authentication_profile.auth_profile_name]
    if len(auth_profiles) == 0:
        raise ArkServiceException('Failed to find authentication profile')
    return auth_profiles[0]

disable_default_policy()

Disables the default policy (makes it inactive)

Source code in ark_sdk_python/services/identity/policies/ark_identity_policies_service.py
211
212
213
214
215
216
217
218
219
def disable_default_policy(self) -> None:
    """
    Disables the default policy (makes it inactive)
    """
    self.disable_policy(
        disable_policy=ArkIdentityDisablePolicy(
            policy_name='/Policy/Default Policy',
        ),
    )

disable_policy(disable_policy)

Disables a policy by name

Parameters:

Name Type Description Default
disable_policy ArkIdentityDisablePolicy

description

required
Source code in ark_sdk_python/services/identity/policies/ark_identity_policies_service.py
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
def disable_policy(self, disable_policy: ArkIdentityDisablePolicy) -> None:
    """
    Disables a policy by name

    Args:
        disable_policy (ArkIdentityDisablePolicy): _description_

    """
    self._logger.info(f'Making Policy [{disable_policy.policy_name}] inactive')
    self.perform_action_on_policy(
        policy_operation=ArkIdentityPolicyOperation(
            policy_name=disable_policy.policy_name,
            operation_type=ArkIdentityPolicyOperationType.DISABLE,
        ),
    )

enable_default_policy()

Enables the default policy (makes it active)

Source code in ark_sdk_python/services/identity/policies/ark_identity_policies_service.py
221
222
223
224
225
226
227
228
229
def enable_default_policy(self) -> None:
    """
    Enables the default policy (makes it active)
    """
    self.enable_policy(
        enable_policy=ArkIdentityEnablePolicy(
            policy_name='/Policy/Default Policy',
        ),
    )

enable_policy(enable_policy)

Enables a policy by name

Parameters:

Name Type Description Default
enable_policy ArkIdentityEnablePolicy

description

required
Source code in ark_sdk_python/services/identity/policies/ark_identity_policies_service.py
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
def enable_policy(self, enable_policy: ArkIdentityEnablePolicy) -> None:
    """
    Enables a policy by name

    Args:
        enable_policy (ArkIdentityEnablePolicy): _description_

    """
    self._logger.info(f'Making Policy [{enable_policy.policy_name}] active')
    self.perform_action_on_policy(
        policy_operation=ArkIdentityPolicyOperation(
            policy_name=enable_policy.policy_name,
            operation_type=ArkIdentityPolicyOperationType.ENABLE,
        ),
    )

list_authentication_profiles()

List available authentication profiles

Raises:

Type Description
ArkServiceException

description

Returns:

Type Description
List[ArkIdentityAuthenticationProfile]

List[ArkIdentityAuthenticationProfile]: description

Source code in ark_sdk_python/services/identity/policies/ark_identity_policies_service.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def list_authentication_profiles(self) -> List[ArkIdentityAuthenticationProfile]:
    """
    List available authentication profiles

    Raises:
        ArkServiceException: _description_

    Returns:
        List[ArkIdentityAuthenticationProfile]: _description_
    """
    self._logger.info('Listing authentication profiles')
    response: Response = self._client.post(f'{self._url_prefix}{GET_PROFILES_URL}')
    try:
        result = response.json()
        if response.status_code != HTTPStatus.OK or not result['success']:
            raise ArkServiceException(f'Failed to list authentication profiles [{response.text}] - [{response.status_code}]')
        return parse_obj_as(List[ArkIdentityAuthenticationProfile], [r['Row'] for r in result['Result']['Results']])
    except (ValidationError, JSONDecodeError, KeyError) as ex:
        self._logger.exception(f'Failed to parse list authentication profiles response [{str(ex)}] - [{response.text}]')
        raise ArkServiceException(f'Failed to parse list authentication profiles response [{str(ex)}]') from ex

list_policies()

Lists all policies short info

Returns:

Type Description
List[ArkIdentityPolicyInfo]

List[ArkIdentityPolicyInfo]: description

Source code in ark_sdk_python/services/identity/policies/ark_identity_policies_service.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
def list_policies(self) -> List[ArkIdentityPolicyInfo]:
    """
    Lists all policies short info

    Returns:
        List[ArkIdentityPolicyInfo]: _description_
    """
    self._logger.info('Listing all policies')
    response: Response = self._client.post(f'{self._url_prefix}{LIST_POLICIES_URL}')
    try:
        result = response.json()
        if response.status_code != HTTPStatus.OK or not result['success']:
            raise ArkServiceException(f'Failed to list policies [{response.text}] - [{response.status_code}]')
        return parse_obj_as(List[ArkIdentityPolicyInfo], [p['Row'] for p in result['Result']['Results']])
    except (ValidationError, JSONDecodeError, KeyError) as ex:
        self._logger.exception(f'Failed to parse list policies response [{str(ex)}] - [{response.text}]')
        raise ArkServiceException(f'Failed to parse list policies response [{str(ex)}]') from ex

perform_action_on_policy(policy_operation)

Performs operation on policy (enable/disable)

Parameters:

Name Type Description Default
policy_operation ArkIdentityPolicyOperation

description

required

Raises:

Type Description
ArkServiceException

description

Source code in ark_sdk_python/services/identity/policies/ark_identity_policies_service.py
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
def perform_action_on_policy(self, policy_operation: ArkIdentityPolicyOperation) -> None:
    """
    Performs operation on policy (enable/disable)

    Args:
        policy_operation (ArkIdentityPolicyOperation): _description_

    Raises:
        ArkServiceException: _description_
    """
    policy_name = policy_operation.policy_name
    policy = self.policy(get_policy=ArkIdentityGetPolicy(policy_name=policy_name))

    policies_list = [p.dict(by_alias=True) for p in self.list_policies()]
    for elem in policies_list:
        if elem['ID'] == policy_name:
            elem['LinkType'] = policy_operation.operation_type.value
    data = {
        "plinks": policies_list,
        "policy": {
            "Path": policy_name,
            "Version": 1,
            "Description": policy.description,
            "RevStamp": policy.rev_stamp,
            "Settings": policy.settings,
            "Newpolicy": False,
        },
    }
    response: Response = self._client.post(f'{self._url_prefix}{SAVE_POLICY_URL}', json=data)
    try:
        if response.status_code != HTTPStatus.OK or not response.json()['success']:
            raise ArkServiceException(f'Failed to add policy [{response.text}] - [{response.status_code}]')
    except (ValidationError, JSONDecodeError, KeyError) as ex:
        self._logger.exception(f'Failed to parse perform policy action response [{str(ex)}] - [{response.text}]')
        raise ArkServiceException(f'Failed to parse perform policy action response [{str(ex)}]') from ex

policy(get_policy)

Retrieves a policy full info by name

Parameters:

Name Type Description Default
get_policy ArkIdentityGetPolicy

description

required

Returns:

Name Type Description
ArkIdentityPolicy ArkIdentityPolicy

description

Source code in ark_sdk_python/services/identity/policies/ark_identity_policies_service.py
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
def policy(self, get_policy: ArkIdentityGetPolicy) -> ArkIdentityPolicy:
    """
    Retrieves a policy full info by name

    Args:
        get_policy (ArkIdentityGetPolicy): _description_

    Returns:
        ArkIdentityPolicy: _description_
    """
    self._logger.info(f'Retrieving policy [{get_policy.policy_name}]')
    policy_name = get_policy.policy_name
    if not policy_name.startswith('/Policy/'):
        policy_name = f'/Policy/{policy_name}'
    response: Response = self._client.post(f'{self._url_prefix}{GET_POLICY_URL}', json={'name': policy_name})
    try:
        result = response.json()
        if response.status_code != HTTPStatus.OK or not result['success']:
            raise ArkServiceException(f'Failed to list policies [{response.text}] - [{response.status_code}]')
        return ArkIdentityPolicy.parse_obj(result['Result'])
    except (ValidationError, JSONDecodeError, KeyError) as ex:
        self._logger.exception(f'Failed to parse policy response [{str(ex)}] - [{response.text}]')
        raise ArkServiceException(f'Failed to parse policy response [{str(ex)}]') from ex

remove_authentication_profile(remove_authentication_profile)

Removes an authentication profile by name or id

Parameters:

Name Type Description Default
remove_authentication_profile ArkIdentityRemoveAuthenticationProfile

description

required
Source code in ark_sdk_python/services/identity/policies/ark_identity_policies_service.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def remove_authentication_profile(self, remove_authentication_profile: ArkIdentityRemoveAuthenticationProfile) -> None:
    """
    Removes an authentication profile by name or id

    Args:
        remove_authentication_profile (ArkIdentityRemoveAuthenticationProfile): _description_
    """
    if remove_authentication_profile.auth_profile_name and not remove_authentication_profile.auth_profile_id:
        remove_authentication_profile.auth_profile_id = self.authentication_profile(
            ArkIdentityGetAuthenticationProfile(auth_profile_name=remove_authentication_profile.auth_profile_name)
        ).uuid
    self._logger.info(f'Removing authentication profile [{remove_authentication_profile.auth_profile_id}]')
    response: Response = self._client.post(
        f'{self._url_prefix}{DELETE_PROFILE_URL}', json={'uuid': remove_authentication_profile.auth_profile_id}
    )
    try:
        if response.status_code != HTTPStatus.OK or not response.json()['success']:
            raise ArkServiceException(f'Failed to remove authentication profile [{response.text}] - [{response.status_code}]')
    except (ValidationError, JSONDecodeError, KeyError) as ex:
        self._logger.exception(f'Failed to parse remove authentication profile response [{str(ex)}] - [{response.text}]')
        raise ArkServiceException(f'Failed to parse remove authentication profile response [{str(ex)}]') from ex

remove_policy(remove_policy)

Removes a policy by name

Parameters:

Name Type Description Default
remove_policy ArkIdentityRemovePolicy

description

required

Raises:

Type Description
ArkServiceException

description

Source code in ark_sdk_python/services/identity/policies/ark_identity_policies_service.py
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
def remove_policy(self, remove_policy: ArkIdentityRemovePolicy) -> None:
    """
    Removes a policy by name

    Args:
        remove_policy (ArkIdentityRemovePolicy): _description_

    Raises:
        ArkServiceException: _description_
    """
    self._logger.info(f'Removing policy [{remove_policy.policy_name}]')
    policy_name = remove_policy.policy_name
    if not policy_name.startswith('/Policy/'):
        policy_name = f'/Policy/{policy_name}'
    response: Response = self._client.post(f'{self._url_prefix}{DELETE_POLICY_URL}', json={'path': policy_name})
    try:
        if response.status_code != HTTPStatus.OK or not response.json()['success']:
            raise ArkServiceException(f'Failed to remove policy [{response.text}] - [{response.status_code}]')
    except (ValidationError, JSONDecodeError, KeyError) as ex:
        self._logger.exception(f'Failed to parse remove policy response [{str(ex)}] - [{response.text}]')
        raise ArkServiceException(f'Failed to parse remove policy response [{str(ex)}]') from ex