@@ -45,14 +45,18 @@ export default class httpClient {
4545
4646 this . axiosInstance = axios . create ( axiosConfig ) ;
4747
48-
4948 this . axiosInstance . interceptors . request . use ( ( config ) => {
50- if ( ! config . headers [ 'projectToken' ] ) {
49+ if ( ! config . headers [ 'projectToken' ] && this . projectToken !== '' ) {
5150 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+ }
5259 }
53- config . headers [ 'projectName' ] = this . projectName ;
54- config . headers [ 'username' ] = this . username ;
55- config . headers [ 'accessKey' ] = this . accessKey ;
5660 return config ;
5761 } ) ;
5862
@@ -151,6 +155,53 @@ export default class httpClient {
151155 }
152156 }
153157
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+
154205 createBuild ( git : Git , config : any , log : Logger , buildName : string , isStartExec : boolean ) {
155206 return this . request ( {
156207 url : '/build' ,
@@ -174,16 +225,24 @@ export default class httpClient {
174225 } , log ) ;
175226 }
176227
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+
178240 return this . request ( {
179241 url : '/tunnel' ,
180242 method : 'POST' ,
181- data : {
182- tunnelName : tunnelName
183- }
184- } , log )
243+ data : data
244+ } , log ) ;
185245 }
186-
187246
188247 ping ( buildId : string , log : Logger ) {
189248 return this . request ( {
0 commit comments