Skip to content

Commit 2af0b46

Browse files
authored
MinioAdmin: add IDP/LDAP attach/detach/list APIs (#1470)
Signed-off-by: Bala.FA <bala@minio.io>
1 parent 5bc4dd0 commit 2af0b46

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

minio/minioadmin.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ class _COMMAND(Enum):
9494
SERVICE_ACCOUNT_ADD = "add-service-account"
9595
SERVICE_ACCOUNT_UPDATE = "update-service-account"
9696
SERVICE_ACCOUNT_DELETE = "delete-service-account"
97+
IDP_LDAP_POLICY_ATTACH = "idp/ldap/policy/attach"
98+
IDP_LDAP_POLICY_DETACH = "idp/ldap/policy/detach"
99+
IDP_LDAP_LIST_ACCESS_KEYS = "idp/ldap/list-access-keys"
100+
IDP_LDAP_LIST_ACCESS_KEYS_BULK = "idp/ldap/list-access-keys-bulk"
97101

98102

99103
def _safe_str(value: Any) -> str:
@@ -842,3 +846,84 @@ def delete_service_account(self, access_key: str) -> str:
842846
query_params={"accessKey": access_key},
843847
)
844848
return response.data.decode()
849+
850+
def _attach_detach_policy_ldap(
851+
self,
852+
command: _COMMAND,
853+
policies: list[str],
854+
user: str | None = None,
855+
group: str | None = None,
856+
) -> str:
857+
"""Attach or detach policies for LDAP."""
858+
if (user is not None) ^ (group is not None):
859+
key = "user" if user else "group"
860+
body = json.dumps(
861+
{"policies": policies,
862+
key: cast(str, user or group)},
863+
).encode()
864+
response = self._url_open(
865+
"POST",
866+
command,
867+
body=encrypt(body, self._provider.retrieve().secret_key),
868+
)
869+
return response.data.decode()
870+
raise ValueError("either user or group must be set")
871+
872+
def attach_policy_ldap(
873+
self,
874+
policies: list[str],
875+
user: str | None = None,
876+
group: str | None = None,
877+
) -> str:
878+
"""Attach policies for LDAP."""
879+
return self._attach_detach_policy_ldap(
880+
_COMMAND.IDP_LDAP_POLICY_ATTACH, policies, user, group,
881+
)
882+
883+
def detach_policy_ldap(
884+
self,
885+
policies: list[str],
886+
user: str | None = None,
887+
group: str | None = None,
888+
) -> str:
889+
"""Detach policies for LDAP."""
890+
return self._attach_detach_policy_ldap(
891+
_COMMAND.IDP_LDAP_POLICY_DETACH, policies, user, group,
892+
)
893+
894+
def list_access_keys_ldap(
895+
self,
896+
user_dn: str,
897+
list_type: str,
898+
) -> str:
899+
"""List service accounts belonging to the specified user."""
900+
response = self._url_open(
901+
"GET", _COMMAND.IDP_LDAP_LIST_ACCESS_KEYS,
902+
query_params={"userDN": user_dn, "listType": list_type},
903+
preload_content=False,
904+
)
905+
plain_data = decrypt(
906+
response, self._provider.retrieve().secret_key,
907+
)
908+
return plain_data.decode()
909+
910+
def list_access_keys_ldap_bulk(
911+
self,
912+
users: list[str],
913+
list_type: str,
914+
all_users: bool,
915+
) -> str:
916+
"""List access keys belonging to the given users or all users."""
917+
if len(users) != 0 and all_users:
918+
raise ValueError("both users and all_users are not permitted")
919+
920+
key, value = ("all", "true") if all_users else ("userDNs", users)
921+
response = self._url_open(
922+
"GET", _COMMAND.IDP_LDAP_LIST_ACCESS_KEYS_BULK,
923+
query_params={"listType": list_type, key: value},
924+
preload_content=False,
925+
)
926+
plain_data = decrypt(
927+
response, self._provider.retrieve().secret_key,
928+
)
929+
return plain_data.decode()

0 commit comments

Comments
 (0)