27
27
28
28
class OauthPlugin :
29
29
def __init__ (self ):
30
- self .control_service_rest_api_url = None
31
- self .access_token = None
32
- self .team_name = None
33
30
self .is_oauth_creds_available = False
34
31
35
32
def __attempt_oauth_authentication (
@@ -70,26 +67,6 @@ def vdk_initialize(self, context: CoreContext) -> None:
70
67
71
68
if oauth_configuration .disable_oauth_plugin ():
72
69
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 ()
93
70
94
71
@hookimpl (tryfirst = True )
95
72
def initialize_job (self , context : JobContext ) -> None :
@@ -104,19 +81,32 @@ def initialize_job(self, context: JobContext) -> None:
104
81
if oauth_configuration .disable_oauth_plugin ():
105
82
return
106
83
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 ()
108
98
# Enter a context with an instance of the API client
109
99
configuration = taurus_datajob_api .Configuration (
110
- host = self .control_service_rest_api_url ,
100
+ host = oauth_configuration .control_service_rest_api_url () ,
111
101
)
112
102
113
- configuration .access_token = self . access_token
103
+ configuration .access_token = access_token
114
104
oauth_creds = None
115
105
with taurus_datajob_api .ApiClient (configuration ) as api_client :
116
106
api_instance = taurus_datajob_api .DataJobsSecretsApi (api_client )
117
107
try :
118
108
# 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 )
120
110
except Exception as e :
121
111
log .error (f"Exception when fetching oauth credentials: { e } " )
122
112
raise e
0 commit comments