@@ -62,7 +62,6 @@ class _COMMAND(Enum):
62
62
SET_USER_OR_GROUP_POLICY = "set-user-or-group-policy"
63
63
LIST_CANNED_POLICIES = "list-canned-policies"
64
64
REMOVE_CANNED_POLICY = "remove-canned-policy"
65
- UNSET_USER_OR_GROUP_POLICY = "idp/builtin/policy/detach"
66
65
CANNED_POLICY_INFO = "info-canned-policy"
67
66
SET_BUCKET_QUOTA = "set-bucket-quota"
68
67
GET_BUCKET_QUOTA = "get-bucket-quota"
@@ -98,6 +97,9 @@ class _COMMAND(Enum):
98
97
IDP_LDAP_POLICY_DETACH = "idp/ldap/policy/detach"
99
98
IDP_LDAP_LIST_ACCESS_KEYS = "idp/ldap/list-access-keys"
100
99
IDP_LDAP_LIST_ACCESS_KEYS_BULK = "idp/ldap/list-access-keys-bulk"
100
+ IDP_BUILTIN_POLICY_ATTACH = "idp/builtin/policy/attach"
101
+ IDP_BUILTIN_POLICY_DETACH = "idp/builtin/policy/detach"
102
+ IDP_BUILTIN_POLICY_ENTITIES = "idp/builtin/policy-entities"
101
103
102
104
103
105
def _safe_str (value : Any ) -> str :
@@ -476,7 +478,7 @@ def policy_list(self) -> str:
476
478
477
479
def policy_set (
478
480
self ,
479
- policy_name : str | list [ str ] ,
481
+ policy_name : str ,
480
482
user : str | None = None ,
481
483
group : str | None = None ,
482
484
) -> str :
@@ -499,29 +501,9 @@ def policy_unset(
499
501
group : str | None = None ,
500
502
) -> str :
501
503
"""Unset an IAM policy for a user or group."""
502
- if (user is not None ) ^ (group is not None ):
503
- policies = (
504
- policy_name if isinstance (policy_name , list ) else [policy_name ]
505
- )
506
- data : dict [str , str | list [str ]] = {"policies" : policies }
507
- if user :
508
- data ["user" ] = user
509
- if group :
510
- data ["group" ] = group
511
- response = self ._url_open (
512
- "POST" ,
513
- _COMMAND .UNSET_USER_OR_GROUP_POLICY ,
514
- body = encrypt (
515
- json .dumps (data ).encode (),
516
- self ._provider .retrieve ().secret_key ,
517
- ),
518
- preload_content = False ,
519
- )
520
- plain_data = decrypt (
521
- response , self ._provider .retrieve ().secret_key ,
522
- )
523
- return plain_data .decode ()
524
- raise ValueError ("either user or group must be set" )
504
+ return self .detach_policy (
505
+ policy_name if isinstance (policy_name , list ) else [policy_name ],
506
+ user , group )
525
507
526
508
def config_get (self , key : str | None = None ) -> str :
527
509
"""Get configuration parameters."""
@@ -847,14 +829,14 @@ def delete_service_account(self, access_key: str) -> str:
847
829
)
848
830
return response .data .decode ()
849
831
850
- def _attach_detach_policy_ldap (
832
+ def _attach_detach_policy (
851
833
self ,
852
834
command : _COMMAND ,
853
835
policies : list [str ],
854
836
user : str | None = None ,
855
837
group : str | None = None ,
856
838
) -> str :
857
- """Attach or detach policies for LDAP."""
839
+ """Attach or detach policies for builtin or LDAP."""
858
840
if (user is not None ) ^ (group is not None ):
859
841
key = "user" if user else "group"
860
842
body = json .dumps (
@@ -876,7 +858,7 @@ def attach_policy_ldap(
876
858
group : str | None = None ,
877
859
) -> str :
878
860
"""Attach policies for LDAP."""
879
- return self ._attach_detach_policy_ldap (
861
+ return self ._attach_detach_policy (
880
862
_COMMAND .IDP_LDAP_POLICY_ATTACH , policies , user , group ,
881
863
)
882
864
@@ -887,7 +869,7 @@ def detach_policy_ldap(
887
869
group : str | None = None ,
888
870
) -> str :
889
871
"""Detach policies for LDAP."""
890
- return self ._attach_detach_policy_ldap (
872
+ return self ._attach_detach_policy (
891
873
_COMMAND .IDP_LDAP_POLICY_DETACH , policies , user , group ,
892
874
)
893
875
@@ -927,3 +909,42 @@ def list_access_keys_ldap_bulk(
927
909
response , self ._provider .retrieve ().secret_key ,
928
910
)
929
911
return plain_data .decode ()
912
+
913
+ def attach_policy (
914
+ self ,
915
+ policies : list [str ],
916
+ user : str | None = None ,
917
+ group : str | None = None ,
918
+ ) -> str :
919
+ """Attach builtin policies."""
920
+ return self ._attach_detach_policy (
921
+ _COMMAND .IDP_BUILTIN_POLICY_ATTACH , policies , user , group ,
922
+ )
923
+
924
+ def detach_policy (
925
+ self ,
926
+ policies : list [str ],
927
+ user : str | None = None ,
928
+ group : str | None = None ,
929
+ ) -> str :
930
+ """Detach builtin policies."""
931
+ return self ._attach_detach_policy (
932
+ _COMMAND .IDP_BUILTIN_POLICY_DETACH , policies , user , group ,
933
+ )
934
+
935
+ def get_policy_entities (
936
+ self ,
937
+ users : list [str ],
938
+ groups : list [str ],
939
+ policies : list [str ],
940
+ ) -> str :
941
+ """Get builtin policy entities."""
942
+ response = self ._url_open (
943
+ "GET" , _COMMAND .IDP_BUILTIN_POLICY_ENTITIES ,
944
+ query_params = {"user" : users , "group" : groups , "policy" : policies },
945
+ preload_content = False ,
946
+ )
947
+ plain_data = decrypt (
948
+ response , self ._provider .retrieve ().secret_key ,
949
+ )
950
+ return plain_data .decode ()
0 commit comments