@@ -37,7 +37,9 @@ class IAM(object):
3737 input: object
3838 """
3939
40- def __init__ (self , app_code , app_secret , bk_iam_host = None , bk_paas_host = None , bk_apigateway_url = None ):
40+ def __init__ (
41+ self , app_code , app_secret , bk_iam_host = None , bk_paas_host = None , bk_apigateway_url = None , api_version = "v2"
42+ ):
4143 """
4244 如果有 APIGateway 且权限中心网关接入, 则可以统一API请求全部走APIGateway
4345 - 没有APIGateway的用法: IAM(app_code, app_secret, bk_iam_host, bk_paas_host)
@@ -48,6 +50,8 @@ def __init__(self, app_code, app_secret, bk_iam_host=None, bk_paas_host=None, bk
4850 """
4951 self ._client = Client (app_code , app_secret , bk_iam_host , bk_paas_host , bk_apigateway_url )
5052
53+ self ._api_version = api_version
54+
5155 def _do_policy_query (self , request , with_resources = True ):
5256 data = request .to_dict ()
5357 logger .debug ("the request: %s" , data )
@@ -57,7 +61,10 @@ def _do_policy_query(self, request, with_resources=True):
5761 if not with_resources :
5862 data ["resources" ] = []
5963
60- ok , message , policies = self ._client .policy_query (data )
64+ if self ._api_version == "v2" :
65+ ok , message , policies = self ._client .v2_policy_query (request .system , data )
66+ else :
67+ ok , message , policies = self ._client .policy_query (data )
6168 if not ok :
6269 raise AuthAPIError (message )
6370 return policies
@@ -75,7 +82,10 @@ def _do_policy_query_by_actions(self, request, with_resources=True):
7582 if not with_resources :
7683 data ["resources" ] = []
7784
78- ok , message , action_policies = self ._client .policy_query_by_actions (data )
85+ if self ._api_version == "v2" :
86+ ok , message , action_policies = self ._client .v2_policy_query_by_actions (request .system , data )
87+ else :
88+ ok , message , action_policies = self ._client .policy_query_by_actions (data )
7989 if not ok :
8090 raise AuthAPIError (message )
8191 return action_policies
@@ -401,7 +411,7 @@ def make_filter(self, request, converter_class=DjangoQuerySetConverter, key_mapp
401411
402412 # TODO: add the register model apis
403413 def get_token (self , system ):
404- """ 获取token
414+ """获取token
405415 return bool, message, token
406416 """
407417 return self ._client .get_token (system )
0 commit comments