@@ -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,47 @@ 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 ?. user ) {
162+ userName = ctx . config . tunnel . user
163+ }
164+ if ( ctx . config . tunnel ?. key ) {
165+ passWord = ctx . config . tunnel . key
166+ }
167+ if ( this . projectToken ) {
168+ authResult = 0 ;
169+ }
170+ const response = await this . request ( {
171+ url : '/token/verify' ,
172+ method : 'GET' ,
173+ headers : {
174+ username : userName ,
175+ accessKey : passWord
176+ }
177+ } , log ) ;
178+ if ( response && response . projectToken ) {
179+ let orgId = 0 ;
180+ let userId = 0 ;
181+ this . projectToken = response . projectToken ;
182+ env . PROJECT_TOKEN = response . projectToken ;
183+ if ( response . message && response . message . includes ( 'Project created successfully' ) ) {
184+ authResult = 2 ;
185+ }
186+ if ( response . orgId ) {
187+ orgId = response . orgId
188+ }
189+ if ( response . userId ) {
190+ userId = response . userId
191+ }
192+ return { authResult, orgId, userId } ;
193+ } else {
194+ throw new Error ( 'Authentication failed, project token not received' ) ;
195+ }
196+ }
197+
154198 createBuild ( git : Git , config : any , log : Logger , buildName : string , isStartExec : boolean ) {
155199 return this . request ( {
156200 url : '/build' ,
@@ -174,12 +218,16 @@ export default class httpClient {
174218 } , log ) ;
175219 }
176220
177- getTunnelDetails ( tunnelName : string , log : Logger ) {
221+ getTunnelDetails ( ctx : Context , log : Logger ) {
178222 return this . request ( {
179223 url : '/tunnel' ,
180224 method : 'POST' ,
181225 data : {
182- tunnelName : tunnelName
226+ tunnelName : ctx . config . tunnel ?. tunnelName ,
227+ orgId : ctx . orgId ,
228+ userId : ctx . userId ,
229+ userName : ctx . config . tunnel ?. user ,
230+ password : ctx . config . tunnel ?. key
183231 }
184232 } , log )
185233 }
0 commit comments