@@ -4,7 +4,7 @@ import * as core from '@actions/core';
44import * as moment from 'moment' ;
55
66import { LogEntry , LogLevelDebug , LogLevelError , LogLevelInformation , LogLevelWarning , SubmitSigningRequestResult , ValidationResult } from './dtos/submit-signing-request-result' ;
7- import { buildSignPathAuthorizationHeader , executeWithRetries , httpErrorResponseToText } from './utils' ;
7+ import { executeWithRetries , httpErrorResponseToText } from './utils' ;
88import { ConnectorUrlBuilder } from './connector-url-builder' ;
99import { HelperInputOutput } from './helper-input-output' ;
1010import { taskVersion } from './version' ;
@@ -15,18 +15,19 @@ import { SigningRequestStatusDto } from './dtos/signing-request-status';
1515// output variables
1616// signingRequestId - the id of the newly created signing request
1717// signingRequestWebUrl - the url of the signing request in SignPath
18- // signPathApiUrl - the base API url of the SignPath API
19- // signingRequestDownloadUrl - the url of the signed artifact in SignPath
18+ // signingRequestDownloadUrl - the url of the signed artifact to retrieve via the connector
2019
2120export class Task {
22- urlBuilder : ConnectorUrlBuilder ;
21+ private readonly urlBuilder : ConnectorUrlBuilder ;
22+ private readonly userAgent : string ;
2323
2424 constructor (
25- private helperInputOutput : HelperInputOutput ,
26- private helperArtifactDownload : HelperArtifactDownload ,
27- private config : Config
25+ private readonly helperInputOutput : HelperInputOutput ,
26+ private readonly helperArtifactDownload : HelperArtifactDownload ,
27+ private readonly config : Config
2828 ) {
2929 this . urlBuilder = new ConnectorUrlBuilder ( this . helperInputOutput . signPathConnectorUrl , this . helperInputOutput . organizationId ) ;
30+ this . userAgent = `SignPath.SubmitSigningRequestGitHubAction/${ taskVersion } (NodeJS/${ process . version } ; ${ process . platform } ${ process . arch } })` ;
3031 }
3132
3233 async run ( ) {
@@ -54,20 +55,18 @@ export class Task {
5455
5556 private async submitSigningRequest ( ) : Promise < string > {
5657
57- core . info ( 'Submitting the signing request to SignPath CI connector...' ) ;
58+ const submitSigningRequestUrl = this . urlBuilder . buildSubmitSigningRequestUrl ( ) ;
59+ core . info ( 'Submitting the signing request to SignPath GitHub Actions connector...' ) ;
5860
5961 // prepare the payload
6062 const submitRequestPayload = this . buildSigningRequestPayload ( ) ;
6163
62- // call the signPath API to submit the signing request
64+ // call the connector to submit the signing request
6365 const response = ( await axios
64- . post < SubmitSigningRequestResult > ( this . urlBuilder . buildSubmitSigningRequestUrl ( ) ,
66+ . post < SubmitSigningRequestResult > ( submitSigningRequestUrl ,
6567 submitRequestPayload ,
6668 {
67- responseType : "json" ,
68- headers : {
69- "Authorization" : buildSignPathAuthorizationHeader ( this . helperInputOutput . signPathApiToken )
70- }
69+ responseType : "json"
7170 } )
7271 . catch ( ( e : AxiosError ) => {
7372
@@ -101,9 +100,7 @@ export class Task {
101100
102101 this . helperInputOutput . setSigningRequestId ( response . signingRequestId ) ;
103102 this . helperInputOutput . setSigningRequestWebUrl ( response . signingRequestUrl ) ;
104-
105- // TODO: think what to set as output
106- // this.helperInputOutput.setSignPathApiUrl(this.urlBuilder.signPathBaseUrl + '/API');
103+ this . helperInputOutput . setSignedArtifactDownloadUrl ( this . urlBuilder . buildGetSignedArtifactUrl ( response . signingRequestId ) )
107104
108105 return response . signingRequestId ;
109106 }
@@ -129,7 +126,6 @@ export class Task {
129126 }
130127 }
131128
132- // TODO: what the heck
133129 // if auto-generated GitHub Actions token (secrets.GITHUB_TOKEN) is used for artifact download,
134130 // ensure the workflow continues running until the download is complete.
135131 // The token is valid only for the workflow's duration
@@ -205,15 +201,13 @@ export class Task {
205201
206202 private async getSigningRequestStatus ( signingRequestId : string ) : Promise < SigningRequestStatusDto > {
207203 const requestStatusUrl = this . urlBuilder . buildGetSigningRequestStatusUrl ( signingRequestId ) ;
204+ core . info ( `Sending request: GET ${ requestStatusUrl } ` )
208205
209206 const signingRequestStatusDto = await axios
210207 . get < SigningRequestStatusDto > (
211208 requestStatusUrl ,
212209 {
213- responseType : "json" ,
214- headers : {
215- "Authorization" : buildSignPathAuthorizationHeader ( this . helperInputOutput . signPathApiToken )
216- }
210+ responseType : "json"
217211 }
218212 )
219213 . catch ( ( e : AxiosError ) => {
@@ -229,10 +223,20 @@ export class Task {
229223 private configureAxios ( ) : void {
230224
231225 // set user agent
232- axios . defaults . headers . common [ 'User-Agent' ] = this . buildUserAgent ( ) ;
226+ axios . defaults . headers . common [ 'User-Agent' ] = this . userAgent ;
227+
228+ // set token for all outgoing requests
229+ axios . defaults . headers . common . Authorization = `Bearer ${ this . helperInputOutput . signPathApiToken } `
230+
233231 const timeoutMs = this . helperInputOutput . serviceUnavailableTimeoutInSeconds * 1000
234232 axios . defaults . timeout = timeoutMs ;
235233
234+ // log all outgoing requests
235+ axios . interceptors . request . use ( request => {
236+ core . info ( `Sending request: ${ request . method ?. toUpperCase ( ) } ${ request . url } ` )
237+ return request ;
238+ } )
239+
236240 // original axiosRetry doesn't work for POST requests
237241 // thats why we need to override some functions
238242 axiosRetry . isNetworkOrIdempotentRequestError = ( error : AxiosError ) => {
@@ -287,11 +291,6 @@ export class Task {
287291
288292 }
289293
290- private buildUserAgent ( ) : string {
291- const userAgent = `SignPath.SubmitSigningRequestGitHubAction/${ taskVersion } (NodeJS/${ process . version } ; ${ process . platform } ${ process . arch } })` ;
292- return userAgent ;
293- }
294-
295294 private checkResponseStructure ( response : SubmitSigningRequestResult ) : void {
296295 if ( ! response . validationResult && ! response . signingRequestId ) {
297296
0 commit comments