Python SDK API サンプル

PAM360のすべてのAPIは、PAM360で設定されたユーザーロールに基づいてPython SDKを通じてアクセスでき、データ同期を効率的に実行するカスタムアプリケーションの開発を支援します。

PAM360 Python SDK内で利用可能なすべてのAPIメソッドのサンプルコードが、関連するSDK例外とともに参照用としてここに提供されています。

詳細については、Pythonドキュメントも参照してください。

Python SDK を使用した REST API のサンプル コード

1.リソースの操作

クラス - リソース

コンストラクター - Resource(service:PAMService)

説明 - PAMService を使用して、リソース関連の関数を含むリソース エンティティ クラス インスタンスを作成します。

メソッド

説明

create

create_resource_model = ResourceModel( resource_name="CHTOW-T11-1108", dns_name="manageengine.com", resource_type="Windows", resource_group_name="Privileged Resources", resource_description="Workstation - 1108J6 - Virtual", domain_name="acme.com", department="System Administration", location="California", resource_password_policy="Strong", resource_custom_field={ "SERIES": "A" }, account_name="sysadmin", account_password="$rgvhTnCSD7h%", enable_private_key=True, owner_name="Anderson", notes="Auditing purpose", account_custom_field={ "LOCAL": True } ) resource_id: int = resource_entity.create(create_resource_model) print(f"Resource ID of the created Resource is {resource_id}")

提供された属性を使用して、PAM360 リポジトリに新しいリソースを作成します。

delete

resource_deletion_status: bool = resource_entity.delete(resource="CHTOW-T11-1108") print(f"Resource Deletion Status is {resource_deletion_status}")

指定されたリソース ID またはリソース名を入力して、PAM360 リポジトリからリソースを削除します。

edit

edit_resource_model = ResourceModel( resource_name="CHTOW-T11-1105", dns_name="gofrugal.com", resource_custom_field={ "SERIES": "B" }, ) print(resource_entity.edit(resource="CHTOW-T11-1109", resource_model=edit_resource_model))

提供された属性を使用して、PAM360 リポジトリ内のリソースを編集します。

get_all_resource_types

resource_types_list: list[ResourceTypeDetails] = resource_entity.get_all_resource_types( resource_type_filter_list=["Win"]) for resource_type in resource_types_list: print(resource_type)

リソース フィルタを使用してすべてのリソース タイプを取得します。

get_associated_resource_groups

associated_resource_group_list: list[dict] = resource_entity.get_associated_resource_groups(resource="CHTOW-T11-1109") for details in associated_resource_group_list: print(details)

リソース名を使用して、リソースに関連付けられているリソース グループのリストを取得します。

get_resources_of_user

resource_details_list: list[ResourceDetails] = resource_entity.get_resources_of_user() for details in resource_details_list: print(details)

ユーザーが共有または所有しているリソースのリストを取得します。

shareToUser

resource_share_to_user_status: bool = (resource_entity.share_to_user(resource="CHTOW-65H3", user="john", access_type=ResourceConstant.AccessPermission.MODIFY)) print(f"Resource Share to User Status is {resource_share_to_user_status}")

リソース名とユーザー名を入力として使用して、リソースをユーザーと共有します。

sharetoUsergroups

resource_share_to_user_group_status: bool = (resource_entity.share_to_user_group(resource="CHTOW-65H3", user_group="System Administration", access_type=ResourceConstant.AccessPermission.MODIFY)) print(f"Resource Share to User Group Status is {resource_share_to_user_group_status}")

リソース名とユーザー グループ名を入力として使用して、リソースをユーザー グループと共有します。

move_resource_to_trash

resource_trash_status: bool = resource_entity.trash(resource=301) print(f"Resource Trash Status is {resource_trash_status}")

ユーザーが所有するリソースをゴミ箱に移動するために使用します。

fetch_all_trashed_resources

trash_details: list[TrashDetails] = trash_entity.get_trashed_resource_details() print(f"Trashed Resource Details: {trash_details}")

PAM360でゴミ箱に移動されたユーザーの所有リソースを取得するために使用します。

restore_resources_from_trash

status: bool = trash_entity.restore_trashed_resources([301, 302]) print(f"Resource Restore Status: {status}")

PAM360のゴミ箱からユーザーが所有するリソースを復元するために使用します。

configure_remote_password_reset_mssql

configure_remote_password_reset_model = ConfigureRemotePasswordResetModel(mssql_authentication=ResourceConstant.ConfigureRemotePasswordReset.MSSQLAuthenticationType.WINDOWS, mssql_port="1433", win_auth_resource_name="resource_1", win_auth_account_name="account_1", mssql_account="admin", connection_mode=ResourceConstant.ConfigureRemotePasswordReset.ConnectionMode.SSL, resource=[1201, 304], resource_type=ResourceConstant.ConfigureRemotePasswordReset.ResourceType.MSSQL, mssql_instance_name="sample" ) configure_remote_password_reset_detail: list[RemotePasswordResetDetails] = (resource_entity.configure_remote_password_reset(configure_remote_password_reset_model) ) print(f"Configured Remote Password Reset Details: {configure_remote_password_reset_detail}")

PAM360で利用可能なMS SQLリソースのリモートパスワードリセットを設定するために使用します。




2.アクセス制御操作

クラス - AccessControl

コンストラクター - AccessControl(service)

説明 - アクセス制御関連の機能を含むアクセス制御エンティティ クラス インスタンスを作成します。

メソッド

説明

approve_password_requests

account_access_approval_status: bool = access_control_entity.approve_password_requests(account_name="sysadmin", resource_name="CHTOW-T11-1109", requester="Anderson") print(f"Account Access approval Status is {account_access_approval_status}")

リソース名とリクエストされたユーザー名を使用して、ユーザーによって発行されたパスワード アクセスリクエストを承認します。

check_in_admin

account_checkin_by_admin_status: bool = access_control_entity.check_in_admin(account_name="aut-2k19", resource_name="CHTOW-T11-1109", requester="guest") print(f"Account Checkin by Admin Status is {account_checkin_by_admin_status}")

リソース名、アカウント名、リクエスト者名を使用して、管理者としてアカウントにリクエストされたパスワードをチェックインします。

check_in_user

account_checkin_by_user_status: bool = access_control_entity.check_in_user(account_name="sysadmin", resource_name="CHTOW-T11-1109") print(f"Account Checkin by User Status is {account_checkin_by_user_status}")

リソース名とアカウント名を使用して、ユーザーとしてアカウントにリクエストされたパスワードをチェックインします。

check_out_user

account_checkout_status: bool = access_control_entity.check_out_user(account_name="sysadmin", resource_name="CHTOW-T11-1109") print(f"Account Checkout Status is {account_checkout_status}")

承認後にリソース名と理由を使用して、アカウントに対してリクエストされたパスワードをチェックアウトします。

get_password_requests

password_requests_list: list[PasswordRequestDetails] = access_control_entity.get_password_requests() for requests in password_requests_list: print(requests)

承認待ちのパスワード アクセスリクエストのリストを取得します。

reject_password_requests

account_access_rejection_status: bool = access_control_entity.reject_password_requests(account_name="sysadmin", resource_name="CHTOW-T11-1109", requester="guest") print(f"Account Access rejection Status is {account_access_rejection_status}")

リソース名とリクエストされたユーザー名を使用してユーザーが発行したパスワード アクセスリクエストを拒否します。

request_password_approval

password_request_approval_status: str = access_control_entity.request_password_approval(account_name="sysadmin", resource_name="CHTOW-T11-1109", reason="Access to a Software") print(f"Password Request Approval Status is {password_request_approval_status}")

アカウント名とリクエスト理由を使用して、アカウントへのパスワード アクセスをリクエストします。




3.アカウントの操作

クラス - Account

コンストラクター - Account(service)

説明 - アカウント関連の操作を含む Account エンティティ クラス インスタンスを作成します。

メソッド

説明

create

account_creation_status_list: list[dict] = account_entity.create(resource="CHTOW-T11-1109", account_model_list=[AccountModel(account_name="aud-2024", password="JhfEr54#*hb", account_password_policy="Strong", notes="Account for auditing purpose", record_rdp_sessions=True)]) for status in account_creation_status_list: print(status)

指定されたアカウント属性とリソース名を使用して、リソースに新しいアカウントを作成します。

delete

account_deletion_status: bool = account_entity.delete(resource_name="CHTOW-T11-1109", account_name="guest") print(f"Account Deletion Status is {account_deletion_status}")

指定されたリソース名とアカウント名を入力して、リソース内のアカウントを削除します。

edit

account_editing_status: bool = account_entity.edit(resource_name="CHTOW-T12-1106", account_name="guest", account_model=AccountModel(account_name="aut-2k23", notes="Account maintained in VM")) print(f"Account Editing Status is {account_editing_status}")

指定されたアカウント属性とリソース名を使用して、リソース内のアカウントを編集します。

get_accounts_of_resource

account_details_list: list[AccountsOfResourceDetails] = account_entity.get_accounts_of_resource(resource="CHTOW-T12-1106") for account in account_details_list: print(account)

指定されたリソース ID またはリソース名を入力として、リソースの下にあるアカウントのリストを取得します。

get_details

account_details: AccountDetails = account_entity.get_details(resource_name="CHTOW-T12-1106", account_name="sysadmin") print(account_details)

リソース名とアカウント名を使用して、リソース内のアカウントの詳細を取得します。

get_resource_and_accounts_id

resource_and_account_id_details: ResourceAndAccountIdDetails = account_entity.get_resource_and_account_id(resource_name="CHTOW-T12-1106", account_name="guest") print(resource_and_account_id_details)

リソース名とアカウント名を使用して、アカウント ID と関連するリソース ID を取得します。

shareToUser

account_share_to_user_status: bool = account_entity.share_to_user(resource_name="CHTOW-T12-1106", account_name="aut-2k23", user="anderson", access_type=AccountConstant.AccessPermission.VIEW) print(f"Account Share to User Status is {account_share_to_user_status}")

リソース名、アカウント名、ユーザー名を入力として使用して、ユーザーにアカウントを共有します。

shareToUserGroup

account_share_to_user_group_status: bool = ( account_entity.share_to_user_group(resource_name="CHTOW-T12-1106", account_name="aut-2k23", user_group="System Administration", access_type=AccountConstant.AccessPermission.MODIFY)) print(f"Account Share to User Group Status is {account_share_to_user_group_status}")

リソース名、アカウント名、ユーザー グループ名を入力として使用して、リソースをユーザー グループと共有します。

move_account_to_trash

status: bool = account_entity.trash(301, 302) print(f"Account Move Status: {bool}")

PAM360でユーザーが所有するアカウントをゴミ箱に移動するために使用します。

fetch_all_trashed_accounts

trash_details: list[TrashDetails] = trash_entity.get_trashed_account_details() print(f"Trashed Account Details: {trash_details}")

PAM360でゴミ箱に移動されたユーザーの所有アカウントを取得するために使用します。

restore_accounts_from_trash

status: bool = trash_entity.restore_trashed_accounts( resource=301, trash=[301, 302] ) print(f"Account Restore Status: {status}")

PAM360のゴミ箱からユーザーが所有するアカウントを復元するために使用します。




4.パスワードの操作

クラス - Password

コンストラクター - Password(service)

説明 - パスワード関連の操作を含むパスワード エンティティ クラス インスタンスを作成します。

メソッド

説明

change_password_account

resource_name = "CHTOW-T12-1106" account_name = "aut-2k23" new_password = "Drg56&*hjk$" password_reset_type = PasswordConstant.ResetType.LOCAL password_change_status: bool = password_entity.change_password_account(resource=resource_name, account=account_name, new_password=new_password, reset_type=password_reset_type) print(f"Password Changed Status is {password_change_status}")

リソース名とアカウント名を使用してアカウントのパスワードを変更します。

generate_password

policy = "Strong>" password = password_entity.generate_password(policy=policy) print(f"Generated Password for Policy {policy} is {password}")

提供されたポリシーに基づいて新しいパスワードを生成します。

get_password_account

resource_name = "CHTOW-T12-1106" account_name = "aut-2k23" password = password_entity.get_password_account(resource=resource_name, account=account_name) print(f"Password of Account {account_name} under Resource {resource_name} is {password}")

提供されたリソース名とアカウント名を使用してアカウントのパスワードを取得します。

get_password_policies

print(password_entity.get_password_policies())

組織内で利用可能なすべてのパスワード ポリシーを取得します。

validate_password

policy_name = "Strong" password = "fyuiKEFD34#%" password_validation_status: bool = password_entity.validate_password(policy=policy_name, password=password) print(f"Validation Status of Password {password} against Policy {policy_name} is {password_validation_status}")

パスワードがパスワード ポリシーに準拠しているかどうかを検証します。

reset_passwords_accessed_by_user

password_reset_status: bool = user_entity.reset_owned_and_shared_passwords(user=301, emails_to_notify=["admin@example.com", "security@example.com"] ) print(f"Password Reset Status: {password_reset_status}")

PAM360でユーザーが所有するすべてのパスワード、およびそのユーザーと共有されているすべてのパスワードをリセットするために使用します。




5.ユーザー管理

クラス - User

コンストラクター - User(PAMService service, APIRequestHandler rest)

説明 - ユーザー関連の操作を含む User エンティティ クラス インスタンスを作成します。

メソッド

説明

add_to_user_group

user_to_user_group_addition_status: bool = user_entity.add_to_user_group(user_name="anderson", user_group_name="SDP Group") print(f"User to User Group Addition Status is {user_to_user_group_addition_status}")

ユーザー名とユーザー グループ名を入力として使用して、ユーザーをユーザー グループに追加します。

create_user

create_user_model = UserModel( first_name="Samuel", last_name="Anderson", user_name="sam-anderson", password="WrE#RTgHBj%6", password_policy="Strong", role="Administrator", email="sam.anderson@zykler.com", department="System Administration", location="Noida", web_access=True, language_code="english", mobile_access=True, addon_access=True, restapi_access=True, auth_token_validity=datetime.today() + timedelta(days=180), hostcheck=True, hostname="sam-7276" ) created_user_details: UserDetails = user_entity.create_user(user_model=create_user_model) print(f"User Creation Status message: {created_user_details.message}") print(f"User API Auth Token: {created_user_details.auth_token}")

提供されたユーザー属性を入力として使用して、PAM360 アクセス用の新しいユーザー アカウントを作成します。

delete_user

deletion_status: bool = user_entity.delete_user(user="sam-anderson") print(f"User Deletion Status is {deletion_status}")

ユーザー名を使用してユーザー アカウントを削除します。

delete_user_groups

user_group_deletion_status_list: list[dict] = user_entity.delete_user_groups(user_group_list=["System Administration", "Interns and Trainees"]) for status in user_group_deletion_status_list: print(status)

ユーザー グループ名またはユーザー グループ ID を使用してユーザー グループを削除します。

edit_user

edit_user_model = UserModel(auth_token_validity=datetime.today() + timedelta(days=90), ) edited_user_details: UserDetails = user_entity.edit_user(user="sam-anderson", user_model=edit_user_model) print(f"Edited User Status message: {edited_user_details.message}")

提供されたユーザー属性を入力として PAM360 ユーザー アカウントを編集します。

get_user_group_id

user_group_id: int = user_entity.get_user_group_id(user_group_name="SDP Group") print(f"User Group ID is {user_group_id}")

ユーザー グループ名を使用して、ユーザー グループのユーザー グループ ID を取得します。

get_user_id

user_id: int = user_entity.get_user_id(user_name="sam-anderson") print(f"User ID of the User is {user_id}")

指定された組織のユーザー名を使用してユーザーのユーザー ID を取得します。

lock

user_lock_statu: bool = user_entity.lock(user_name="sam-anderson") print(f"User Lock Status is {user_lock_statu}")

ユーザー名を使用してユーザー アカウントをロックします。

auth_token

auth_token: str = user_entity.regenerate_auth_token(expiry_date=datetime.today() + timedelta(days=28)) print(f"Regenerated User RestAPI Auth Token is {auth_token}")

現在の SDK ユーザーの認証トークンを再生成します。

remove_from_user_group

user_removal_from_user_group_status_list: list[dict] = user_entity.remove_from_user_group(user_list=["sam-anderson", 1], user_group="SDP Group") for status in user_removal_from_user_group_status_list: print(status)

ユーザー グループ名またはユーザー グループ ID とともにユーザー名とユーザー ID を使用して、ユーザー グループからユーザーを削除します。

reset_multi_factor_authentication

mfa_reset_status: bool = user_entity.reset_multi_factor_authentication(user_name="sam-anderson") print(f"MFA Reset Status is {mfa_reset_status}")

ユーザー名を使用してユーザーの多要素認証をリセットします。

unlock

user_unlock_status: bool = user_entity.unlock(user_name="sam-anderson") print(f"User Unlock Status is {user_unlock_status}")

ユーザー名を使用してユーザー アカウントのロックを解除します。




6.リソースグループ操作

クラス - ResourceGroup

コンストラクター - ResourceGroup(service:PAMService)

説明 - リソース グループ関連の操作を含むリソース グループ クラス インスタンスを作成します。

メソッド

説明

associate_resources

resource_group_association_status_list: list[dict] = resource_group_entity.associate_resources( resources_list=["CHTOW-T12-1106", "CHTOW-T09-1109"], resource_group="sysadmin resources", resource_group_owner="sam-anderson") for status in resource_group_association_status_list: print(status)

リソース ID とリソース グループ ID、またはリソース名とリソース グループ名を使用して、リソースを静的リソース グループに関連付けます。

create

create_resource_group = ResourceGroupModel( resource_group_name="VM Windows Resources", parent_group="VM Instance Resources", group_type=ResourceGroupConstant.GroupType.DYNAMIC, description="Resources maintained in Virtual Machines", password_policy="Strong", dynamic_group_criteria_list=[DynamicGroupCriteria(condition=ResourceGroupConstant.Condition.RESOURCE_NAME, value="VM"), DynamicGroupCriteria(condition=ResourceGroupConstant.Condition.RESOURCE_TYPE, value="Windows")], match_all_criteria=True ) resource_group_creation_status: bool = resource_group_entity.create(resource_group_model=create_resource_group, user="sam-anderson") print(f"Resource Group Creation Status is {resource_group_creation_status}")

指定された属性を持つ動的リソース グループを作成します。

delete

resource_group_deletion_status: bool = resource_group_entity.delete(resource_group="Intern Resources", resource_group_owner="sam-anderson") print(f"Resource Group Deletion Status is {resource_group_deletion_status}")

リソース名を使用してリソース グループを削除します。

disassociate_resources

resource_group_dissociation_status_list: list[dict] = resource_group_entity.dissociate_resources( resources_list=["CHTOW-T12-1106", "CHTOW-T08-1109"], resource_group="Intern Resources", resource_group_owner="sam-anderson") for status in resource_group_dissociation_status_list: print(status)

リソース ID とリソース グループ ID、またはリソース名とリソース グループ名を使用して、静的リソース グループへのリソースの関連付けを解除します。

get_id

resource_group_id: int = resource_group_entity.get_id(resource_group_name="VM Windows Resources", user="sam-anderson") print(f"Resource Group ID is {resource_group_id}")

リソース グループ名を使用してリソース グループ ID を取得します。

get_resource_groups_of_user

resource_group_details_list: list[ResourceGroupDetails] = resource_group_entity.get_resource_groups_of_user() for details in resource_group_details_list: print(details)

所有しているまたは自分のユーザー アカウントに共有されているすべてのリソース グループを取得します。




7.監査操作

クラス - Audit

コンストラクター - Audit(service:PAMService)

説明 - 監査関連の操作を含む監査エンティティ クラス インスタンスを作成します。

メソッド

説明

get_details

audit_model = AuditModel(audit_type=AuditConstant.Type.RESOURCE, date=datetime.datetime.today()) print(audit_entity.get_details(audit_model=audit_model))

PAM360 リポジトリからリソースとユーザーの監査の詳細を取得します。




8.組織の操作

クラス - Organizations

コンストラクター - Organizations(PAMService service, APIRequestHandler rest)

説明 - リソースグループ関連の操作を含む組織クラスのインスタンスを作成します。

メソッド

説明

manage_org_access

manage_org_model = ManageOrgModel( users=[301, 302], user_groups=[601, 602], manage_permission=OrganizationConstants.ManageOrganization.GRANT, org_ids=[2, 302], approval_admin=901 ) manage_org_detail: list[ManageOrgDetails] = organization_entity.manage_organization(manage_org_model) print(f"Managed Organization Details: {manage_org_detail}")

承認ワークフローにおけるクライアント組織の管理権限を、ユーザーに対して付与または取り消すよう申請します。




9.レポート操作

クラス - Reports

コンストラクター - Reports(PAMService service, APIRequestHandler rest)

説明 - レポート関連の操作を含むレポートクラスのインスタンスを作成します。

メソッド

説明

fetch_all_users_report

create_search_model = SearchModel( limit=10, start_index=0, search_value="admin", search_column=SearchConstant.UserSearchColumn.USER_NAME, search_operator=SearchConstant.SearchOperator.STARTS_WITH) report_details: list[ReportDetails] = report_entity.get_user_report_details(create_search_model) print(f"Report Details: {report_details}")

PAM360で利用可能なすべてのユーザーのユーザー名およびユーザーIDを取得します。

fetch_all_user_groups_report

create_search_model = SearchModel( limit=10, start_index=0, search_value="admin", search_column=SearchConstant.UserSearchColumn.USER_GROUP_NAME, search_operator=SearchConstant.SearchOperator.STARTS_WITH ) report_details: list[ReportDetails] = report_entity.get_usergroup_report_details(create_search_model) print(f"Report Details: {report_details}")

PAM360で利用可能なすべてのユーザーグループのユーザーグループ名およびユーザーグループIDを取得します。

fetch_all_resources_report

create_search_model = SearchModel( limit=10, start_index=0, search_value="test", search_column=SearchConstant.UserSearchColumn.RESOURCE_NAME, search_operator=SearchConstant.SearchOperator.STARTS_WITH ) report_details: list[ReportDetails] = report_entity.get_resource_report_details() print(f"Resource Report Details: {report_details}")

PAM360で利用可能なすべてのリソースのリソース名とリソースIDを取得します。

fetch_all_resource_groups_report

create_search_model = SearchModel( limit=10, start_index=0, search_value="test", search_column=SearchConstant.UserSearchColumn.RESOURCE_GROUP_NAME, search_operator=SearchConstant.SearchOperator.STARTS_WITH ) report_details: list[ReportDetails] = report_entity.get_resourcegroup_report_details() print(f"Resource Report Details: {report_details}")

PAM360で利用可能なすべてのリソースグループのリソースグループ名とリソースグループIDを取得します。




Python SDK 例外

API がエラー応答を返すたびに、応答は例外のタイプに基づいていずれかの例外クラスのインスタンスになります。

  1. SDKConnectionError - PAM360 SDK が PAM360 サーバーに接続できない場合にこの例外が発生します。
  2. SDKRegistrationError - PAM360 アプリケーションで PAM360 SDK を使用して Python アプリケーション/サービスを登録するときに問題が発生した場合に発生します。
  3. SDKOperationFailedError - この例外は、必要な入力を渡した後に意図した API 操作が失敗した場合に発生します。
  4. SDKInvalidArgumentError - API 入力が無効なデータ型で解析されると例外が発生します。

SDK の異常やその他の予期しない動作などのその他のすべての例外は、SDKError クラスでスローされます。

Pythonドキュメント