@@ -6,6 +6,8 @@ import * as exec from '@actions/exec';
66import * as os from 'os' ;
77
88const sendReportRetryCount : number = 1 ;
9+ const GetScanContextURL : string = "https://dfdinfra-afdendpoint-prod-d5fqbucbg7fue0cf.z01.azurefd.net/github/v1/auth-push/GetScanContext?context=authOnly" ;
10+ const ContainerMappingURL : string = "https://dfdinfra-afdendpoint-prod-d5fqbucbg7fue0cf.z01.azurefd.net/github/v1/container-mappings" ;
911
1012/**
1113 * Represents the tasks for container mapping that are used to fetch Docker images pushed in a job run.
@@ -184,7 +186,6 @@ export class ContainerMapping implements IMicrosoftSecurityDevOps {
184186 private async _sendReport ( data : string , bearerToken : string ) : Promise < void > {
185187 return new Promise ( async ( resolve , reject ) => {
186188 let apiTime = new Date ( ) . getMilliseconds ( ) ;
187- let url : string = "https://dfdinfra-afdendpoint-prod-d5fqbucbg7fue0cf.z01.azurefd.net/github/v1/container-mappings" ;
188189 let options = {
189190 method : 'POST' ,
190191 timeout : 2500 ,
@@ -194,9 +195,9 @@ export class ContainerMapping implements IMicrosoftSecurityDevOps {
194195 'Content-Length' : data . length
195196 }
196197 } ;
197- core . debug ( `${ options [ 'method' ] . toUpperCase ( ) } ${ url } ` ) ;
198+ core . debug ( `${ options [ 'method' ] . toUpperCase ( ) } ${ ContainerMappingURL } ` ) ;
198199
199- const req = https . request ( url , options , ( res ) => {
200+ const req = https . request ( ContainerMappingURL , options , ( res ) => {
200201 let resData = '' ;
201202 res . on ( 'data' , ( chunk ) => {
202203 resData += chunk . toString ( ) ;
@@ -236,33 +237,31 @@ export class ContainerMapping implements IMicrosoftSecurityDevOps {
236237 . then ( async ( statusCode ) => {
237238 if ( statusCode == 200 ) { // Status 'OK' means the caller is an onboarded customer.
238239 return true ;
239- } else if ( statusCode == 403 ) { // Status 'Forbidden' means caller is not a customer.
240+ } else if ( statusCode == 403 ) { // Status 'Forbidden' means caller is not a customer.
240241 return false ;
241242 } else {
242243 core . debug ( `Unexpected status code: ${ statusCode } ` ) ;
243- if ( retryCount == 0 ) {
244- return false ;
245- } else {
246- core . info ( `Retrying API call.\nRetry count: ${ retryCount } ` ) ;
247- retryCount -- ;
248- return await this . checkCallerIsCustomer ( bearerToken , retryCount ) ;
249- }
244+ return await this . retryCall ( bearerToken , retryCount ) ;
250245 }
251246 } )
252247 . catch ( async ( error ) => {
253- if ( retryCount == 0 ) {
254- return false ;
255- } else {
256- core . info ( `Retrying checkCallerIsCustomer call due to error: ${ error } .\nRetry count: ${ retryCount } ` ) ;
257- retryCount -- ;
258- return await this . checkCallerIsCustomer ( bearerToken , retryCount ) ;
259- }
248+ core . info ( `Unexpected error: ${ error } .` ) ;
249+ return await this . retryCall ( bearerToken , retryCount ) ;
260250 } ) ;
261251 }
262252
253+ private async retryCall ( bearerToken : string , retryCount : number ) : Promise < boolean > {
254+ if ( retryCount == 0 ) {
255+ return false ;
256+ } else {
257+ core . info ( `Retrying checkCallerIsCustomer.\nRetry count: ${ retryCount } ` ) ;
258+ retryCount -- ;
259+ return await this . checkCallerIsCustomer ( bearerToken , retryCount ) ;
260+ }
261+ }
262+
263263 private async _checkCallerIsCustomer ( bearerToken : string ) : Promise < number > {
264264 return new Promise ( async ( resolve , reject ) => {
265- let url : string = "https://dfdinfra-afdendpoint-prod-d5fqbucbg7fue0cf.z01.azurefd.net/github/v1/auth-push/GetScanContext?context=authOnly" ;
266265 let options = {
267266 method : 'GET' ,
268267 timeout : 2500 ,
@@ -271,9 +270,9 @@ export class ContainerMapping implements IMicrosoftSecurityDevOps {
271270 'Authorization' : 'Bearer ' + bearerToken ,
272271 }
273272 } ;
274- core . debug ( `${ options [ 'method' ] . toUpperCase ( ) } ${ url } ` ) ;
273+ core . debug ( `${ options [ 'method' ] . toUpperCase ( ) } ${ GetScanContextURL } ` ) ;
275274
276- const req = https . request ( url , options , ( res ) => {
275+ const req = https . request ( GetScanContextURL , options , ( res ) => {
277276
278277 res . on ( 'end' , ( ) => {
279278 resolve ( res . statusCode ) ;
0 commit comments