Skip to content

Commit

Permalink
SIGN-7471 - connector logs support
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-bobko committed Dec 11, 2024
1 parent 5ce03f0 commit 173fcbc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface SubmitSigningRequestResult {
validationResult: ValidationResult;
signingRequestUrl: string;
error: string;
logs: LogEntry[];
}

export interface ValidationResult {
Expand All @@ -12,4 +13,14 @@ export interface ValidationResult {
export interface ValidationError {
error: string;
howToFix: string;
}
}

export interface LogEntry {
message: string;
level: string;
}

export const LogLevelDebug = "Debug";
export const LogLevelInformation = "Information";
export const LogLevelWarning = "Warning";
export const LogLevelError = "Error";
29 changes: 28 additions & 1 deletion actions/submit-signing-request/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as core from '@actions/core';
import * as moment from 'moment';
import url from 'url';

import { SubmitSigningRequestResult, ValidationResult } from './dtos/submit-signing-request-result';
import { LogEntry, LogLevelDebug, LogLevelError, LogLevelInformation, LogLevelWarning, SubmitSigningRequestResult, ValidationResult } from './dtos/submit-signing-request-result';
import { buildSignPathAuthorizationHeader, executeWithRetries, httpErrorResponseToText } from './utils';
import { SignPathUrlBuilder } from './signpath-url-builder';
import { SigningRequestDto } from './dtos/signing-request';
Expand Down Expand Up @@ -88,6 +88,7 @@ export class Task {

this.checkResponseStructure(response);
this.checkCiSystemValidationResult(response.validationResult);
this.redirectConnectorLogsToActionLogs(response.logs);

const signingRequestUrlObj = url.parse(response.signingRequestUrl);
this.urlBuilder.signPathBaseUrl = signingRequestUrlObj.protocol + '//' + signingRequestUrlObj.host;
Expand Down Expand Up @@ -292,10 +293,36 @@ export class Task {

// if neither validationResult nor signingRequestId are present,
// then the response might be not from the connector
core.error(`Unexpected response from the SignPath connector: ${JSON.stringify(response)}`);
throw new Error(`SignPath signing request was not created. Please make sure that connector-url is pointing to the SignPath GitHub Actions connector endpoint.`);
}
}

private redirectConnectorLogsToActionLogs(logs: LogEntry[]): void {
if (logs && logs.length > 0) {
logs.forEach(log => {
switch (log.level) {
case LogLevelDebug:
core.debug(log.message);
break;
case LogLevelInformation:
console.log('asdasdasdasdasd');
core.info(log.message);
break;
case LogLevelWarning:
core.warning(log.message);
break;
case LogLevelError:
core.error(log.message);
break;
default:
core.info(log.message);
break;
}
});
}
}

private buildSigningRequestPayload(): any {
return {
signPathApiToken: this.helperInputOutput.signPathApiToken,
Expand Down

0 comments on commit 173fcbc

Please sign in to comment.