角色管理接口
更新时间:2021-11-24
创建角色
创建角色,请参考如下代码:
def create_role():
iam_client = IamClient(iam_sample_conf.config)
# 创建角色的请求为dict
# 设置角色名name
# 设置角色描述description
# 指定允许扮演角色的载体assumeRolePolicyDocument
create_role_request = {"name": "test_role", "description": "create role: test_role",
"assumeRolePolicyDocument": "{\"version\":\"v1\",\"accessControlList\":[{"
"\"service\":\"bce:iam\",\"permission\":[\"AssumeRole\"],"
"\"region\":\"*\",\"grantee\":[{"
"\"id\":\"test_account_id\"}],"
"\"effect\":\"Allow\"}]}"}
response = iam_client.create_role(create_role_request)
print(response)
查询角色
查询角色,请参考如下代码:
def get_role():
iam_client = IamClient(iam_sample_conf.config)
# 设置角色名
role_name = b"test_role"
response = iam_client.get_role(role_name)
print(response)
更新角色
更新角色,请参考如下代码:
def update_role():
iam_client = IamClient(iam_sample_conf.config)
# 旧的角色名
role_name = b"test_role"
# 更新角色的请求为dict
# 设置更新的角色名 name
# 设置更新的角色描述 description
# 设置更新的允许扮演角色的载体 assumeRolePolicyDocument
update_role_request = {"name": "test_role_new", "description": "update role: test_role",
"assumeRolePolicyDocument": "{\"version\":\"v1\",\"accessControlList\":[{"
"\"service\":\"bce:iam\",\"permission\":[\"AssumeRole\"],"
"\"region\":\"*\",\"grantee\":[{"
"\"id\":\"test_account_id\"}],"
"\"effect\":\"Allow\"}]}"}
response = iam_client.update_role(role_name, update_role_request)
print(response)
删除角色
删除角色,请参考如下代码:
def delete_role():
iam_client = IamClient(iam_sample_conf.config)
# 需要删除的角色名
role_name = b"test_role"
response = iam_client.delete_role(role_name=role_name)
print(response)
列举角色
列举角色,请参考如下代码:
def list_role():
iam_client = IamClient(iam_sample_conf.config)
response = iam_client.list_role()
print(response)