@@ -45,14 +45,18 @@ export default class httpClient {
45
45
46
46
this . axiosInstance = axios . create ( axiosConfig ) ;
47
47
48
-
49
48
this . axiosInstance . interceptors . request . use ( ( config ) => {
50
- if ( ! config . headers [ 'projectToken' ] ) {
49
+ if ( ! config . headers [ 'projectToken' ] && this . projectToken !== '' ) {
51
50
config . headers [ 'projectToken' ] = this . projectToken ;
51
+ } else if ( ( ! config . headers [ 'projectName' ] && this . projectName !== '' ) ) {
52
+ config . headers [ 'projectName' ] = this . projectName ;
53
+ if ( ! config . headers [ 'username' ] || config . headers [ 'username' ] === '' ) {
54
+ config . headers [ 'username' ] = this . username ;
55
+ }
56
+ if ( ! config . headers [ 'accessKey' ] || config . headers [ 'accessKey' ] === '' ) {
57
+ config . headers [ 'accessKey' ] = this . accessKey ;
58
+ }
52
59
}
53
- config . headers [ 'projectName' ] = this . projectName ;
54
- config . headers [ 'username' ] = this . username ;
55
- config . headers [ 'accessKey' ] = this . accessKey ;
56
60
return config ;
57
61
} ) ;
58
62
@@ -151,6 +155,53 @@ export default class httpClient {
151
155
}
152
156
}
153
157
158
+ async authExec ( ctx : Context , log : Logger , env : Env ) : Promise < { authResult : number , orgId : number , userId : number } > {
159
+ let authResult = 1 ;
160
+ let userName = '' ;
161
+ let passWord = '' ;
162
+ if ( ctx . config . tunnel ) {
163
+ if ( ctx . config . tunnel ?. user && ctx . config . tunnel ?. key ) {
164
+ userName = ctx . config . tunnel . user
165
+ passWord = ctx . config . tunnel . key
166
+ } else {
167
+ userName = this . username
168
+ passWord = this . accessKey
169
+ }
170
+ }
171
+ if ( this . projectToken ) {
172
+ authResult = 0 ;
173
+ }
174
+ const response = await this . request ( {
175
+ url : '/token/verify' ,
176
+ method : 'GET' ,
177
+ headers : {
178
+ username : userName ,
179
+ accessKey : passWord
180
+ }
181
+ } , log ) ;
182
+ if ( response && response . projectToken ) {
183
+ let orgId = 0 ;
184
+ let userId = 0 ;
185
+ this . projectToken = response . projectToken ;
186
+ env . PROJECT_TOKEN = response . projectToken ;
187
+ if ( response . message && response . message . includes ( 'Project created successfully' ) ) {
188
+ authResult = 2 ;
189
+ }
190
+ if ( response . orgId ) {
191
+ orgId = response . orgId
192
+ }
193
+ if ( response . userId ) {
194
+ userId = response . userId
195
+ }
196
+ return { authResult, orgId, userId } ;
197
+ } else {
198
+ if ( response && response . message ) {
199
+ throw new Error ( response . message ) ;
200
+ }
201
+ throw new Error ( 'Authentication failed, project token not received. Refer to the smartui.log file for more information' ) ;
202
+ }
203
+ }
204
+
154
205
createBuild ( git : Git , config : any , log : Logger , buildName : string , isStartExec : boolean ) {
155
206
return this . request ( {
156
207
url : '/build' ,
@@ -174,16 +225,24 @@ export default class httpClient {
174
225
} , log ) ;
175
226
}
176
227
177
- getTunnelDetails ( tunnelName : string , log : Logger ) {
228
+ getTunnelDetails ( ctx : Context , log : Logger ) {
229
+ const data : any = {
230
+ orgId : ctx . orgId ,
231
+ userId : ctx . userId ,
232
+ userName : ctx . config . tunnel ?. user ,
233
+ password : ctx . config . tunnel ?. key
234
+ } ;
235
+
236
+ if ( ctx . config . tunnel ?. tunnelName ) {
237
+ data . tunnelName = ctx . config . tunnel . tunnelName ;
238
+ }
239
+
178
240
return this . request ( {
179
241
url : '/tunnel' ,
180
242
method : 'POST' ,
181
- data : {
182
- tunnelName : tunnelName
183
- }
184
- } , log )
243
+ data : data
244
+ } , log ) ;
185
245
}
186
-
187
246
188
247
ping ( buildId : string , log : Logger ) {
189
248
return this . request ( {
0 commit comments