From af17fbc1c66f3965b4cda058bdeca842df8303f5 Mon Sep 17 00:00:00 2001 From: pbrw Date: Mon, 21 Aug 2023 18:29:20 +0200 Subject: [PATCH] User: Add, Info, Remove, List --- minio/minioadmin.py | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/minio/minioadmin.py b/minio/minioadmin.py index dd3ee70ae..b6bfcc344 100644 --- a/minio/minioadmin.py +++ b/minio/minioadmin.py @@ -21,12 +21,15 @@ from __future__ import absolute_import from datetime import timedelta +import json from urllib.parse import urlunsplit import os import certifi import urllib3 +from minio.crypto import decrypt, encrypt + from . import time from .credentials.providers import StaticProvider @@ -185,10 +188,15 @@ def _execute( # """Get MinIO server information.""" # return self._run(["info", self._target]) - # def user_add(self, access_key, secret_key): - # """Add a new user.""" - # return self._run(["user", "add", self._target, - # access_key, secret_key]) + def user_add(self, access_key, secret_key): + """Create user with access and secret keys""" + params = {"accessKey": access_key} + body = {"status": "enabled", "secretKey": secret_key} + plain_body = json.dumps(body).encode() + cipher_body = encrypt(plain_body, self._credentials.secret_key) + response = self._url_open("PUT", "/add-user", + query_params=params, body=cipher_body) + return response.data.decode() # def user_disable(self, access_key): # """Disable user.""" @@ -198,17 +206,23 @@ def _execute( # """Enable user.""" # return self._run(["user", "enable", self._target, access_key]) - # def user_remove(self, access_key): - # """Remove user.""" - # return self._run(["user", "remove", self._target, access_key]) - - # def user_info(self, access_key): - # """Get user information.""" - # return self._run(["user", "info", self._target, access_key]) - - # def user_list(self): - # """List users.""" - # return self._run(["user", "list", self._target], multiline=True) + def user_remove(self, access_key): + """Delete user""" + params = {"accessKey": access_key} + response = self._url_open("DELETE", "/remove-user", query_params=params) + return response.data.decode() + + def user_info(self, access_key): + """Get information about user""" + params = {"accessKey": access_key} + response = self._url_open("GET", "/user-info", query_params=params) + return response.data.decode() + + def user_list(self): + """List all users""" + response = self._url_open("GET", "/list-users") + plain_data = decrypt(response.data, self._credentials.secret_key) + return plain_data.decode() # def group_add(self, group_name, members): # """Add users a new or existing group."""