Skip to content

Commit

Permalink
buildx: hasAttestationType func
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Mar 26, 2024
1 parent de2888a commit db709e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions __tests__/buildx/inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ describe('hasDockerExporter', () => {
});
});

describe('hasAttestationType', () => {
// prettier-ignore
test.each([
['type=provenance,mode=min', 'provenance', true],
['type=sbom,true', 'sbom', true],
['type=foo,bar', 'provenance', false],
])('given %p for %p returns %p', async (attrs: string, name: string, expected: boolean) => {
expect(Inputs.hasAttestationType(name, attrs)).toEqual(expected);
});
});

describe('hasGitAuthTokenSecret', () => {
// prettier-ignore
test.each([
Expand Down
17 changes: 17 additions & 0 deletions src/buildx/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@ export class Inputs {
return false;
}

public static hasAttestationType(name: string, attrs: string): boolean {
const attributes = parse(attrs, {
delimiter: ',',
trim: true,
columns: false,
relaxColumnCount: true
});
for (const attr of attributes) {
for (const [key, value] of attr.map((chunk: string) => chunk.split('=').map(item => item.trim()))) {
if (key == 'type' && value == name) {
return true;
}
}
}
return false;
}

public static hasGitAuthTokenSecret(secrets: string[]): boolean {
for (const secret of secrets) {
if (secret.startsWith('GIT_AUTH_TOKEN=')) {
Expand Down

0 comments on commit db709e6

Please sign in to comment.