@@ -62,7 +62,6 @@ class _COMMAND(Enum):
6262 SET_USER_OR_GROUP_POLICY = "set-user-or-group-policy"
6363 LIST_CANNED_POLICIES = "list-canned-policies"
6464 REMOVE_CANNED_POLICY = "remove-canned-policy"
65- UNSET_USER_OR_GROUP_POLICY = "idp/builtin/policy/detach"
6665 CANNED_POLICY_INFO = "info-canned-policy"
6766 SET_BUCKET_QUOTA = "set-bucket-quota"
6867 GET_BUCKET_QUOTA = "get-bucket-quota"
@@ -98,6 +97,9 @@ class _COMMAND(Enum):
9897 IDP_LDAP_POLICY_DETACH = "idp/ldap/policy/detach"
9998 IDP_LDAP_LIST_ACCESS_KEYS = "idp/ldap/list-access-keys"
10099 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"
101103
102104
103105def _safe_str (value : Any ) -> str :
@@ -476,7 +478,7 @@ def policy_list(self) -> str:
476478
477479 def policy_set (
478480 self ,
479- policy_name : str | list [ str ] ,
481+ policy_name : str ,
480482 user : str | None = None ,
481483 group : str | None = None ,
482484 ) -> str :
@@ -499,29 +501,9 @@ def policy_unset(
499501 group : str | None = None ,
500502 ) -> str :
501503 """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 )
525507
526508 def config_get (self , key : str | None = None ) -> str :
527509 """Get configuration parameters."""
@@ -847,14 +829,14 @@ def delete_service_account(self, access_key: str) -> str:
847829 )
848830 return response .data .decode ()
849831
850- def _attach_detach_policy_ldap (
832+ def _attach_detach_policy (
851833 self ,
852834 command : _COMMAND ,
853835 policies : list [str ],
854836 user : str | None = None ,
855837 group : str | None = None ,
856838 ) -> str :
857- """Attach or detach policies for LDAP."""
839+ """Attach or detach policies for builtin or LDAP."""
858840 if (user is not None ) ^ (group is not None ):
859841 key = "user" if user else "group"
860842 body = json .dumps (
@@ -876,7 +858,7 @@ def attach_policy_ldap(
876858 group : str | None = None ,
877859 ) -> str :
878860 """Attach policies for LDAP."""
879- return self ._attach_detach_policy_ldap (
861+ return self ._attach_detach_policy (
880862 _COMMAND .IDP_LDAP_POLICY_ATTACH , policies , user , group ,
881863 )
882864
@@ -887,7 +869,7 @@ def detach_policy_ldap(
887869 group : str | None = None ,
888870 ) -> str :
889871 """Detach policies for LDAP."""
890- return self ._attach_detach_policy_ldap (
872+ return self ._attach_detach_policy (
891873 _COMMAND .IDP_LDAP_POLICY_DETACH , policies , user , group ,
892874 )
893875
@@ -927,3 +909,42 @@ def list_access_keys_ldap_bulk(
927909 response , self ._provider .retrieve ().secret_key ,
928910 )
929911 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