Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGN-7471 - connector logs support #31

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
28 changes: 27 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,35 @@ 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:
core.info(log.message);
break;
case LogLevelWarning:
core.warning(log.message);
break;
case LogLevelError:
core.error(log.message);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will logging to the error stream cause the workflow to actually fail? How does this interfere with the validation result?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it will not. This has nothing to do with the validation result. It’s simply a way to convey additional information to the user—such as notifying them that, during validation, we noticed they have a policy file, so we will use it. Such a message is not part of the validation result; it’s just additional insight into what was happening in the connector.

break;
default:
core.info(log.message);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhmm, should we maybe prefix this with unknown log level or something? IDK

break;
}
});
}
}

private buildSigningRequestPayload(): any {
return {
signPathApiToken: this.helperInputOutput.signPathApiToken,
Expand Down
18 changes: 15 additions & 3 deletions actions/submit-signing-request/tests/task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { HelperInputOutput } from '../helper-input-output';
import { HelperArtifactDownload } from '../helper-artifact-download';
import axiosRetry from 'axios-retry';
import { Config } from '../config';
import { log } from 'console';

const testSignPathApiToken = 'TEST_TOKEN';
const testSigningRequestId = 'TEST_ID';
Expand All @@ -23,6 +24,7 @@ const testOrganizationId = 'TEST_ORGANIZATION_ID';
const testProjectSlug = 'TEST_PROJECT_SLUG';
const testSigningPolicySlug = 'TEST_POLICY_SLUG';
const testGitHubToken = 'TEST_GITHUB_TOKEN';
const testConnectorLogMessage = 'TEST_CONNECTOR_LOG_MESSAGE';

const defaultTestInputMap = {
'wait-for-completion': 'true',
Expand Down Expand Up @@ -59,7 +61,8 @@ beforeEach(() => {
isFinalStatus: true,
status: 'Completed',
unsignedArtifactLink: testUnsignedArtifactLink,
signedArtifactLink: testSignedArtifactLink
signedArtifactLink: testSignedArtifactLink,
logs: [ { message: testConnectorLogMessage, level: 'Information' } ]
};

const getSigningRequestResponse = submitSigningRequestResponse;
Expand Down Expand Up @@ -143,15 +146,15 @@ it('test that the signing request was not submitted due to validation errors', a
return value.includes('TEST_ERROR');
}));
// check that howToFix message was logged
const infoLogStub = sandbox.stub(core, 'info')
const coreInfoStub = sandbox.stub(core, 'info')
.withArgs(sinon.match((value:any) => {
return value.includes('TEST_FIX');
}));

await task.run();
assert.equal(setFailedStub.calledOnce, true);
assert.equal(errorLogStub.called, true);
assert.equal(infoLogStub.called, true);
assert.equal(coreInfoStub.called, true);
});

it('test that the output variables are set correctly', async () => {
Expand All @@ -162,6 +165,15 @@ it('test that the output variables are set correctly', async () => {
assert.equal(setOutputStub.calledWith('signed-artifact-download-url', testSignedArtifactLink), true);
});

it('connector logs logged to the build log', async () => {
const coreInfoStub = sandbox.stub(core, 'info')
.withArgs(sinon.match((value:any) => {
return value.includes(testConnectorLogMessage);
}));
await task.run();
assert.equal(coreInfoStub.called, true);
});

it('test that the connectors url has api version', async () => {
await task.run();
assert.equal(axiosPostStub.calledWith(
Expand Down
Loading