24
24
import os
25
25
from datetime import timedelta
26
26
from enum import Enum
27
- from typing import TextIO
27
+ from typing import TextIO , Tuple , cast
28
28
from urllib .parse import urlunsplit
29
29
30
30
import certifi
40
40
from .crypto import decrypt , encrypt
41
41
from .datatypes import PeerInfo , PeerSite , SiteReplicationStatusOptions
42
42
from .error import MinioAdminException
43
- from .helpers import (_DEFAULT_USER_AGENT , _REGION_REGEX , _parse_url ,
43
+ from .helpers import (_DEFAULT_USER_AGENT , _REGION_REGEX , DictType , _parse_url ,
44
44
headers_to_strings , queryencode , sha256_hash ,
45
45
url_replace )
46
46
from .signer import sign_v4_s3
@@ -149,8 +149,7 @@ def _url_open(
149
149
self ,
150
150
method : str ,
151
151
command : CommandType ,
152
- query_params :
153
- dict [str , str | list [str ] | tuple [str ]] | None = None ,
152
+ query_params : DictType | None = None ,
154
153
body : bytes | None = None ,
155
154
preload_content : bool = True ,
156
155
) -> BaseHTTPResponse :
@@ -169,7 +168,7 @@ def _url_open(
169
168
170
169
content_sha256 = sha256_hash (body )
171
170
date = time .utcnow ()
172
- headers : dict [ str , str | list [ str ] | tuple [ str ]] = {
171
+ headers : DictType = {
173
172
"Host" : url .netloc ,
174
173
"User-Agent" : self ._user_agent ,
175
174
"x-amz-date" : time .to_amz_date (date ),
@@ -239,7 +238,7 @@ def _url_open(
239
238
if response .status in [200 , 204 , 206 ]:
240
239
return response
241
240
242
- raise MinioAdminException (response .status , response .data .decode ())
241
+ raise MinioAdminException (str ( response .status ) , response .data .decode ())
243
242
244
243
def set_app_info (self , app_name : str , app_version : str ):
245
244
"""
@@ -472,7 +471,7 @@ def policy_set(
472
471
response = self ._url_open (
473
472
"PUT" ,
474
473
_COMMAND .SET_USER_OR_GROUP_POLICY ,
475
- query_params = {"userOrGroup" : user or group ,
474
+ query_params = {"userOrGroup" : cast ( str , user or group ) ,
476
475
"isGroup" : "true" if group else "false" ,
477
476
"policyName" : policy_name },
478
477
)
@@ -585,7 +584,10 @@ def config_restore(self, restore_id: str) -> str:
585
584
)
586
585
return response .data .decode ()
587
586
588
- def profile_start (self , profilers : tuple [str ] = ()) -> str :
587
+ def profile_start (
588
+ self ,
589
+ profilers : tuple [str ] = cast (Tuple [str ], ()),
590
+ ) -> str :
589
591
"""Runs a system profile"""
590
592
response = self ._url_open (
591
593
"POST" ,
@@ -607,7 +609,7 @@ def kms_key_create(self, key: str | None = None) -> str:
607
609
response = self ._url_open (
608
610
"POST" ,
609
611
_COMMAND .CREATE_KMS_KEY ,
610
- query_params = {"key-id" : key },
612
+ query_params = {"key-id" : key or "" },
611
613
)
612
614
return response .data .decode ()
613
615
@@ -645,7 +647,7 @@ def get_site_replication_status(
645
647
response = self ._url_open (
646
648
"GET" ,
647
649
_COMMAND .SITE_REPLICATION_STATUS ,
648
- query_params = options .to_query_params (),
650
+ query_params = cast ( DictType , options .to_query_params () ),
649
651
)
650
652
return response .data .decode ()
651
653
@@ -668,9 +670,9 @@ def remove_site_replication(
668
670
"""Remove given sites or all sites from site replication."""
669
671
data = {}
670
672
if all_sites :
671
- data .update ({"all" : True })
673
+ data .update ({"all" : " True" })
672
674
elif sites :
673
- data .update ({"sites" : sites })
675
+ data .update ({"sites" : sites or "" })
674
676
else :
675
677
raise ValueError ("either sites or all flag must be given" )
676
678
body = json .dumps (data ).encode ()
0 commit comments