bake: hasGitAuthTokenSecret func
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -42,6 +42,19 @@
|
|||||||
"ref": "user/app",
|
"ref": "user/app",
|
||||||
"type": "registry"
|
"type": "registry"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"secret": [
|
||||||
|
{
|
||||||
|
"env": "GITHUB_TOKEN",
|
||||||
|
"id": "GITHUB_TOKEN"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "aws",
|
||||||
|
"src": "__tests__/.fixtures/secret.txt"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "GITHUB_REPOSITORY"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,4 +29,9 @@ target "default" {
|
|||||||
"./release-out",
|
"./release-out",
|
||||||
"type=registry,ref=user/app"
|
"type=registry,ref=user/app"
|
||||||
]
|
]
|
||||||
|
secret = [
|
||||||
|
"id=GITHUB_TOKEN,env=GITHUB_TOKEN",
|
||||||
|
"id=aws,src=__tests__/.fixtures/secret.txt",
|
||||||
|
"id=GITHUB_REPOSITORY"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -444,3 +444,44 @@ describe('hasDockerExporter', () => {
|
|||||||
expect(Bake.hasDockerExporter(def, load)).toEqual(expected);
|
expect(Bake.hasDockerExporter(def, load)).toEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('hasGitAuthTokenSecret', () => {
|
||||||
|
// prettier-ignore
|
||||||
|
test.each([
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"target": {
|
||||||
|
"reg": {
|
||||||
|
"secret": [
|
||||||
|
{
|
||||||
|
"id": "A_SECRET",
|
||||||
|
"env": "A_SECRET"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} as unknown as BakeDefinition,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"target": {
|
||||||
|
"reg": {
|
||||||
|
"secret": [
|
||||||
|
{
|
||||||
|
"id": "A_SECRET",
|
||||||
|
"env": "A_SECRET"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "GIT_AUTH_TOKEN"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} as unknown as BakeDefinition,
|
||||||
|
true
|
||||||
|
],
|
||||||
|
])('given %o returns %p', async (def: BakeDefinition, expected: boolean) => {
|
||||||
|
expect(Bake.hasGitAuthTokenSecret(def)).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -348,6 +348,7 @@ export class Bake {
|
|||||||
secretEntry.src = value;
|
secretEntry.src = value;
|
||||||
break;
|
break;
|
||||||
case 'env':
|
case 'env':
|
||||||
|
secretEntry.env = value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -406,4 +407,18 @@ export class Bake {
|
|||||||
}
|
}
|
||||||
return exporters;
|
return exporters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static hasGitAuthTokenSecret(def: BakeDefinition): boolean {
|
||||||
|
for (const key in def.target) {
|
||||||
|
const target = def.target[key];
|
||||||
|
if (target.secret) {
|
||||||
|
for (const secret of target.secret) {
|
||||||
|
if (Bake.parseSecretEntry(secret).id === 'GIT_AUTH_TOKEN') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user