User management API
Create User
Support creating IAM users. Please refer to the following codes:
1def create_user():
2 iam_client = IamClient(iam_sample_conf.config)
3
4# User creation request as dict
5# Set username (1-64 characters, letters, numbers, or "_")
6# Set user description
7 create_user_request = {"name": "test_user", "description": "create user: test_user"}
8 response = iam_client.create_user(create_user_request)
9 print(response)
Query user
Query an IAM user with reference to the following codes:
1def get_user():
2 iam_client = IamClient(iam_sample_conf.config)
3
4# Set username
5 user_name = b'test_user'
6 response = iam_client.get_user(user_name)
7 print(response)
Update user
Support updating an IAM user with reference to the following codes:
1def update_user():
2 iam_client = IamClient(iam_sample_conf.config)
3# Current username
4 user_name = b"test_user"
5
6# User update request as dict
7# Set updated username
8# Set updated user description
9 update_user_request = {"name": "test_user_new", "description": "test-new"}
10 response = iam_client.update_user(user_name, update_user_request)
11 print(response)
Delete user
Support deleting an IAM user with reference to the following codes:
1def delete_user():
2 iam_client = IamClient(iam_sample_conf.config)
3# Current username
4 user_name = b"test_user"
5 response = iam_client.delete_user(user_name)
6 print(response)
List users
List users with reference to the following codes:
1def list_user():
2 iam_client = IamClient(iam_sample_conf.config)
3 response = iam_client.list_user()
4 print(response)
Configure console login for the user
Configure console login for the user with reference to the following codes:
1def update_user_login_profile():
2 iam_client = IamClient(iam_sample_conf.config)
3
4# Configure the user's console login request as dict
5# Set user password, not displayed in responses
6# Whether secondary verification device binding is required enabledLoginMfa
7# Secondary verification type loginMfaType, options: PHONE-Mobile phone number, TOTP virtual MFA device
8# Bound third-party login type thirdPartyType, options: UUAP-intranet account, PASSPORT-Baidu account
9# Bound third-party login account thirdPartyAccount, which can be a phone number, email, or account name when the binding type is PASSPORT
10 update_user_login_profile_request = {"password":"Pa$$word4Demo", "enabledLoginMfa": True, "loginMfaType": "PHONE",
11 "thirdPartyType": "PASSPORT", "thirdPartyAccount": "testPassportAccount"}
12
13# Current username
14 user_name = b"test_user"
15 response = iam_client.update_user_login_profile(user_name, update_user_login_profile_request)
16 print(response)
17}
Note: 1. Unbinding is performed when
thirdPartyTypeandthirdPartyAccountare both empty strings; 2. IfenabledLoginMfa":trueis set,loginMfaTypemust be specified
Query console login configuration
Query console login configuration for the user with reference to the following codes:
1def get_user_login_profile():
2 iam_client = IamClient(iam_sample_conf.config)
3# Current username
4 user_name = b"test_user"
5 response = iam_client.get_user_login_profile(user_name)
6 print(response)
Disable console login configuration
Disable user's console login configuration, i.e., disable user's console login, with reference to the following codes:
1def delete_user_login_profile():
2 iam_client = IamClient(iam_sample_conf.config)
3
4# Set current username
5 user_name = b"test_user"
6 response = iam_client.delete_user_login_profile(user_name)
7 print(response)
Create user's AccessKey
Create a set of AccessKeys for the user with reference to the following codes:
1def create_user_accesskey():
2 iam_client = IamClient(iam_sample_conf.config)
3
4# Set current username
5 user_name = b"test_user"
6 response = iam_client.create_user_accesskey(user_name)
7 print(response)
Disable user's AccessKey
Disable a specified set of AccessKeys for the user with reference to the following codes:
1def disable_user_accesskey():
2 iam_client = IamClient(iam_sample_conf.config)
3
4# Set current username
5 user_name = b"test_user"
6
7# Set the AK to be disabled
8 accesskey_id = b"test_access_key_id"
9 response = iam_client.disable_user_accesskey(user_name, accesskey_id)
10 print(response)
Enable user's AccessKey
Recover a specified set of AccessKeys for the user to "Enabled" status with reference to the following codes:
1def enable_user_accesskey():
2 iam_client = IamClient(iam_sample_conf.config)
3
4# Set current username
5 user_name = b"test_user"
6
7# Set the AK to be enabled
8 accesskey_id = b"test_access_key_id"
9 response = iam_client.enable_user_accesskey(user_name, accesskey_id)
10 print(response)
Delete user's AccessKey
Delete a specified set of AccessKeys for the user with reference to the following codes:
1def delete_user_accesskey():
2 iam_client = IamClient(iam_sample_conf.config)
3# Set current username
4 user_name = b"test_user"
5
6# Set the AK to be deleted
7 accesskey_id = b"test_access_key_id"
8 response = iam_client.delete_user_accesskey(user_name, accesskey_id)
9 print(response)
List user's AccessKeys
List all AccessKeys for the user with reference to the following codes:
1def list_user_accesskey():
2 iam_client = IamClient(iam_sample_conf.config)
3
4# Set current username
5 user_name = b"test_user"
6 response = iam_client.list_user_accesskey(user_name)
7 print(response)
