### Install ark-sdk-python Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/getting_started.md Installs the ark-sdk-python package from PyPI using pip. ```shell pip3 install ark-sdk-python ``` -------------------------------- ### Get SIA Connector Setup Script Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Retrieves the installation script for a CyberArk connector, specifying connector type, OS, and pool ID. ```shell ark exec sia access connector-setup-script -ct onprem -co windows -cpi 588741d5-e059-479d-b4c4-3d821a87f012 ``` -------------------------------- ### Install DPA Connectors Remotely Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Examples for installing DPA connectors on Windows and Linux machines remotely, including authentication methods. ```shell ark exec sia access install-connector --connector-pool-id abcd --connector-type onprem --connector-os windows --target-machine 1.2.3.4 --username myuser --password mypassword ``` ```shell ark exec sia access install-connector --connector-pool-id abcd --connector-type aws --connector-os linux --target-machine 1.2.3.4 --username ec2-user --private-key-path /path/to/key.pem ``` -------------------------------- ### Upgrade ark-sdk-python Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/getting_started.md Upgrades the ark-sdk-python package to the latest version from PyPI using pip. ```shell pip3 install -U ark-sdk-python ``` -------------------------------- ### Authenticate and Provision SIA Databases, Policies, and Connectors Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/sdk_examples.md Provides a comprehensive example of authenticating to a CyberArk tenant and then provisioning SIA resources. This includes adding a database secret, a database entry, installing a connector, and defining a database policy with user access rules. ```python from ark_sdk_python.auth import ArkISPAuth from ark_sdk_python.models.auth import ArkSecret, ArkAuthProfile, ArkAuthMethod, IdentityArkAuthMethodSettings from ark_sdk_python.services.sia.api import ArkSIAAPI from ark_sdk_python.models.sia.db import ArkSIADBAddSecret, ArkSIADBSecretType, ArkSIADBAddDatabase, ArkSIADBDatabaseEngineType from ark_sdk_python.models.sia.access import ArkSIAInstallConnector, ArkOsType, ArkWorkspaceType from ark_sdk_python.models.sia.policies.db import ArkSIADBAddPolicy, ArkSIARuleStatus, ArkSIADBProvidersData, ArkSIADBPostgres, ArkSIADBAuthorizationRule, ArkSIADBConnectionInformation, ArkSIADBConnectAs, ArkSIADBLocalDBAuth, ArkSIADBAppliedTo from ark_sdk_python.models.sia.common import ArkSIAUserData, ArkSIADBResourceIdentifierType from ark_sdk_python.config import ArkSystemConfig if __name__ == '__main__': ArkSystemConfig.disable_verbose_logging() # Authenticate to the tenant with an auth profile to configure SIA username = 'user@cyberark.cloud.12345' print(f'Authenticating to the created tenant with user [{username}]') isp_auth = ArkISPAuth() isp_auth.authenticate( auth_profile=ArkAuthProfile( username=username, auth_method=ArkAuthMethod.Identity, auth_method_settings=IdentityArkAuthMethodSettings() ), secret=ArkSecret(secret='CoolPassword'), ) # Create SIA DB Secret, Database, Connector and DB Policy sia_service = ArkSIAAPI(isp_auth) print('Adding SIA DB User Secret') secret = sia_service.secrets_db.add_secret( ArkSIADBAddSecret(secret_type=ArkSIADBSecretType.UsernamePassword, username='Administrator', password='CoolPassword') ) print('Adding SIA Database') sia_service.workspace_db.add_database( ArkSIADBAddDatabase( name='mydomain.com', provider_engine=ArkSIADBDatabaseEngineType.PostgresSH, secret_id=secret.secret_id, read_write_endpoint="myendpoint.mydomain.com", ) ) print('Installing SIA Connector') sia_service.access.install_connector( ArkSIAInstallConnector( connector_os=ArkOsType.LINUX, connector_type=ArkWorkspaceType.ONPREM, connector_pool_id='pool_id', target_machine='1.2.3.4', username='root', private_key_path='/path/to/private.pem', ) ) print('Adding SIA DB Policy') sia_service.policies_db.add_policy( ArkSIADBAddPolicy( policy_name='IT Policy', status=ArkSIARuleStatus.Enabled, description='IT Policy', providers_data=ArkSIADBProvidersData( postgres=ArkSIADBPostgres( resources=['postgres-onboarded-asset'], ), ), user_access_rules=[ ArkSIADBAuthorizationRule( rule_name='IT Rule', user_data=ArkSIAUserData(roles=['DpaAdmin'], groups=[], users=[]), connection_information=ArkSIADBConnectionInformation( grant_access=2, idle_time=10, full_days=True, hours_from='07:00', hours_to='17:00', time_zone='Asia/Jerusalem', connect_as=ArkSIADBConnectAs( db_auth=[ ArkSIADBLocalDBAuth( roles=['rds_superuser'], applied_to=[ ArkSIADBAppliedTo( name='postgres-onboarded-asset', type=ArkSIADBResourceIdentifierType.RESOURCE, ) ], ), ], ), ), ) ], ) ) ``` -------------------------------- ### Login to ark CLI Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/getting_started.md Logs into the ark CLI using the configured profile and a provided ISP secret. ```shell ark login --silent --isp-secret mysecret ``` -------------------------------- ### Configure ark CLI profile silently Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/getting_started.md Configures the ark CLI profile silently with specified username and work-with-isp options. ```shell ark configure --silent --work-with-isp --isp-username myuser ``` -------------------------------- ### Get Connector Setup Script Source: https://github.com/cyberark/ark-sdk-python/blob/main/README.md Retrieves the setup script for a connector, specifying the connector type, operating system, and pool ID. ```shell ark exec sia access connector-setup-script -ct onprem -co windows -cpi 588741d5-e059-479d-b4c4-3d821a87f012 ``` -------------------------------- ### Execute ark CLI command Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/getting_started.md Executes a command using the ark CLI, specifically for generating a short-lived SSO password for the SIA service. ```shell ark exec sia sso short-lived-password ``` -------------------------------- ### List PCloud Accounts Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/sdk_examples.md This example shows how to list PCloud accounts using the ArkPCloudAccountsService. It requires authentication with specific PCloud credentials and prints the details of each account. ```python import pprint from ark_sdk_python.auth import ArkISPAuth from ark_sdk_python.models.auth import ArkAuthMethod, ArkAuthProfile, ArkSecret, IdentityArkAuthMethodSettings from ark_sdk_python.services.pcloud.accounts import ArkPCloudAccountsService if __name__ == '__main__': isp_auth = ArkISPAuth(cache_authentication=False) isp_auth.authenticate( auth_profile=ArkAuthProfile( username='smarom@cyberark.cloud.84573', auth_method=ArkAuthMethod.Identity, auth_method_settings=IdentityArkAuthMethodSettings(), ), secret=ArkSecret(secret="CoolPassword"), ) accounts_service = ArkPCloudAccountsService(isp_auth=isp_auth) for page in accounts_service.list_accounts(): for item in page: pprint.pprint(item.model_dump()) ``` -------------------------------- ### Provision SIA VM RDP Target Set and Related Resources Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/sdk_examples.md This snippet shows how to authenticate to a CyberArk tenant using an Identity Ark Auth Profile and then provision a SIA VM secret, install a connector, add a target set, and configure a VM policy for RDP access. It covers secret creation, connector installation with specified OS and connection details, target set configuration with FQDN rules, and user access rules with specific connection information for local ephemeral users. ```python if __name__ == '__main__': ArkSystemConfig.disable_verbose_logging() # Authenticate to the tenant with an auth profile to configure SIA username = 'user@cyberark.cloud.12345' print(f'Authenticating to the created tenant with user [{username}]') isp_auth = ArkISPAuth() isp_auth.authenticate( auth_profile=ArkAuthProfile( username=username, auth_method=ArkAuthMethod.Identity, auth_method_settings=IdentityArkAuthMethodSettings() ), secret=ArkSecret(secret='CoolPassword'), ) # Create SIA VM Secret, Target Set and VM Policy sia_service = ArkSIAAPI(isp_auth) print('Adding SIA VM User Secret') secret = sia_service.secrets_vm.add_secret( ArkSIAVMAddSecret( secret_type=ArkSIAVMSecretType.ProvisionerUser, provisioner_username='Administrator', provisioner_password='CoolPassword', ), ) print('Installing SIA Connector') sia_service.access.install_connector( ArkSIAInstallConnector( connector_os=ArkOsType.LINUX, connector_type=ArkWorkspaceType.ONPREM, connector_pool_id='pool_id', target_machine='1.2.3.4', username='root', private_key_path='/path/to/private.pem', ) ) print('Adding SIA Target Set') sia_service.workspace_target_sets.add_target_set( ArkSIAAddTargetSet( name='mydomain.com', secret_type=ArkSIAVMSecretType.ProvisionerUser, secret_id=secret.secret_id, ) ) print('Adding SIA VM Policy') sia_service.policies_vm.add_policy( ArkSIAVMAddPolicy( policy_name='IT Policy', status=ArkSIARuleStatus.Enabled, description='IT Policy', providers_data={ ArkWorkspaceType.ONPREM: ArkSIAVMOnPremProviderData( fqdn_rules=[ ArkSIAVMFQDNRule( operator=ArkSIAVMFQDNOperator.WILDCARD, computername_pattern='*', domain='mydomain.com', ), ], ), }, user_access_rules=[ ArkSIAVMAuthorizationRule( rule_name='IT Rule', user_data=ArkSIAUserData(roles=['DpaAdmin'], groups=[], users=[]), connection_information=ArkSIAVMConnectionInformation( grant_access=2, idle_time=10, full_days=True, hours_from='07:00', hours_to='17:00', time_zone='Asia/Jerusalem', connect_as={ ArkWorkspaceType.ONPREM: { ArkProtocolType.RDP: ArkSIAVMRDPLocalEphemeralUserConnectionData( local_ephemeral_user=ArkSIAVMLocalEphemeralUserConnectionMethodData( assign_groups=[ 'Administrators' ], ), ), }, }, ), ) ], ) ) print('Finished Successfully') ``` -------------------------------- ### List PCloud Platforms Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Lists all available platforms supported by PCloud. ```shell ark exec pcloud platforms list-platforms ``` -------------------------------- ### Create PCloud Safe Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Creates a new Safe within the PCloud environment. A Safe is a container for accounts and secrets. ```shell ark exec pcloud safes add-safe --safe-name=safe ``` -------------------------------- ### Get Tenant Default Suffix and List Directory Entities Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/sdk_examples.md This example retrieves the current tenant's default suffix and lists the names of directory entities using the ArkIdentityAPI. It requires authentication via ArkISPAuth and utilizes ArkIdentityListDirectoriesEntities for filtering. ```python from ark_sdk_python.auth import ArkISPAuth from ark_sdk_python.models.ark_profile import ArkProfileLoader from ark_sdk_python.models.services.identity.directories import ArkIdentityListDirectoriesEntities from ark_sdk_python.services.identity import ArkIdentityAPI if __name__ == "__main__": isp_auth = ArkISPAuth() isp_auth.authenticate(ArkProfileLoader().load_default_profile()) identity_api = ArkIdentityAPI(isp_auth) print(identity_api.identity_directories.tenant_default_suffix()) for page in identity_api.identity_directories.list_directories_entities(ArkIdentityListDirectoriesEntities()): print([i.name for i in page.items]) ``` -------------------------------- ### List Session Monitoring Sessions by Search Query Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Lists Session Monitoring sessions matching a specific search query. The query can filter by start time, session duration, and protocol. ```shell ark exec sm list-sessions-by --search 'startTime ge 2023-12-03T08:55:29Z AND sessionDuration GE 00:00:01 AND protocol IN SSH,RDP,Database' ``` -------------------------------- ### Install Connector on Windows Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/howto/install_sia_connectors.md Install a connector on a Windows target machine, specifying connector pool ID, type, OS, target machine IP, username, and password. ```shell ark exec sia access install-connector --connector-pool-id mypool_id --connector-type onprem --connector-os windows --target-machine 1.2.3.4 --username myuser --password mypassword ``` -------------------------------- ### Create Network and Connector Pool Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/howto/install_sia_connectors.md Create a network and a connector pool, assigning the pool to the created network. ```shell ark exec cmgr add-network --name mynetwork ``` ```shell ark exec cmgr add-pool --name mypool --assigned-network-ids mynetwork_id ``` -------------------------------- ### Get VM Policies Statistics Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Retrieves statistics for virtual machine policies within the SIA context. ```shell ark exec sia policies vm policies-stats ``` -------------------------------- ### Manage SIA Databases Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Demonstrates adding a new database to the SIA workspace and listing existing databases. ```shell ark exec sia workspaces db add-database --name mydb --provider-engine postgres-sh --read-write-endpoint myendpoint.domain.com ``` ```shell ark exec sia workspaces db list-databases ``` -------------------------------- ### Generate SSO Passwords and Oracle Wallets Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Examples for generating short-lived SSO passwords for database and RDP connections, and an Oracle wallet. ```shell ark exec sia sso short-lived-password ``` ```shell ark exec sia sso short-lived-password --service DPA-RDP ``` ```shell ark exec sia sso short-lived-oracle-wallet --folder ~/wallet ``` -------------------------------- ### Install Connector on Linux Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/howto/install_sia_connectors.md Install a connector on a Linux target machine, specifying connector pool ID, type, OS, target machine IP, username, and private key path. ```shell ark exec sia access install-connector --connector-pool-id mypool_id --connector-type aws --connector-os linux --target-machine 1.2.3.4 --username ec2-user --private-key-path /path/to/key.pem ``` -------------------------------- ### Configure Ark SDK Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/howto/install_sia_connectors.md Configure the Ark SDK, either interactively or silently with specified parameters. ```shell ark configure ``` ```shell ark configure --silent --work-with-isp --isp-username myuser ``` -------------------------------- ### Manage SIA Database Secrets Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Examples for adding and deleting database secrets within the SIA (Secrets in Applications) context. ```shell ark exec sia secrets db add-secret --secret-name mysecret --secret-type username_password --username user --password mypass ``` ```shell ark exec sia secrets db delete-secret --secret-name mysecret ``` -------------------------------- ### Login to ARK CLI Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Shows an example of performing a silent login to the ARK CLI using a pre-configured profile and ISP secret. ```bash ark login -s --isp-secret=CoolPasswordß ``` -------------------------------- ### Create Identity User Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Creates a new user with a username, email, and password. ```shell ark exec identity users create-user --username myname --email email@email.com --password MyPassword ``` -------------------------------- ### Install ark-sdk-python Source: https://github.com/cyberark/ark-sdk-python/blob/main/README.md Installs the CyberArk ARK SDK Python package using pip. ```shell pip3 install ark-sdk-python ``` -------------------------------- ### List CMGR Connector Pools Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Lists all CMGR connector pools. ```shell ark exec cmgr list-pools ``` -------------------------------- ### Create PCloud Safe Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Creates a new PCloud Safe with a specified name. ```shell ark exec pcloud safes add-safe --safe-name=safe ``` -------------------------------- ### Manage Kubernetes Configuration Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Commands to generate a kubectl configuration file, optionally saving it to a specified directory. ```shell ark exec sia k8s generate-kubeconfig ``` ```shell ark exec sia k8s generate-kubeconfig --folder=/Users/My.User/.kube ``` -------------------------------- ### List Session Activities Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Lists all activities for a given session ID. ```shell ark exec sm list-session-activities --session-id 5e62bdb8-cd81-42b8-ac72-1e06bf9c496d ``` -------------------------------- ### Manage SIA VM Target Sets Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Adds a target set for a domain within the SIA workspace. ```shell ark_public exec sia workspaces target-sets add-target-set --name mydomain.com --type Domain ``` -------------------------------- ### Add CMGR Network Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Adds a new network configuration to CMGR. This command requires a name for the network. ```shell ark exec cmgr add-network --name mynetwork ``` -------------------------------- ### Add Authentication Profile Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Adds an authentication profile with specified first and second challenges. ```shell ark exec identity policies add-authentication-profile --auth-profile-name myprofile --first-challenges UP --second-challenges EMAIL ``` -------------------------------- ### Configure Ark SDK Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/howto/enduser_rdp_workflow.md Installs and configures the Ark SDK. Supports interactive and silent configuration modes. ```shell ark configure ``` ```shell ark configure --silent --work-with-isp --isp-username myuser ``` -------------------------------- ### Fake-useragent Usage Example Source: https://github.com/cyberark/ark-sdk-python/blob/main/NOTICES.md Demonstrates how to use the fake-useragent library to generate random user-agent strings. This is useful for simulating different browsers and devices in web scraping or testing scenarios. ```python from fake_useragent import UserAgent ua = UserAgent() # Get a random user agent print(ua.random) # Get a Chrome user agent print(ua.chrome) # Get a Firefox user agent print(ua.firefox) # Get an IE user agent print(ua.ie) # Get an Opera user agent print(ua.opera) # Get a Safari user agent print(ua.safari) ``` -------------------------------- ### List Available Platforms Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Lists all available platforms that can be used for managing accounts within the PCloud environment. This helps in identifying supported connection types. ```shell ark exec pcloud platforms list-platforms ``` -------------------------------- ### Database Connection Examples Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/howto/enduser_databases_workflow.md Demonstrates two methods for connecting to a PostgreSQL database: direct login and login via Ark's exec command. ```shell psql "host=mytenant.postgres.cyberark.cloud user=user@cyberark.cloud.12345@postgres@mypostgres.fqdn.com" ``` ```shell ark exec sia db psql --target-username postgres --target-address mypostgres.fqdn.com ``` -------------------------------- ### DeepDiff Author Contributions Source: https://github.com/cyberark/ark-sdk-python/blob/main/NOTICES.md Lists the authors and their contributions to the DeepDiff library, a component of the ARK SDK Python project. This includes initial setup, porting, feature additions, and bug fixes. ```text Sep Dehpour (Seperman) Victor Hahn Castell nfvs brbsix WangFenjin timoilya Bernhard10 b-jazz finnhughes moloney serv-inc movermeyer maxrothman MartyHub sreecodeslayer Brian Maissy brianmaissy Bartosz Borowik boba-2 Juan Soler Soleronline mthaddon Necrophagos gaal-dev Ivan Piskunov van-ess0 Michał Karaś MKaras93 Christian Kothe chkothe Timothy d0b3rm4n MyrikLD Stian Jensen stianjensen Florian Klien flowolf Tim Klein timjklein36 Wilhelm Schürmannwbsch lyz-code dtorres-sf Tony Wang Tony-Wang Sun Ao eggachecat SlavaSkvortsov Håvard Thom havardthom Dhanvantari Tilak Dhanvantari Yael Mintz yaelmi3 Mikhail Khviyuzov mskhviyu Enric Pou Uwe Fladrich Michal Ozery-Flato martin-kokos kor4ik Alex Sauer-Budge William Jamieson ``` -------------------------------- ### Example Profile JSON Structure Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/howto/working_with_profiles.md Demonstrates the structure of a typical Ark profile configuration file, including profile name, description, and authentication settings. ```json { "profile_name": "ark", "profile_description": "Default Ark Profile", "auth_profiles": { "isp": { "username": "tina@cyberark.cloud.1234567", "auth_method": "identity", "auth_method_settings": { "identity_mfa_method": "email", "identity_mfa_interactive": true, "identity_application": null, "identity_url": null } } } } ``` -------------------------------- ### Requests Library Usage Source: https://github.com/cyberark/ark-sdk-python/blob/main/NOTICES.md The Requests library is a popular Python HTTP library. It simplifies making HTTP requests and is often used for interacting with web APIs. This snippet demonstrates a basic GET request. ```python import requests response = requests.get('https://api.github.com') print(response.status_code) ``` -------------------------------- ### Get SSH CA Public Key Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Retrieves the SSH CA public key. ```shell ark exec sia ssh-ca public-key ``` -------------------------------- ### Create PCloud Account Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Adds a new account to a specified PCloud Safe. This includes details like account name, platform ID, username, address, secret type, and the secret itself. ```shell ark exec pcloud accounts add-account --name account --safe-name safe --platform-id='UnixSSH' --username root --address 1.2.3.4 --secret-type=password --secret mypass ``` -------------------------------- ### Get SSH CA Public Key Script Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Retrieves the SSH CA public key as a script. ```shell ark exec sia ssh-ca public-key-script ``` -------------------------------- ### Add Authentication Profile Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Adds a new authentication profile, defining the sequence of authentication challenges. It supports specifying first and second challenges, such as 'UP' (Username/Password) and 'EMAIL'. ```shell ark exec identity policies add-authentication-profile --auth-profile-name myprofile --first-challenges UP --second-challenges EMAIL ``` -------------------------------- ### Count Session Monitoring Sessions by Search Query Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Counts Session Monitoring sessions matching a specific search query. The query can filter by start time, session duration, and protocol. ```shell ark exec sm count-sessions-by --search 'startTime ge 2023-12-03T08:55:29Z AND sessionDuration GE 00:00:01 AND protocol IN SSH,RDP,Database' ``` -------------------------------- ### LGPL - Applying Terms to New Libraries Source: https://github.com/cyberark/ark-sdk-python/blob/main/NOTICES.md Provides guidance on how to make a new library free software by applying the LGPL terms, recommending the use of standard notices. ```text How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is ``` -------------------------------- ### View Session Monitoring Sessions and Activities Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/sdk_examples.md This snippet demonstrates how to retrieve and count session monitoring sessions and their activities using the ArkSMService. It filters sessions based on start time, duration, and protocol, then iterates through sessions to fetch detailed activities. ```python from ark_sdk_python.services.sm import ArkSMService from ark_sdk_python.models.services.sm import ArkSMSessionsFilter, ArkSMGetSession, ArkSMGetSessionActivities from ark_sdk_python.models.ark_profile import ArkProfileLoader from ark_sdk_python.models.common import ArkProtocolType from ark_sdk_python.auth import ArkISPAuth from datetime import datetime, timedelta if __name__ == "__main__": isp_auth = ArkISPAuth() isp_auth.authenticate( profile=ArkProfileLoader().load_default_profile() ) sm: ArkSMService = ArkSMService(isp_auth) search_by = 'startTime ge {start_time_from} AND sessionDuration GE {min_duration} AND protocol IN {protocols}' search_by = search_by.format( start_time_from=(datetime.utcnow() - timedelta(days=30)).isoformat(timespec='seconds'), min_duration='00:00:01', protocols=','.join([ArkProtocolType.DB[0], ArkProtocolType.SSH[0], ArkProtocolType.RDP[0]]), ) sessions_filter = ArkSMSessionsFilter( search=search_by, ) print(f'session_count = {sm.count_sessions_by(sessions_filter)}') for s_page in sm.list_sessions_by(sessions_filter): for session in s_page.items: session = sm.session(ArkSMGetSession(session_id=session.session_id)) get_session_activities = ArkSMGetSessionActivities(session_id=session.session_id) print(f'session = {session}, activities_count = {sm.count_session_activities(get_session_activities)}') session_activities = [activity for page in sm.list_session_activities(get_session_activities) for activity in page.items] print(session_activities) ``` -------------------------------- ### ARK SDK Python Usage Example Source: https://github.com/cyberark/ark-sdk-python/blob/main/README.md Demonstrates basic SDK usage in Python by disabling verbose logging. ```python ArkSystemConfig.disable_verbose_logging() ``` -------------------------------- ### Authenticate and Read Tenant DB Policies Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/sdk_examples.md Demonstrates how to authenticate to a CyberArk tenant using ArkISPAuth and then retrieve database policies using the ArkSIADBPoliciesService. This involves setting up authentication credentials and profile, then initializing the service to list policies. ```python from ark_sdk_python.auth import ArkISPAuth from ark_sdk_python.models.auth import ArkSecret, ArkAuthMethod, ArkAuthProfile, IdentityArkAuthMethodSettings from ark_sdk_python.services.sia.policies.db import ArkSIADBPoliciesService if __name__ == "__main__": isp_auth = ArkISPAuth() isp_auth.authenticate( auth_profile=ArkAuthProfile( username='tina@cyberark.cloud.12345', auth_method=ArkAuthMethod.Identity, auth_method_settings=IdentityArkAuthMethodSettings() ), secret=ArkSecret(secret='CoolPassword'), ) db_policies_service = ArkSIADBPoliciesService(isp_auth) policies = db_policies_service.list_policies() ``` -------------------------------- ### Run Configure Command Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/commands/configure.md Executes the configure command to initiate the profile creation process. This can be done interactively or silently with provided arguments. ```shell ark configure ``` -------------------------------- ### Configure Profile and Log In Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/howto/simple_commands_workflow.md Configures the ark CLI profile for working with an Identity Provider Service (ISP) and logs into the tenant using provided credentials. ```shell ark configure --work-with-isp --isp-username=username ark login -s --isp-secret=secret ``` -------------------------------- ### List CMGR Connector Pools Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Lists the existing connector pools managed by CMGR (CyberArk Centralized Management of Remote Access). This provides an overview of the current pool configurations. ```shell ark exec cmgr list-pools ``` -------------------------------- ### Ark SDK Model Usage Example Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/sdk/schemas.md Illustrates how to use Ark SDK models when interacting with the Ark Identity API, specifically for creating a role. This example shows the instantiation of the API client and the call to a method with a model as input, returning another model. ```python # Assuming isp_auth is an authenticated session object and ArkIdentityAPI is the client class # from ark_sdk_python.api.identity import ArkIdentityAPI # from ark_sdk_python.models.identity import ArkIdentityCreateRole, ArkIdentityRole # identity_api = ArkIdentityAPI(isp_auth) # role: ArkIdentityRole = identity_api.identity_roles.create_role(ArkIdentityCreateRole(role_name='IT')) ``` -------------------------------- ### Create PCloud Account Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/examples/commands_examples.md Creates a new PCloud account with details including name, safe name, platform ID, username, address, and secret. ```shell ark exec pcloud accounts add-account --name account --safe-name safe --platform-id='UnixSSH' --username root --address 1.2.3.4 --secret-type=password --secret mypass ``` -------------------------------- ### Login to Ark Source: https://github.com/cyberark/ark-sdk-python/blob/main/docs/howto/install_sia_connectors.md Log in to Ark silently using a provided secret. ```shell ark login --silent --isp-secret ```