2727
2828class OauthPlugin :
2929 def __init__ (self ):
30- self .control_service_rest_api_url = None
31- self .access_token = None
32- self .team_name = None
3330 self .is_oauth_creds_available = False
3431
3532 def __attempt_oauth_authentication (
@@ -70,26 +67,6 @@ def vdk_initialize(self, context: CoreContext) -> None:
7067
7168 if oauth_configuration .disable_oauth_plugin ():
7269 return
73- # Scenario: data job running in cloud has oauth creds present
74- if (
75- oauth_configuration .team_client_id () is not None
76- and oauth_configuration .team_client_secret () is not None
77- ):
78- self .is_oauth_creds_available = True
79- return
80- # Scenario: data job running in local does not have oauth creds
81- credentials_cache = LocalFolderCredentialsCache ()
82- credentials = credentials_cache .read_credentials ()
83- try :
84- creds_json = json .loads (credentials )
85- except json .JSONDecodeError as e :
86- log .error (f"Try VDK login command and then try executing data job." )
87- raise e
88- self .access_token = creds_json .get ("access_token" )
89- self .control_service_rest_api_url = (
90- oauth_configuration .control_service_rest_api_url ()
91- )
92- self .team_name = oauth_configuration .team ()
9370
9471 @hookimpl (tryfirst = True )
9572 def initialize_job (self , context : JobContext ) -> None :
@@ -104,19 +81,32 @@ def initialize_job(self, context: JobContext) -> None:
10481 if oauth_configuration .disable_oauth_plugin ():
10582 return
10683
107- if not self .is_oauth_creds_available :
84+ # Scenario: data job running in local does not have oauth creds
85+ if (
86+ oauth_configuration .team_client_id () is None
87+ or oauth_configuration .team_client_secret () is None
88+ ):
89+ credentials_cache = LocalFolderCredentialsCache ()
90+ credentials = credentials_cache .read_credentials ()
91+ try :
92+ creds_json = json .loads (credentials )
93+ except json .JSONDecodeError as e :
94+ log .error (f"Try VDK login command and then try executing data job." )
95+ raise e
96+ access_token = creds_json .get ("access_token" )
97+ team_name = oauth_configuration .team ()
10898 # Enter a context with an instance of the API client
10999 configuration = taurus_datajob_api .Configuration (
110- host = self .control_service_rest_api_url ,
100+ host = oauth_configuration .control_service_rest_api_url () ,
111101 )
112102
113- configuration .access_token = self . access_token
103+ configuration .access_token = access_token
114104 oauth_creds = None
115105 with taurus_datajob_api .ApiClient (configuration ) as api_client :
116106 api_instance = taurus_datajob_api .DataJobsSecretsApi (api_client )
117107 try :
118108 # Retrieves details of an existing Data Job by specifying the name of the Data Job. | (Stable)
119- oauth_creds = api_instance .oauth_credentials_get (self . team_name )
109+ oauth_creds = api_instance .oauth_credentials_get (team_name )
120110 except Exception as e :
121111 log .error (f"Exception when fetching oauth credentials: { e } " )
122112 raise e
0 commit comments