Skip to content

ark_pcloud_platforms_service

ArkPCloudPlatformsService

Bases: ArkPCloudBaseService

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
 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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
class ArkPCloudPlatformsService(ArkPCloudBaseService):
    def __list_platforms_by_filters(
        self, active: Optional[bool] = None, platform_type: Optional[ArkPCloudPlatformType] = None, platform_name: Optional[str] = None
    ) -> List[ArkPCloudPlatform]:
        args = {}
        if active is not None:
            args['Active'] = active
        if platform_type:
            args['PlatformType'] = platform_type.value
        if platform_name:
            args['Search'] = platform_name
        resp: Response = self._client.get(PLATFORMS_URL, params=args)
        if resp.status_code == HTTPStatus.OK:
            try:
                data = resp.json()
                # Platform type may come in uppercase, lowercase it just in case
                for p in data['Platforms']:
                    p['general']['platformType'] = p['general']['platformType'].lower()
                return parse_obj_as(List[ArkPCloudPlatform], data['Platforms'])
            except (ValidationError, JSONDecodeError, KeyError) as ex:
                self._logger.exception(f'Failed to parse list platforms response [{str(ex)}] - [{resp.text}]')
                raise ArkServiceException(f'Failed to parse list platforms response [{str(ex)}]') from ex
        raise ArkServiceException(f'Failed to list platforms [{resp.text}] - [{resp.status_code}]')

    def list_platforms(self) -> List[ArkPCloudPlatform]:
        """
        Lists all the platforms visible to the user
        https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-get-platforms.htm

        Returns:
            List[ArkPCloudPlatform]: _description_
        """
        self._logger.info('Listing all platforms')
        return self.__list_platforms_by_filters()

    def list_platforms_by(self, platforms_filter: ArkPCloudPlatformsFilter) -> List[ArkPCloudPlatform]:
        """
        Lists platforms by given filters
        https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-get-platforms.htm

        Args:
            platforms_filter (ArkPCloudPlatformsFilter): _description_

        Returns:
            List[ArkPCloudPlatform]: _description_
        """
        self._logger.info(f'Listing platforms by filter [{platforms_filter}]')
        return self.__list_platforms_by_filters(
            active=platforms_filter.active, platform_type=platforms_filter.platform_type, platform_name=platforms_filter.platform_name
        )

    def platform(self, get_platform: ArkPCloudGetPlatform) -> ArkPCloudPlatform:
        """
        Retrieves a platform by id
        https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/WebServices/GetPlatformDetails.htm

        Args:
            get_platform (ArkPCloudGetPlatform): _description_

        Raises:
            ArkServiceException: _description_

        Returns:
            ArkPCloudPlatform: _description_
        """
        self._logger.info(f'Retrieving platform [{get_platform.platform_id}]')
        resp: Response = self._client.get(PLATFORM_URL.format(platform_id=get_platform.platform_id))
        if resp.status_code == HTTPStatus.OK:
            try:
                return ArkPCloudPlatform.parse_obj(resp.json())
            except (ValidationError, JSONDecodeError) as ex:
                self._logger.exception(f'Failed to parse platform response [{str(ex)}] - [{resp.text}]')
                raise ArkServiceException(f'Failed to parse platform response [{str(ex)}]') from ex
        raise ArkServiceException(f'Failed to retrieve platform [{resp.text}] - [{resp.status_code}]')

    def import_platform(self, import_platform: ArkPCloudImportPlatform) -> ArkPCloudPlatform:
        """
        Tries to import a platform zip data
        https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/WebServices/ImportPlatform.htm

        Args:
            import_platform (ArkPCloudImportPlatform): _description_

        Raises:
            ArkServiceException: _description_

        Returns:
            ArkPCloudPlatform: _description_
        """
        self._logger.info('Importing platform')
        platform_path = Path(import_platform.platform_zip_path)
        if not platform_path.exists():
            raise ArkServiceException(f'Given path [{str(platform_path)}] does not exist or is invalid')
        zip_data = b64encode(platform_path.read_bytes()).decode()
        resp: Response = self._client.post(IMPORT_PLATFORM_URL, json={'ImportFile': zip_data})
        if resp.status_code == HTTPStatus.CREATED:
            try:
                platform_id = resp.json()['PlatformID']
                return self.platform(ArkPCloudGetPlatform(platform_id=platform_id))
            except (ValidationError, JSONDecodeError, KeyError) as ex:
                self._logger.exception(f'Failed to parse import platform response [{str(ex)}] - [{resp.text}]')
                raise ArkServiceException(f'Failed to parse import platform response [{str(ex)}]') from ex
        raise ArkServiceException(f'Failed to import platform [{resp.text}] - [{resp.status_code}]')

    def import_target_platform(self, import_platform: ArkPCloudImportTargetPlatform) -> ArkPCloudTargetPlatform:
        """
        Tries to import a platform zip data
        https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/WebServices/ImportPlatform.htm

        Args:
            import_platform (ArkPCloudImportTargetPlatform): _description_

        Raises:
            ArkServiceException: _description_

        Returns:
            ArkPCloudTargetPlatform: _description_
        """
        self._logger.info('Importing target platform')
        platform_path = Path(import_platform.platform_zip_path)
        if not platform_path.exists():
            raise ArkServiceException(f'Given path [{str(platform_path)}] does not exist or is invalid')
        zip_data = b64encode(platform_path.read_bytes()).decode()
        resp: Response = self._client.post(IMPORT_PLATFORM_URL, json={'ImportFile': zip_data})
        if resp.status_code == HTTPStatus.CREATED:
            try:
                platform_id = resp.json()['PlatformID']
                platforms = self.list_target_platforms_by(ArkPCloudTargetPlatformsFilter(platform_id=platform_id))
                if platforms:
                    return platforms[0]
                raise ArkServiceException('Failed to find target platform after importing it')

            except (ValidationError, JSONDecodeError, KeyError) as ex:
                self._logger.exception(f'Failed to parse import platform response [{str(ex)}] - [{resp.text}]')
                raise ArkServiceException(f'Failed to parse import platform response [{str(ex)}]') from ex
        raise ArkServiceException(f'Failed to import platform [{resp.text}] - [{resp.status_code}]')

    def export_platform(self, export_platform: ArkPCloudExportPlatform) -> None:
        """
        Exports a platform zip data to a given folder by id
        https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/SDK/ExportPlatform.htm

        Args:
            export_platform (ArkPCloudExportPlatform): _description_

        Raises:
            ArkServiceException: _description_
        """
        self._logger.info(f'Exporting platform [{export_platform.platform_id}] to folder [{export_platform.output_folder}]')
        output_folder = Path(export_platform.output_folder)
        output_folder.mkdir(exist_ok=True, parents=True)
        resp: Response = self._client.post(EXPORT_PLATFORM_URL.format(platform_id=export_platform.platform_id))
        if resp.status_code != HTTPStatus.OK:
            raise ArkServiceException(f'Failed to export platform [{resp.text}] - [{resp.status_code}]')
        (output_folder / export_platform.platform_id).write_bytes(resp.text.encode())

    def export_target_platform(self, export_platform: ArkPCloudExportTargetPlatform) -> None:
        """
        Exports a platform zip data to a given folder by id
        https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/SDK/ExportPlatform.htm

        Args:
            export_platform (ArkPCloudExportTargetPlatform): _description_

        Raises:
            ArkServiceException: _description_
        """
        self._logger.info(f'Exporting platform [{export_platform.target_platform_id}] to folder [{export_platform.output_folder}]')
        output_folder = Path(export_platform.output_folder)
        output_folder.mkdir(exist_ok=True, parents=True)
        target_platform: ArkPCloudTargetPlatform = self.target_platform(
            ArkPCloudGetTargetPlatform(target_platform_id=export_platform.target_platform_id)
        )
        resp: Response = self._client.post(EXPORT_TARGET_PLATFORM_URL.format(target_platform_id=export_platform.target_platform_id))
        if resp.status_code != HTTPStatus.OK:
            raise ArkServiceException(f'Failed to export platform [{resp.text}] - [{resp.status_code}]')
        (output_folder / target_platform.platform_id).write_bytes(resp.text.encode())

    def platforms_stats(self) -> ArkPCloudPlatformsStats:
        """
        Calculates platforms stats

        Returns:
            ArkPCloudPlatformsStats: _description_
        """
        self._logger.info('Calculating platform statistics')
        platforms = self.list_platforms()
        platforms_stats = ArkPCloudPlatformsStats.construct()
        platforms_stats.platforms_count = len(platforms)

        # Get platforms per platform type
        platform_types: Set[ArkPCloudPlatformType] = {p.general.platform_type for p in platforms}
        platforms_stats.platforms_count_by_type = {
            pt: len([p for p in platforms if p.general.platform_type == pt]) for pt in platform_types
        }

        return platforms_stats

    def __list_target_platforms_by_filters(
        self,
        active: Optional[bool] = None,
        system_type: Optional[str] = None,
        periodic_verify: Optional[bool] = None,
        manual_verify: Optional[bool] = None,
        periodic_change: Optional[bool] = None,
        manual_change: Optional[bool] = None,
        automatic_reconcile: Optional[bool] = None,
        manual_reconcile: Optional[bool] = None,
    ) -> List[ArkPCloudTargetPlatform]:
        args = {}
        if active is not None:
            args['active'] = active
        if system_type is not None:
            args['systemType'] = system_type
        if periodic_verify is not None:
            args['periodicVerify'] = str(periodic_verify)
        if manual_verify is not None:
            args['manualVerify'] = str(manual_verify)
        if periodic_change is not None:
            args['periodicChange'] = str(periodic_change)
        if manual_change is not None:
            args['manualChange'] = str(manual_change)
        if automatic_reconcile is not None:
            args['automaticReconcile'] = str(automatic_reconcile)
        if manual_reconcile is not None:
            args['manualReconcile'] = str(manual_reconcile)
        params = " AND ".join([f"{k} eq {v}" for k, v in args.items()])
        resp: Response = self._client.get(TARGET_PLATFORMS_URL, params=params)
        if resp.status_code == HTTPStatus.OK:
            try:
                return parse_obj_as(List[ArkPCloudTargetPlatform], resp.json()['Platforms'])
            except (ValidationError, JSONDecodeError, KeyError) as ex:
                self._logger.exception(f'Failed to parse list target platforms response [{str(ex)}] - [{resp.text}]')
                raise ArkServiceException(f'Failed to parse list target platforms response [{str(ex)}]') from ex
        raise ArkServiceException(f'Failed to list target platforms [{resp.text}] - [{resp.status_code}]')

    def list_target_platforms(self) -> List[ArkPCloudTargetPlatform]:
        """
        Lists all the target platforms visible to the user
        https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-get-target-platforms.htm

        Returns:
            List[ArkPCloudTargetPlatform]: _description_
        """
        self._logger.info('Listing all target platforms')
        return self.__list_target_platforms_by_filters()

    def list_target_platforms_by(self, target_platforms_filter: ArkPCloudTargetPlatformsFilter) -> List[ArkPCloudTargetPlatform]:
        """
        Lists target platforms by given filters
        https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-get-target-platforms.htm

        Args:
            target_platforms_filter (ArkPCloudTargetPlatformsFilter): _description_

        Returns:
            List[ArkPCloudTargetPlatform]: _description_
        """
        self._logger.info(f'Listing target platforms by filter [{target_platforms_filter}]')
        target_platforms = self.__list_target_platforms_by_filters(
            active=target_platforms_filter.active,
            system_type=target_platforms_filter.system_type,
            periodic_verify=target_platforms_filter.periodic_verify,
            manual_verify=target_platforms_filter.manual_verify,
            periodic_change=target_platforms_filter.periodic_change,
            manual_change=target_platforms_filter.manual_change,
            automatic_reconcile=target_platforms_filter.automatic_reconcile,
            manual_reconcile=target_platforms_filter.manual_reconcile,
        )

        # Filter by platform id
        if target_platforms_filter.platform_id:
            target_platforms = [p for p in target_platforms if fnmatch(p.platform_id.lower(), target_platforms_filter.platform_id.lower())]

        # Filter by name
        if target_platforms_filter.name:
            target_platforms = [p for p in target_platforms if fnmatch(p.name.lower(), target_platforms_filter.name.lower())]

        # Filter by active
        if target_platforms_filter.active is not None:
            target_platforms = [p for p in target_platforms if p.active is target_platforms_filter.active]

        return target_platforms

    def target_platform(self, get_target_platform: ArkPCloudGetTargetPlatform) -> ArkPCloudTargetPlatform:
        """
        Gets a target platform by id
        https://docs.cyberark.com/privilege-cloud-shared-services/Latest/en/Content/SDK/rest-api-get-target-platforms.htm

        Args:
            get_target_platform (ArkPCloudGetTargetPlatform): _description_

        Returns:
            ArkPCloudTargetPlatform: _description_

        Raises:
            ArkServiceException: _description_
        """
        self._logger.info(f'Retrieving target platform [{get_target_platform.target_platform_id}]')
        target_platform = [p for p in self.list_target_platforms() if p.id == get_target_platform.target_platform_id]
        if len(target_platform) != 1:
            raise ArkServiceException('Failed to get target platform')
        return target_platform[0]

    def activate_target_platform(self, activate_target_platform: ArkPCloudActivateTargetPlatform) -> None:
        """
        Activates a target platform by id
        https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/SDK/rest-api-activate-target-platform.htm

        Args:
            activate_target_platform (ArkPCloudActivateTargetPlatform): _description_

        Raises:
            ArkServiceException: _description_
        """
        self._logger.info(f'Activating target platform [{activate_target_platform.target_platform_id}]')
        resp: Response = self._client.post(
            ACTIVATE_TARGET_PLATFORM_URL.format(target_platform_id=activate_target_platform.target_platform_id)
        )
        if resp.status_code != HTTPStatus.OK:
            raise ArkServiceException(f'Failed to activate target platform [{resp.text}] - [{resp.status_code}]')

    def deactivate_target_platform(self, deactivate_target_platform: ArkPCloudDeactivateTargetPlatform) -> None:
        """
        Deactivates a target platform by id
        https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/SDK/rest-api-deactivate-target-platform.htm

        Args:
            deactivate_target_platform (ArkPCloudDeactivateTargetPlatform): _description_

        Raises:
            ArkServiceException: _description_
        """
        self._logger.info(f'Deactivating target platform [{deactivate_target_platform.target_platform_id}]')
        resp: Response = self._client.post(
            DEACTIVATE_TARGET_PLATFORM_URL.format(target_platform_id=deactivate_target_platform.target_platform_id)
        )
        if resp.status_code != HTTPStatus.OK:
            raise ArkServiceException(f'Failed to deactivate target platform [{resp.text}] - [{resp.status_code}]')

    def duplicate_target_platform(
        self, duplicate_target_platform: ArkPCloudDuplicateTargetPlatform
    ) -> ArkPCloudDuplicatedTargetPlatformInfo:
        """
        Duplicates a target platform by id
        https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-duplicate-target-platforms.htm

        Args:
            duplicate_target_platform (ArkPCloudDuplicateTargetPlatform): _description_

        Returns:
            ArkPCloudDuplicatedTargetPlatformInfo: _description_

        Raises:
            ArkServiceException: _description_
        """
        self._logger.info(
            f'Duplicates target platform [{duplicate_target_platform.target_platform_id}] to name [{duplicate_target_platform.name}]'
        )
        resp: Response = self._client.post(
            DUPLICATE_TARGET_PLATFORM_URL.format(target_platform_id=duplicate_target_platform.target_platform_id),
            json=duplicate_target_platform.dict(by_alias=True, exclude={'target_platform_id'}),
        )
        if resp.status_code == HTTPStatus.OK:
            try:
                return ArkPCloudDuplicatedTargetPlatformInfo.parse_obj(resp.json())
            except (ValidationError, JSONDecodeError, KeyError) as ex:
                self._logger.exception(f'Failed to parse duplicate target platform response [{str(ex)}] - [{resp.text}]')
                raise ArkServiceException(f'Failed to parse duplicate target platform response [{str(ex)}]') from ex
        raise ArkServiceException(f'Failed to duplicate target platform [{resp.text}] - [{resp.status_code}]')

    def delete_target_platform(self, delete_target_platform: ArkPCloudDeleteTargetPlatform) -> None:
        """
        Deletes a target platform by id
        https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-delete-target-platform.htm

        Args:
            delete_target_platform (ArkPCloudDeleteTargetPlatform): _description_

        Raises:
            ArkServiceException: _description_
        """
        self._logger.info(f'Deleting target platform [{delete_target_platform.target_platform_id}]')
        resp: Response = self._client.delete(TARGET_PLATFORM_URL.format(target_platform_id=delete_target_platform.target_platform_id))
        if resp.status_code != HTTPStatus.NO_CONTENT:
            raise ArkServiceException(f'Failed to delete target platform [{resp.text}] - [{resp.status_code}]')

    def target_platforms_stats(self) -> ArkPCloudTargetPlatformsStats:
        """
        Calculates target platforms stats

        Returns:
            ArkPCloudTargetPlatformsStats: _description_
        """
        self._logger.info('Calculating target platform statistics')
        target_platforms = self.list_target_platforms()
        target_platforms_stats = ArkPCloudTargetPlatformsStats.construct()
        target_platforms_stats.target_platforms_count = len(target_platforms)

        # Get target platforms per system type
        target_platform_system_types: Set[str] = {p.system_type for p in target_platforms}
        target_platforms_stats.target_platforms_count_by_system_type = {
            pt: len([p for p in target_platforms if p.system_type == pt]) for pt in target_platform_system_types
        }

        return target_platforms_stats

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

activate_target_platform(activate_target_platform)

Activates a target platform by id https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/SDK/rest-api-activate-target-platform.htm

Parameters:

Name Type Description Default
activate_target_platform ArkPCloudActivateTargetPlatform

description

required

Raises:

Type Description
ArkServiceException

description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
def activate_target_platform(self, activate_target_platform: ArkPCloudActivateTargetPlatform) -> None:
    """
    Activates a target platform by id
    https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/SDK/rest-api-activate-target-platform.htm

    Args:
        activate_target_platform (ArkPCloudActivateTargetPlatform): _description_

    Raises:
        ArkServiceException: _description_
    """
    self._logger.info(f'Activating target platform [{activate_target_platform.target_platform_id}]')
    resp: Response = self._client.post(
        ACTIVATE_TARGET_PLATFORM_URL.format(target_platform_id=activate_target_platform.target_platform_id)
    )
    if resp.status_code != HTTPStatus.OK:
        raise ArkServiceException(f'Failed to activate target platform [{resp.text}] - [{resp.status_code}]')

deactivate_target_platform(deactivate_target_platform)

Deactivates a target platform by id https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/SDK/rest-api-deactivate-target-platform.htm

Parameters:

Name Type Description Default
deactivate_target_platform ArkPCloudDeactivateTargetPlatform

description

required

Raises:

Type Description
ArkServiceException

description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
def deactivate_target_platform(self, deactivate_target_platform: ArkPCloudDeactivateTargetPlatform) -> None:
    """
    Deactivates a target platform by id
    https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/SDK/rest-api-deactivate-target-platform.htm

    Args:
        deactivate_target_platform (ArkPCloudDeactivateTargetPlatform): _description_

    Raises:
        ArkServiceException: _description_
    """
    self._logger.info(f'Deactivating target platform [{deactivate_target_platform.target_platform_id}]')
    resp: Response = self._client.post(
        DEACTIVATE_TARGET_PLATFORM_URL.format(target_platform_id=deactivate_target_platform.target_platform_id)
    )
    if resp.status_code != HTTPStatus.OK:
        raise ArkServiceException(f'Failed to deactivate target platform [{resp.text}] - [{resp.status_code}]')

delete_target_platform(delete_target_platform)

Deletes a target platform by id https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-delete-target-platform.htm

Parameters:

Name Type Description Default
delete_target_platform ArkPCloudDeleteTargetPlatform

description

required

Raises:

Type Description
ArkServiceException

description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
def delete_target_platform(self, delete_target_platform: ArkPCloudDeleteTargetPlatform) -> None:
    """
    Deletes a target platform by id
    https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-delete-target-platform.htm

    Args:
        delete_target_platform (ArkPCloudDeleteTargetPlatform): _description_

    Raises:
        ArkServiceException: _description_
    """
    self._logger.info(f'Deleting target platform [{delete_target_platform.target_platform_id}]')
    resp: Response = self._client.delete(TARGET_PLATFORM_URL.format(target_platform_id=delete_target_platform.target_platform_id))
    if resp.status_code != HTTPStatus.NO_CONTENT:
        raise ArkServiceException(f'Failed to delete target platform [{resp.text}] - [{resp.status_code}]')

duplicate_target_platform(duplicate_target_platform)

Duplicates a target platform by id https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-duplicate-target-platforms.htm

Parameters:

Name Type Description Default
duplicate_target_platform ArkPCloudDuplicateTargetPlatform

description

required

Returns:

Name Type Description
ArkPCloudDuplicatedTargetPlatformInfo ArkPCloudDuplicatedTargetPlatformInfo

description

Raises:

Type Description
ArkServiceException

description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
def duplicate_target_platform(
    self, duplicate_target_platform: ArkPCloudDuplicateTargetPlatform
) -> ArkPCloudDuplicatedTargetPlatformInfo:
    """
    Duplicates a target platform by id
    https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-duplicate-target-platforms.htm

    Args:
        duplicate_target_platform (ArkPCloudDuplicateTargetPlatform): _description_

    Returns:
        ArkPCloudDuplicatedTargetPlatformInfo: _description_

    Raises:
        ArkServiceException: _description_
    """
    self._logger.info(
        f'Duplicates target platform [{duplicate_target_platform.target_platform_id}] to name [{duplicate_target_platform.name}]'
    )
    resp: Response = self._client.post(
        DUPLICATE_TARGET_PLATFORM_URL.format(target_platform_id=duplicate_target_platform.target_platform_id),
        json=duplicate_target_platform.dict(by_alias=True, exclude={'target_platform_id'}),
    )
    if resp.status_code == HTTPStatus.OK:
        try:
            return ArkPCloudDuplicatedTargetPlatformInfo.parse_obj(resp.json())
        except (ValidationError, JSONDecodeError, KeyError) as ex:
            self._logger.exception(f'Failed to parse duplicate target platform response [{str(ex)}] - [{resp.text}]')
            raise ArkServiceException(f'Failed to parse duplicate target platform response [{str(ex)}]') from ex
    raise ArkServiceException(f'Failed to duplicate target platform [{resp.text}] - [{resp.status_code}]')

export_platform(export_platform)

Exports a platform zip data to a given folder by id https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/SDK/ExportPlatform.htm

Parameters:

Name Type Description Default
export_platform ArkPCloudExportPlatform

description

required

Raises:

Type Description
ArkServiceException

description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
def export_platform(self, export_platform: ArkPCloudExportPlatform) -> None:
    """
    Exports a platform zip data to a given folder by id
    https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/SDK/ExportPlatform.htm

    Args:
        export_platform (ArkPCloudExportPlatform): _description_

    Raises:
        ArkServiceException: _description_
    """
    self._logger.info(f'Exporting platform [{export_platform.platform_id}] to folder [{export_platform.output_folder}]')
    output_folder = Path(export_platform.output_folder)
    output_folder.mkdir(exist_ok=True, parents=True)
    resp: Response = self._client.post(EXPORT_PLATFORM_URL.format(platform_id=export_platform.platform_id))
    if resp.status_code != HTTPStatus.OK:
        raise ArkServiceException(f'Failed to export platform [{resp.text}] - [{resp.status_code}]')
    (output_folder / export_platform.platform_id).write_bytes(resp.text.encode())

export_target_platform(export_platform)

Exports a platform zip data to a given folder by id https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/SDK/ExportPlatform.htm

Parameters:

Name Type Description Default
export_platform ArkPCloudExportTargetPlatform

description

required

Raises:

Type Description
ArkServiceException

description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
def export_target_platform(self, export_platform: ArkPCloudExportTargetPlatform) -> None:
    """
    Exports a platform zip data to a given folder by id
    https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/SDK/ExportPlatform.htm

    Args:
        export_platform (ArkPCloudExportTargetPlatform): _description_

    Raises:
        ArkServiceException: _description_
    """
    self._logger.info(f'Exporting platform [{export_platform.target_platform_id}] to folder [{export_platform.output_folder}]')
    output_folder = Path(export_platform.output_folder)
    output_folder.mkdir(exist_ok=True, parents=True)
    target_platform: ArkPCloudTargetPlatform = self.target_platform(
        ArkPCloudGetTargetPlatform(target_platform_id=export_platform.target_platform_id)
    )
    resp: Response = self._client.post(EXPORT_TARGET_PLATFORM_URL.format(target_platform_id=export_platform.target_platform_id))
    if resp.status_code != HTTPStatus.OK:
        raise ArkServiceException(f'Failed to export platform [{resp.text}] - [{resp.status_code}]')
    (output_folder / target_platform.platform_id).write_bytes(resp.text.encode())

import_platform(import_platform)

Tries to import a platform zip data https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/WebServices/ImportPlatform.htm

Parameters:

Name Type Description Default
import_platform ArkPCloudImportPlatform

description

required

Raises:

Type Description
ArkServiceException

description

Returns:

Name Type Description
ArkPCloudPlatform ArkPCloudPlatform

description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
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
def import_platform(self, import_platform: ArkPCloudImportPlatform) -> ArkPCloudPlatform:
    """
    Tries to import a platform zip data
    https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/WebServices/ImportPlatform.htm

    Args:
        import_platform (ArkPCloudImportPlatform): _description_

    Raises:
        ArkServiceException: _description_

    Returns:
        ArkPCloudPlatform: _description_
    """
    self._logger.info('Importing platform')
    platform_path = Path(import_platform.platform_zip_path)
    if not platform_path.exists():
        raise ArkServiceException(f'Given path [{str(platform_path)}] does not exist or is invalid')
    zip_data = b64encode(platform_path.read_bytes()).decode()
    resp: Response = self._client.post(IMPORT_PLATFORM_URL, json={'ImportFile': zip_data})
    if resp.status_code == HTTPStatus.CREATED:
        try:
            platform_id = resp.json()['PlatformID']
            return self.platform(ArkPCloudGetPlatform(platform_id=platform_id))
        except (ValidationError, JSONDecodeError, KeyError) as ex:
            self._logger.exception(f'Failed to parse import platform response [{str(ex)}] - [{resp.text}]')
            raise ArkServiceException(f'Failed to parse import platform response [{str(ex)}]') from ex
    raise ArkServiceException(f'Failed to import platform [{resp.text}] - [{resp.status_code}]')

import_target_platform(import_platform)

Tries to import a platform zip data https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/WebServices/ImportPlatform.htm

Parameters:

Name Type Description Default
import_platform ArkPCloudImportTargetPlatform

description

required

Raises:

Type Description
ArkServiceException

description

Returns:

Name Type Description
ArkPCloudTargetPlatform ArkPCloudTargetPlatform

description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
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
def import_target_platform(self, import_platform: ArkPCloudImportTargetPlatform) -> ArkPCloudTargetPlatform:
    """
    Tries to import a platform zip data
    https://docs.cyberark.com/Product-Doc/OnlineHelp/PrivCloud-SS/Latest/en/Content/WebServices/ImportPlatform.htm

    Args:
        import_platform (ArkPCloudImportTargetPlatform): _description_

    Raises:
        ArkServiceException: _description_

    Returns:
        ArkPCloudTargetPlatform: _description_
    """
    self._logger.info('Importing target platform')
    platform_path = Path(import_platform.platform_zip_path)
    if not platform_path.exists():
        raise ArkServiceException(f'Given path [{str(platform_path)}] does not exist or is invalid')
    zip_data = b64encode(platform_path.read_bytes()).decode()
    resp: Response = self._client.post(IMPORT_PLATFORM_URL, json={'ImportFile': zip_data})
    if resp.status_code == HTTPStatus.CREATED:
        try:
            platform_id = resp.json()['PlatformID']
            platforms = self.list_target_platforms_by(ArkPCloudTargetPlatformsFilter(platform_id=platform_id))
            if platforms:
                return platforms[0]
            raise ArkServiceException('Failed to find target platform after importing it')

        except (ValidationError, JSONDecodeError, KeyError) as ex:
            self._logger.exception(f'Failed to parse import platform response [{str(ex)}] - [{resp.text}]')
            raise ArkServiceException(f'Failed to parse import platform response [{str(ex)}]') from ex
    raise ArkServiceException(f'Failed to import platform [{resp.text}] - [{resp.status_code}]')

list_platforms()

Lists all the platforms visible to the user https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-get-platforms.htm

Returns:

Type Description
List[ArkPCloudPlatform]

List[ArkPCloudPlatform]: description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
76
77
78
79
80
81
82
83
84
85
def list_platforms(self) -> List[ArkPCloudPlatform]:
    """
    Lists all the platforms visible to the user
    https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-get-platforms.htm

    Returns:
        List[ArkPCloudPlatform]: _description_
    """
    self._logger.info('Listing all platforms')
    return self.__list_platforms_by_filters()

list_platforms_by(platforms_filter)

Lists platforms by given filters https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-get-platforms.htm

Parameters:

Name Type Description Default
platforms_filter ArkPCloudPlatformsFilter

description

required

Returns:

Type Description
List[ArkPCloudPlatform]

List[ArkPCloudPlatform]: description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def list_platforms_by(self, platforms_filter: ArkPCloudPlatformsFilter) -> List[ArkPCloudPlatform]:
    """
    Lists platforms by given filters
    https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-get-platforms.htm

    Args:
        platforms_filter (ArkPCloudPlatformsFilter): _description_

    Returns:
        List[ArkPCloudPlatform]: _description_
    """
    self._logger.info(f'Listing platforms by filter [{platforms_filter}]')
    return self.__list_platforms_by_filters(
        active=platforms_filter.active, platform_type=platforms_filter.platform_type, platform_name=platforms_filter.platform_name
    )

list_target_platforms()

Lists all the target platforms visible to the user https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-get-target-platforms.htm

Returns:

Type Description
List[ArkPCloudTargetPlatform]

List[ArkPCloudTargetPlatform]: description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
288
289
290
291
292
293
294
295
296
297
def list_target_platforms(self) -> List[ArkPCloudTargetPlatform]:
    """
    Lists all the target platforms visible to the user
    https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-get-target-platforms.htm

    Returns:
        List[ArkPCloudTargetPlatform]: _description_
    """
    self._logger.info('Listing all target platforms')
    return self.__list_target_platforms_by_filters()

list_target_platforms_by(target_platforms_filter)

Lists target platforms by given filters https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-get-target-platforms.htm

Parameters:

Name Type Description Default
target_platforms_filter ArkPCloudTargetPlatformsFilter

description

required

Returns:

Type Description
List[ArkPCloudTargetPlatform]

List[ArkPCloudTargetPlatform]: description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
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
def list_target_platforms_by(self, target_platforms_filter: ArkPCloudTargetPlatformsFilter) -> List[ArkPCloudTargetPlatform]:
    """
    Lists target platforms by given filters
    https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/SDK/rest-api-get-target-platforms.htm

    Args:
        target_platforms_filter (ArkPCloudTargetPlatformsFilter): _description_

    Returns:
        List[ArkPCloudTargetPlatform]: _description_
    """
    self._logger.info(f'Listing target platforms by filter [{target_platforms_filter}]')
    target_platforms = self.__list_target_platforms_by_filters(
        active=target_platforms_filter.active,
        system_type=target_platforms_filter.system_type,
        periodic_verify=target_platforms_filter.periodic_verify,
        manual_verify=target_platforms_filter.manual_verify,
        periodic_change=target_platforms_filter.periodic_change,
        manual_change=target_platforms_filter.manual_change,
        automatic_reconcile=target_platforms_filter.automatic_reconcile,
        manual_reconcile=target_platforms_filter.manual_reconcile,
    )

    # Filter by platform id
    if target_platforms_filter.platform_id:
        target_platforms = [p for p in target_platforms if fnmatch(p.platform_id.lower(), target_platforms_filter.platform_id.lower())]

    # Filter by name
    if target_platforms_filter.name:
        target_platforms = [p for p in target_platforms if fnmatch(p.name.lower(), target_platforms_filter.name.lower())]

    # Filter by active
    if target_platforms_filter.active is not None:
        target_platforms = [p for p in target_platforms if p.active is target_platforms_filter.active]

    return target_platforms

platform(get_platform)

Retrieves a platform by id https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/WebServices/GetPlatformDetails.htm

Parameters:

Name Type Description Default
get_platform ArkPCloudGetPlatform

description

required

Raises:

Type Description
ArkServiceException

description

Returns:

Name Type Description
ArkPCloudPlatform ArkPCloudPlatform

description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def platform(self, get_platform: ArkPCloudGetPlatform) -> ArkPCloudPlatform:
    """
    Retrieves a platform by id
    https://docs.cyberark.com/Product-Doc/OnlineHelp/PAS/Latest/en/Content/WebServices/GetPlatformDetails.htm

    Args:
        get_platform (ArkPCloudGetPlatform): _description_

    Raises:
        ArkServiceException: _description_

    Returns:
        ArkPCloudPlatform: _description_
    """
    self._logger.info(f'Retrieving platform [{get_platform.platform_id}]')
    resp: Response = self._client.get(PLATFORM_URL.format(platform_id=get_platform.platform_id))
    if resp.status_code == HTTPStatus.OK:
        try:
            return ArkPCloudPlatform.parse_obj(resp.json())
        except (ValidationError, JSONDecodeError) as ex:
            self._logger.exception(f'Failed to parse platform response [{str(ex)}] - [{resp.text}]')
            raise ArkServiceException(f'Failed to parse platform response [{str(ex)}]') from ex
    raise ArkServiceException(f'Failed to retrieve platform [{resp.text}] - [{resp.status_code}]')

platforms_stats()

Calculates platforms stats

Returns:

Name Type Description
ArkPCloudPlatformsStats ArkPCloudPlatformsStats

description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
def platforms_stats(self) -> ArkPCloudPlatformsStats:
    """
    Calculates platforms stats

    Returns:
        ArkPCloudPlatformsStats: _description_
    """
    self._logger.info('Calculating platform statistics')
    platforms = self.list_platforms()
    platforms_stats = ArkPCloudPlatformsStats.construct()
    platforms_stats.platforms_count = len(platforms)

    # Get platforms per platform type
    platform_types: Set[ArkPCloudPlatformType] = {p.general.platform_type for p in platforms}
    platforms_stats.platforms_count_by_type = {
        pt: len([p for p in platforms if p.general.platform_type == pt]) for pt in platform_types
    }

    return platforms_stats

target_platform(get_target_platform)

Gets a target platform by id https://docs.cyberark.com/privilege-cloud-shared-services/Latest/en/Content/SDK/rest-api-get-target-platforms.htm

Parameters:

Name Type Description Default
get_target_platform ArkPCloudGetTargetPlatform

description

required

Returns:

Name Type Description
ArkPCloudTargetPlatform ArkPCloudTargetPlatform

description

Raises:

Type Description
ArkServiceException

description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
def target_platform(self, get_target_platform: ArkPCloudGetTargetPlatform) -> ArkPCloudTargetPlatform:
    """
    Gets a target platform by id
    https://docs.cyberark.com/privilege-cloud-shared-services/Latest/en/Content/SDK/rest-api-get-target-platforms.htm

    Args:
        get_target_platform (ArkPCloudGetTargetPlatform): _description_

    Returns:
        ArkPCloudTargetPlatform: _description_

    Raises:
        ArkServiceException: _description_
    """
    self._logger.info(f'Retrieving target platform [{get_target_platform.target_platform_id}]')
    target_platform = [p for p in self.list_target_platforms() if p.id == get_target_platform.target_platform_id]
    if len(target_platform) != 1:
        raise ArkServiceException('Failed to get target platform')
    return target_platform[0]

target_platforms_stats()

Calculates target platforms stats

Returns:

Name Type Description
ArkPCloudTargetPlatformsStats ArkPCloudTargetPlatformsStats

description

Source code in ark_sdk_python/services/pcloud/platforms/ark_pcloud_platforms_service.py
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
def target_platforms_stats(self) -> ArkPCloudTargetPlatformsStats:
    """
    Calculates target platforms stats

    Returns:
        ArkPCloudTargetPlatformsStats: _description_
    """
    self._logger.info('Calculating target platform statistics')
    target_platforms = self.list_target_platforms()
    target_platforms_stats = ArkPCloudTargetPlatformsStats.construct()
    target_platforms_stats.target_platforms_count = len(target_platforms)

    # Get target platforms per system type
    target_platform_system_types: Set[str] = {p.system_type for p in target_platforms}
    target_platforms_stats.target_platforms_count_by_system_type = {
        pt: len([p for p in target_platforms if p.system_type == pt]) for pt in target_platform_system_types
    }

    return target_platforms_stats