@@ -45,14 +45,17 @@ export default class httpClient {
4545
4646 this . axiosInstance = axios . create ( axiosConfig ) ;
4747
48-
4948 this . axiosInstance . interceptors . request . use ( ( config ) => {
5049 if ( ! config . headers [ 'projectToken' ] ) {
5150 config . headers [ 'projectToken' ] = this . projectToken ;
5251 }
5352 config . headers [ 'projectName' ] = this . projectName ;
54- config . headers [ 'username' ] = this . username ;
55- config . headers [ 'accessKey' ] = this . accessKey ;
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+ }
5659 return config ;
5760 } ) ;
5861
@@ -151,6 +154,45 @@ export default class httpClient {
151154 }
152155 }
153156
157+ async authExec ( ctx : Context , log : Logger , env : Env ) : Promise < { authResult : number , orgId : number , userId : number } > {
158+ let authResult = 1 ;
159+ let userName = '' ;
160+ let passWord = '' ;
161+ if ( ctx . config . tunnel && ctx . config . tunnel ?. user && ctx . config . tunnel ?. key ) {
162+ userName = ctx . config . tunnel . user
163+ passWord = ctx . config . tunnel . key
164+ }
165+ if ( this . projectToken ) {
166+ authResult = 0 ;
167+ }
168+ const response = await this . request ( {
169+ url : '/token/verify' ,
170+ method : 'GET' ,
171+ headers : {
172+ username : userName ,
173+ accessKey : passWord
174+ }
175+ } , log ) ;
176+ if ( response && response . projectToken ) {
177+ let orgId = 0 ;
178+ let userId = 0 ;
179+ this . projectToken = response . projectToken ;
180+ env . PROJECT_TOKEN = response . projectToken ;
181+ if ( response . message && response . message . includes ( 'Project created successfully' ) ) {
182+ authResult = 2 ;
183+ }
184+ if ( response . orgId ) {
185+ orgId = response . orgId
186+ }
187+ if ( response . userId ) {
188+ userId = response . userId
189+ }
190+ return { authResult, orgId, userId } ;
191+ } else {
192+ throw new Error ( 'Authentication failed, project token not received. Refer to the smartui.log file for more information' ) ;
193+ }
194+ }
195+
154196 createBuild ( git : Git , config : any , log : Logger , buildName : string , isStartExec : boolean ) {
155197 return this . request ( {
156198 url : '/build' ,
@@ -174,16 +216,24 @@ export default class httpClient {
174216 } , log ) ;
175217 }
176218
177- getTunnelDetails ( tunnelName : string , log : Logger ) {
219+ getTunnelDetails ( ctx : Context , log : Logger ) {
220+ const data : any = {
221+ orgId : ctx . orgId ,
222+ userId : ctx . userId ,
223+ userName : ctx . config . tunnel ?. user ,
224+ password : ctx . config . tunnel ?. key
225+ } ;
226+
227+ if ( ctx . config . tunnel ?. tunnelName ) {
228+ data . tunnelName = ctx . config . tunnel . tunnelName ;
229+ }
230+
178231 return this . request ( {
179232 url : '/tunnel' ,
180233 method : 'POST' ,
181- data : {
182- tunnelName : tunnelName
183- }
184- } , log )
234+ data : data
235+ } , log ) ;
185236 }
186-
187237
188238 ping ( buildId : string , log : Logger ) {
189239 return this . request ( {
0 commit comments