Skip to content

Commit 73473a8

Browse files
committed
bake: hasGitAuthTokenSecret func
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent e36200f commit 73473a8

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

__tests__/.fixtures/bake-03-default.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@
4242
"ref": "user/app",
4343
"type": "registry"
4444
}
45+
],
46+
"secret": [
47+
{
48+
"env": "GITHUB_TOKEN",
49+
"id": "GITHUB_TOKEN"
50+
},
51+
{
52+
"id": "aws",
53+
"src": "__tests__/.fixtures/secret.txt"
54+
},
55+
{
56+
"id": "GITHUB_REPOSITORY"
57+
}
4558
]
4659
}
4760
}

__tests__/.fixtures/bake-03.hcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ target "default" {
2929
"./release-out",
3030
"type=registry,ref=user/app"
3131
]
32+
secret = [
33+
"id=GITHUB_TOKEN,env=GITHUB_TOKEN",
34+
"id=aws,src=__tests__/.fixtures/secret.txt",
35+
"id=GITHUB_REPOSITORY"
36+
]
3237
}

__tests__/buildx/bake.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,3 +444,44 @@ describe('hasDockerExporter', () => {
444444
expect(Bake.hasDockerExporter(def, load)).toEqual(expected);
445445
});
446446
});
447+
448+
describe('hasGitAuthTokenSecret', () => {
449+
// prettier-ignore
450+
test.each([
451+
[
452+
{
453+
"target": {
454+
"reg": {
455+
"secret": [
456+
{
457+
"id": "A_SECRET",
458+
"env": "A_SECRET"
459+
}
460+
]
461+
},
462+
}
463+
} as unknown as BakeDefinition,
464+
false
465+
],
466+
[
467+
{
468+
"target": {
469+
"reg": {
470+
"secret": [
471+
{
472+
"id": "A_SECRET",
473+
"env": "A_SECRET"
474+
},
475+
{
476+
"id": "GIT_AUTH_TOKEN"
477+
}
478+
]
479+
},
480+
}
481+
} as unknown as BakeDefinition,
482+
true
483+
],
484+
])('given %o returns %p', async (def: BakeDefinition, expected: boolean) => {
485+
expect(Bake.hasGitAuthTokenSecret(def)).toEqual(expected);
486+
});
487+
});

src/buildx/bake.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ export class Bake {
348348
secretEntry.src = value;
349349
break;
350350
case 'env':
351+
secretEntry.env = value;
351352
break;
352353
}
353354
}
@@ -406,4 +407,18 @@ export class Bake {
406407
}
407408
return exporters;
408409
}
410+
411+
public static hasGitAuthTokenSecret(def: BakeDefinition): boolean {
412+
for (const key in def.target) {
413+
const target = def.target[key];
414+
if (target.secret) {
415+
for (const secret of target.secret) {
416+
if (Bake.parseSecretEntry(secret).id === 'GIT_AUTH_TOKEN') {
417+
return true;
418+
}
419+
}
420+
}
421+
}
422+
return false;
423+
}
409424
}

0 commit comments

Comments
 (0)