All Entities Examples
Access Control Operations
# Entity is the entry point to all entity-related operations
access_control_entity: AccessControl = service.get_access_control_instance()
# Request Password Approval using Account name and Resource name
password_request_approval_status: str = access_control_entity.request_password_approval(
account_name="local_admin", resource_name="VM Win 1", reason="Access to Paid Software")
print(f"Password Request Approval Status is {password_request_approval_status}")
# Approve Password Request to Account using Account name, Resource name and Requester ID or Requester name
account_access_approval_status: bool = access_control_entity.approve_password_requests(
account_name="localadmin", resource_name="WIN_SERVER_CAL_1", requester="rowan_atkinson")
print(f"Account Access approval Status is {account_access_approval_status}")
# Reject Password Request to Account using Account name, Resource name and Requester ID or Requester name
account_access_rejection_status: bool = access_control_entity.reject_password_requests(
account_name="localadmin", resource_name="WIN_SERVER_CAL_1", requester="guest")
print(f"Account Access rejection Status is {account_access_rejection_status}")
# Get list of Account Password Requests sent to you
password_requests_list: list[PasswordRequestDetails] = access_control_entity.get_password_requests()
for requests in password_requests_list:
print(requests)
# Check out Account using Account name and Resource name
account_checkout_status: bool = access_control_entity.check_out_user(account_name="rowan_atkinson",
resource_name="VM Win 1")
print(f"Account Checkout Status is {account_checkout_status}")
# Check in Account by yourself using Account name and Resource name
account_checkin_by_user_status: bool = access_control_entity.check_in_user(account_name="rowan_atkinson",
resource_name="WIN_SERVER_CAL_1")
print(f"Account Checkin by User Status is {account_checkin_by_user_status}")
# Check in Account by Account Administrator using Account name and Resource name
account_checkin_by_admin_status: bool = access_control_entity.check_in_admin(account_name="rowan_atkinson",
resource_name="WIN_SERVER_CAL_1",
requester="guest")
print(f"Account Checkin by Admin Status is {account_checkin_by_admin_status}")
Account Operations
# Entity is the entry point to all entity-related operations
account_entity: Account = service.get_account_instance()
# Create Account
account_creation_status_list: list[dict] = account_entity.create(resource="WIN_SERVER_CAL_1",
account_model_list=[AccountModel(
account_name="rowan_atkinson",
password="Test@123",
account_password_policy="Strong",
notes="Account is reserved for rowan atkinson only",
record_rdp_sessions=True)])
for status in account_creation_status_list:
print(status)
# Edit Account
account_editing_status: bool = account_entity.edit(resource_name="WIN_SERVER_CAL_1", account_name="rowan_atkinson",
account_model=AccountModel(
account_name="rowan_atkinson",
notes="Account is maintained in VM"
))
print(f"Account Editing Status is {account_editing_status}")
# Get Resource ID and Account ID using Resource name and Account name
resource_and_account_id_details: ResourceAndAccountIdDetails = account_entity.get_resource_and_account_id(
resource_name="WIN_SERVER_CAL_1", account_name="localadmin")
print(resource_and_account_id_details)
# Get all accounts under Resource using Resource Name
account_details_list: list[AccountsOfResourceDetails] = account_entity.get_accounts_of_resource(
resource="WIN_SERVER_CAL_1")
for account in account_details_list:
print(account)
# Get all accounts under Resource using Resource ID
account_details_list: list[AccountsOfResourceDetails] = account_entity.get_accounts_of_resource(resource=1)
for account in account_details_list:
print(account)
# Get Account Details using Resource Name and Account Name
account_details: AccountDetails = account_entity.get_details(resource_name="WIN_SERVER_CAL_1",
account_name="localadmin")
print(account_details)
# Delete Account using Resource Name and Account Name
account_deletion_status: bool = account_entity.delete(resource_name="WIN_SERVER_CAL_1", account_name="localadmin")
print(f"Account Deletion Status is {account_deletion_status}")
# Share Account to User using User ID
account_share_to_user_status: bool = account_entity.share_to_user(resource_name="WIN_SERVER_CAL_1",
account_name="localadmin",
user=1,
access_type=AccountConstant.AccessPermission.VIEW)
print(f"Account Share to User Status is {account_share_to_user_status}")
# Share Account to User using Username
account_share_to_user_status: bool = account_entity.share_to_user(resource_name="WIN_SERVER_CAL_1",
account_name="localadmin",
user="sam_anderson",
access_type=AccountConstant.AccessPermission.VIEW)
print(f"Account Share to User Status is {account_share_to_user_status}")
# Share Account to User Group using User Group ID
account_share_to_user_group_status: bool = (
account_entity.share_to_user_group(resource_name="WIN_SERVER_CAL_1", account_name="localadmin",
user_group=1, access_type=AccountConstant.AccessPermission.MODIFY))
print(f"Account Share to User Group Status is {account_share_to_user_group_status}")
# Share Account to User Group using User Group Name
account_share_to_user_group_status: bool = (
account_entity.share_to_user_group(resource_name="WIN_SERVER_CAL_1", account_name="localadmin",
user_group="California Admins Group",
access_type=AccountConstant.AccessPermission.MODIFY))
print(f"Account Share to User Group Status is {account_share_to_user_group_status}")
Audit Operations
# Entity is the entry point to all entity-related operations
audit_entity: Audit = service.get_audit_instance()
# Get Audit Details
audit_model = AuditModel(
audit_type=AuditConstant.Type.RESOURCE,
date=datetime.datetime.today()
)
print(audit_entity.get_details(audit_model=audit_model))
Password Operations
# Entity is the entry point to all entity-related operations
password_entity: Password = service.get_password_instance()
# Generate Password
policy = "Strong"
password = password_entity.generate_password(policy=policy)
print(f"Generated Password for Policy {policy} is {password}")
# Get Password of an Account using Names
resource_name = "resource1"
account_name = "account1"
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 of an Account using IDs
resource_id = 4
account_id = 5
password = password_entity.get_password_account(resource=resource_id, account=account_id)
print(f"Password of Account ID {account_id} under Resource ID {resource_id} is {password}")
# Change Password of an Account using Names
resource_name = "resource1"
account_name = "account1"
new_password = "Test@123"
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}")
# Change Password of an Account using IDs
resource_id = 1
account_id = 1
new_password = "Test@123"
password_reset_type = PasswordConstant.ResetType.LOCAL
password_change_status: bool = password_entity.change_password_account(resource=resource_id,
account=account_id,
new_password=new_password,
reset_type=password_reset_type)
print(f"Password Changed Status is {password_change_status}")
# Get list of Password Policies in PAM360 Server
print(password_entity.get_password_policies())
# Validate Password against provided Policy
policy_name = "Strong"
password = "Test@123"
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}")
Resource Group Operations
# Entity is the entry point to all entity-related operations
resource_group_entity: ResourceGroup = service.get_resource_group_instance()
# Create Resource Group
# Provide User ID or Username when parentGroup is provided in ResourceGroupModel
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}")
# Get Resource Group ID using Resource Group name and User ID or Username
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}")
# Get all your Resource Groups using filters
resource_group_details_list: list[ResourceGroupDetails] = resource_group_entity.get_resource_groups_of_user()
for details in resource_group_details_list:
print(details)
# Associate list of Resources to Resource Group under an Owner
resource_group_association_status_list: list[dict] = resource_group_entity.associate_resources(
resources_list=["WIN_SERVER_CAL_1", "WIN_SERVER_CAL_2"], resource_group="Test Resources",
resource_group_owner="sam_anderson")
for status in resource_group_association_status_list:
print(status)
# Dissociate list of Resources to Resource Group under an Owner
resource_group_dissociation_status_list: list[dict] = resource_group_entity.dissociate_resources(
resources_list=["WIN_SERVER_CAL_1", "WIN_SERVER_CAL_2"], resource_group="Test Resources",
resource_group_owner="sam_anderson")
for status in resource_group_dissociation_status_list:
print(status)
# Delete Resource Group using Resource Group and Resource Group Owner
resource_group_deletion_status: bool = resource_group_entity.delete(resource_group="Test Resources",
resource_group_owner="sam_anderson")
print(f"Resource Group Deletion Status is {resource_group_deletion_status}")
Resource Operations
# Entity is the entry point to all entity-related operations
resource_entity: Resource = service.get_resource_instance()
# Create Resource
create_resource_model = ResourceModel(
resource_name="WIN_SERVER_CAL_1",
dns_name="win10cal1",
resource_type="Windows",
resource_group_name="Windows Resources",
resource_description="Windows Machine 64bit Workstation",
domain_name="windowsgroup",
department="System Administration",
location="California",
resource_password_policy="Strong",
resource_custom_field={
"SERIES": "A"
},
account_name="localadmin",
account_password="Test@123",
enable_private_key=True,
owner_name="sam_anderson",
notes="Used for auditing purposes",
account_custom_field={
"LOCAL": True
}
)
resource_id: int = resource_entity.create(create_resource_model)
print(f"Resource ID of created Resource is {resource_id}")
# Edit Resource
edit_resource_model = ResourceModel(
resource_name="WIN_SERVER_CAL_2",
dns_name="win10cal2",
resource_custom_field={
"SERIES": "B"
},
)
print(resource_entity.edit(resource="WIN_SERVER_CAL_1", resource_model=edit_resource_model))
# Get Resource ID using Resource name
resource_id: int = resource_entity.get_id(resource_name="WIN_SERVER_CAL_1")
print(f"Resource ID is {resource_id}")
# Get all Resources list owned or shared to you
resource_details_list: list[ResourceDetails] = resource_entity.get_resources_of_user()
for details in resource_details_list:
print(details)
# Delete Resource using ID
resource_deletion_status: bool = resource_entity.delete(resource=1)
print(f"Resource Deletion Status is {resource_deletion_status}")
# Delete Resource using Name
resource_deletion_status: bool = resource_entity.delete(resource="WIN_SERVER_CAL_1")
print(f"Resource Deletion Status is {resource_deletion_status}")
# Share Resource to User using User ID or Username and Resource ID or Resource name
resource_share_to_user_status: bool = (resource_entity
.share_to_user(resource="WIN_SERVER_CAL_1", user="rowan_atkinson",
access_type=ResourceConstant.AccessPermission.MODIFY))
print(f"Resource Share to User Status is {resource_share_to_user_status}")
# Share Resource to User Group using User Group ID or User Group name and Resource ID or Resource name
resource_share_to_user_group_status: bool = (resource_entity
.share_to_user_group(resource="WIN_SERVER_CAL_1",
user_group="California Admins Group",
access_type=ResourceConstant.AccessPermission.MODIFY))
print(f"Resource Share to User Group Status is {resource_share_to_user_group_status}")
# Get associated Resource Groups of Resource using Resource ID
associated_resource_group_list: list[dict] = resource_entity.get_associated_resource_groups(resource=1)
for details in associated_resource_group_list:
print(details)
# Get associated Resource Groups of Resource using Resource Name
associated_resource_group_list: list[dict] = resource_entity.get_associated_resource_groups(resource="WIN_SERVER_CAL_1")
for details in associated_resource_group_list:
print(details)
# Get all Resource Types by filter
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)
User Operations
# Entity is the entry point to all entity-related operations
user_entity: User = service.get_user_instance()
# Create User
create_user_model = UserModel(
first_name="Samuel",
last_name="Anderson",
user_name="sam_anderson",
password="Test@123",
password_policy="Strong",
role="Administrator",
email="sam.anderson@test.xyz",
secondary_email="sam.anderson123@domain.xyz",
department="System Administration",
location="California",
web_access=True,
language_code="english",
mobile_access=True,
addon_access=True,
restapi_access=True,
auth_token_validity=datetime.today() + timedelta(days=28),
hostcheck=True,
hostname="sysadmin123"
)
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}")
# Edit User using Name
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}")
# Edit User using ID
edit_user_model = UserModel(
auth_token_validity=datetime.today() + timedelta(days=90),
)
edited_user_details: UserDetails = user_entity.edit_user(user=5, user_model=edit_user_model)
print(f"Edited User Status message: {edited_user_details.message}")
# Get User ID using Username
user_id: int = user_entity.get_user_id(user_name="sam_anderson")
print(f"User ID of the User is {user_id}")
# Delete User using Username
deletion_status: bool = user_entity.delete_user(user="sam_anderson")
print(f"User Deletion Status is {deletion_status}")
# Delete User using ID
deletion_status: bool = user_entity.delete_user(user=5)
print(f"User Deletion Status is {deletion_status}")
# Lock User using Username
user_lock_statu: bool = user_entity.lock(user_name="sam_anderson")
print(f"User Lock Status is {user_lock_statu}")
# Unlock User using Username
user_unlock_status: bool = user_entity.unlock(user_name="sam_anderson")
print(f"User Unlock Status is {user_unlock_status}")
# Add User to User Group using Username and User Group name
user_to_user_group_addition_status: bool = user_entity.add_to_user_group(user_name="sam_anderson",
user_group_name="California Admins Group")
print(f"User to User Group Addition Status is {user_to_user_group_addition_status}")
# Get User Group ID using User Group Name
user_group_id: int = user_entity.get_user_group_id(user_group_name="California Admins Group")
print(f"User Group ID is {user_group_id}")
# Remove User from User Group using User ID or Username list using User Group name
user_removal_from_user_group_status_list: list[dict] = user_entity.remove_from_user_group(
user_list=["sam_anderson", 1], user_group="California Admins Group")
for status in user_removal_from_user_group_status_list:
print(status)
# Remove User from User Group using User ID or Username list using User Group ID
user_removal_from_user_group_status_list: list[dict] = user_entity.remove_from_user_group(
user_list=["sam_anderson", 1], user_group=1)
for status in user_removal_from_user_group_status_list:
print(status)
# Delete User Group List using User Group names
user_group_deletion_status_list: list[dict] = user_entity.delete_user_groups(
user_group_list=["Default Group 1", "Default Group 2"])
for status in user_group_deletion_status_list:
print(status)
# Reset Multi-Factor Authentication for User using Username
mfa_reset_status: bool = user_entity.reset_multi_factor_authentication(user_name="sam_anderson")
print(f"MFA Reset Status is {mfa_reset_status}")
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}")