组管理接口
更新时间:2021-11-24
创建组
创建组,请参考如下代码:
Python
1def create_group():
2
3 iam_client = IamClient(iam_sample_conf.config)
4
5 # 创建用户组的请求为dict
6 # 设置用户组名name
7 # 设置用户组描述description
8 create_group_request = {"name": "test_group", "description": "create test_group"}
9 response = iam_client.create_group(create_group_request)
10
11 print(response)
查询组
查询组,请参考如下代码:
Python
1def get_group():
2
3 iam_client = IamClient(iam_sample_conf.config)
4
5 # 用户组名
6 group_name = b"test_group"
7 response = iam_client.get_group(group_name)
8
9 print(response)
更新组
更新组,请参考如下代码:
Python
1def update_group():
2
3 iam_client = IamClient(iam_sample_conf.config)
4
5 # 目前的用户组名
6 group_name = b"test_group"
7
8 # 更新用户组的请求为dict
9 # 设置新的用户组名name
10 # 设置用户组描述description
11 update_group_request = {"name": "test_group_new", "description": "update test_group"}
12 response = iam_client.update_group(group_name, update_group_request)
13
14 print(response)
删除组
删除组,请参考如下代码:
Python
1def delete_group():
2
3 iam_client = IamClient(iam_sample_conf.config)
4
5 # 目前的用户组名
6 group_name = b"test_group"
7 response = iam_client.delete_group(group_name)
8
9 print(response)
列举组
列举组,请参考如下代码:
Python
1def list_group():
2
3 iam_client = IamClient(iam_sample_conf.config)
4
5 response = iam_client.list_group()
6
7 print(response)
添加用户到组
添加用户到组,请参考如下代码:
Python
1def add_user_to_group():
2
3 iam_client = IamClient(iam_sample_conf.config)
4
5 # 用户组名
6 group_name = b"test_group"
7 # 需要加入用户组中的用户
8 user_name = b"test_user"
9 response = iam_client.add_user_to_group(group_name, user_name)
10
11 print(response)
从组内移除用户
从组内移除用户,请参考如下代码:
Python
1def remove_user_from_group():
2
3 iam_client = IamClient(iam_sample_conf.config)
4
5 # 用户组名
6 group_name = b"test_group"
7
8 # 需要从用户组中删除的用户
9 user_name = b"test_user"
10 response = iam_client.remove_user_from_group(group_name, user_name)
11
12 print(response)
列举用户的组
列举用户所在的组,请参考如下代码:
Python
1def list_user_group():
2
3 iam_client = IamClient(iam_sample_conf.config)
4
5 # 用户名
6 user_name = b"test_user"
7 response = iam_client.list_user_group(user_name)
8
9 print(response)
列举组内用户
列举组内用户,请参考如下代码:
Python
1def list_group_user():
2
3 iam_client = IamClient(iam_sample_conf.config)
4
5 group_name = b"test_group"
6 response = iam_client.list_group_user(group_name)
7
8 print(response)