Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix admin command enum typing #1436

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 47 additions & 57 deletions minio/minioadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
import json
import os
from datetime import timedelta
from enum import Enum
from enum import Enum, unique
from typing import TextIO, Tuple, cast
from urllib.parse import urlunsplit

import certifi
from typing_extensions import Protocol
from urllib3 import Retry
from urllib3._collections import HTTPHeaderDict
from urllib3.poolmanager import PoolManager
Expand All @@ -50,60 +49,51 @@
url_replace)
from .signer import sign_v4_s3

_COMMAND = Enum(
"Command",
{
"ADD_USER": "add-user",
"USER_INFO": "user-info",
"LIST_USERS": "list-users",
"REMOVE_USER": "remove-user",
"SET_USER_STATUS": "set-user-status",
"ADD_CANNED_POLICY": "add-canned-policy",
"SET_USER_OR_GROUP_POLICY": "set-user-or-group-policy",
"LIST_CANNED_POLICIES": "list-canned-policies",
"REMOVE_CANNED_POLICY": "remove-canned-policy",
"UNSET_USER_OR_GROUP_POLICY": "idp/builtin/policy/detach",
"CANNED_POLICY_INFO": "info-canned-policy",
"SET_BUCKET_QUOTA": "set-bucket-quota",
"GET_BUCKET_QUOTA": "get-bucket-quota",
"DATA_USAGE_INFO": "datausageinfo",
"ADD_UPDATE_REMOVE_GROUP": "update-group-members",
"SET_GROUP_STATUS": "set-group-status",
"GROUP_INFO": "group",
"LIST_GROUPS": "groups",
"INFO": "info",
"SERVICE": "service",
"UPDATE": "update",
"TOP_LOCKS": "top/locks",
"HELP_CONFIG": "help-config-kv",
"GET_CONFIG": "get-config-kv",
"SET_CONFIG": "set-config-kv",
"DELETE_CONFIG": "del-config-kv",
"LIST_CONFIG_HISTORY": "list-config-history-kv",
"RESOTRE_CONFIG_HISTORY": "restore-config-history-kv",
"START_PROFILE": "profile",
"CREATE_KMS_KEY": "kms/key/create",
"GET_KMS_KEY_STATUS": "kms/key/status",
"SITE_REPLICATION_ADD": "site-replication/add",
"SITE_REPLICATION_INFO": "site-replication/info",
"SITE_REPLICATION_STATUS": "site-replication/status",
"SITE_REPLICATION_EDIT": "site-replication/edit",
"SITE_REPLICATION_REMOVE": "site-replication/remove",
"SERVICE_ACCOUNT_INFO": "info-service-account",
"SERVICE_ACCOUNT_LIST": "list-service-accounts",
"SERVICE_ACCOUNT_ADD": "add-service-account",
"SERVICE_ACCOUNT_UPDATE": "update-service-account",
"SERVICE_ACCOUNT_DELETE": "delete-service-account",
},
)


class CommandType(Protocol):
"""typing stub for enum.Command class"""

@property
def value(self) -> str:
"""Get value of the command."""

@unique
class _COMMAND(Enum):
"""Admin Command enumerations."""
ADD_USER = "add-user"
USER_INFO = "user-info"
LIST_USERS = "list-users"
REMOVE_USER = "remove-user"
SET_USER_STATUS = "set-user-status"
ADD_CANNED_POLICY = "add-canned-policy"
SET_USER_OR_GROUP_POLICY = "set-user-or-group-policy"
LIST_CANNED_POLICIES = "list-canned-policies"
REMOVE_CANNED_POLICY = "remove-canned-policy"
UNSET_USER_OR_GROUP_POLICY = "idp/builtin/policy/detach"
CANNED_POLICY_INFO = "info-canned-policy"
SET_BUCKET_QUOTA = "set-bucket-quota"
GET_BUCKET_QUOTA = "get-bucket-quota"
DATA_USAGE_INFO = "datausageinfo"
ADD_UPDATE_REMOVE_GROUP = "update-group-members"
SET_GROUP_STATUS = "set-group-status"
GROUP_INFO = "group"
LIST_GROUPS = "groups"
INFO = "info"
SERVICE = "service"
UPDATE = "update"
TOP_LOCKS = "top/locks"
HELP_CONFIG = "help-config-kv"
GET_CONFIG = "get-config-kv"
SET_CONFIG = "set-config-kv"
DELETE_CONFIG = "del-config-kv"
LIST_CONFIG_HISTORY = "list-config-history-kv"
RESOTRE_CONFIG_HISTORY = "restore-config-history-kv"
START_PROFILE = "profile"
CREATE_KMS_KEY = "kms/key/create"
GET_KMS_KEY_STATUS = "kms/key/status"
SITE_REPLICATION_ADD = "site-replication/add"
SITE_REPLICATION_INFO = "site-replication/info"
SITE_REPLICATION_STATUS = "site-replication/status"
SITE_REPLICATION_EDIT = "site-replication/edit"
SITE_REPLICATION_REMOVE = "site-replication/remove"
SERVICE_ACCOUNT_INFO = "info-service-account"
SERVICE_ACCOUNT_LIST = "list-service-accounts"
SERVICE_ACCOUNT_ADD = "add-service-account"
SERVICE_ACCOUNT_UPDATE = "update-service-account"
SERVICE_ACCOUNT_DELETE = "delete-service-account"


class MinioAdmin:
Expand Down Expand Up @@ -158,7 +148,7 @@ def __del__(self):
def _url_open(
self,
method: str,
command: CommandType,
command: _COMMAND,
query_params: DictType | None = None,
body: bytes | None = None,
preload_content: bool = True,
Expand Down
Loading