insert secrets dynamically, expect uniqueness to fail

pull/263/head
Frostebite 2021-05-02 02:28:58 +01:00
parent 97d1a5bb54
commit d4099caeff
3 changed files with 71 additions and 63 deletions

66
dist/index.js vendored
View File

@ -478,40 +478,44 @@ class AWS {
`; `;
const taskDefStackName = `${stackName}-${buildUid}`; const taskDefStackName = `${stackName}-${buildUid}`;
let taskDefCloudFormation = fs.readFileSync(`${__dirname}/cloud-formations/task-def-formation.yml`, 'utf8'); let taskDefCloudFormation = fs.readFileSync(`${__dirname}/cloud-formations/task-def-formation.yml`, 'utf8');
const p1string = 'p1 - input'; for (const secret of secrets) {
const p2string = 'p2 - secret'; const p1string = 'p1 - input';
const p3string = 'p3 - container def'; const p2string = 'p2 - secret';
const indexp1 = taskDefCloudFormation.search(p1string) + p1string.length + '\n'.length; const p3string = 'p3 - container def';
const template1 = ` const indexp1 = taskDefCloudFormation.search(p1string) + p1string.length + '\n'.length;
AWSSecretAccessKeyssss: const template1 = `
${secret.ParameterKey}:
Type: String Type: String
Default: '0'`; Default: ''
taskDefCloudFormation = [ `;
taskDefCloudFormation.slice(0, indexp1), taskDefCloudFormation = [
template1, taskDefCloudFormation.slice(0, indexp1),
taskDefCloudFormation.slice(indexp1), template1,
].join(''); taskDefCloudFormation.slice(indexp1),
const indexp2 = taskDefCloudFormation.search(p2string) + p2string.length + '\n'.length; ].join('');
const template2 = ` const indexp2 = taskDefCloudFormation.search(p2string) + p2string.length + '\n'.length;
TestSec: const template2 = `
${secret.ParameterKey}Secret:
Type: AWS::SecretsManager::Secret Type: AWS::SecretsManager::Secret
Properties: Properties:
Name: !Join [ "", [ 'testsec', !Ref BUILDID ] ] Name: !Join [ "", [ '${secret.ParameterKey}', !Ref BUILDID ] ]
SecretString: !Ref AWSSecretAccessKey`; SecretString: !Ref ${secret.ParameterKey}
taskDefCloudFormation = [ `;
taskDefCloudFormation.slice(0, indexp2), taskDefCloudFormation = [
template2, taskDefCloudFormation.slice(0, indexp2),
taskDefCloudFormation.slice(indexp2), template2,
].join(''); taskDefCloudFormation.slice(indexp2),
const indexp3 = taskDefCloudFormation.search(p3string) + p3string.length + '\n'.length; ].join('');
const template3 = ` const indexp3 = taskDefCloudFormation.search(p3string) + p3string.length + '\n'.length;
- Name: 'test' const template3 = `
ValueFrom: !Ref GithubTokenSecret`; - Name: '${secret.ParameterKey.toUpperCase()}'
taskDefCloudFormation = [ ValueFrom: !Ref ${secret.ParameterKey}Secret`;
taskDefCloudFormation.slice(0, indexp3), taskDefCloudFormation = [
template3, taskDefCloudFormation.slice(0, indexp3),
taskDefCloudFormation.slice(indexp3), template3,
].join(''); taskDefCloudFormation.slice(indexp3),
].join('');
}
core.info(taskDefCloudFormation); core.info(taskDefCloudFormation);
yield CF.createStack({ yield CF.createStack({
StackName: taskDefStackName, StackName: taskDefStackName,

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -333,40 +333,44 @@ class AWS {
`; `;
const taskDefStackName = `${stackName}-${buildUid}`; const taskDefStackName = `${stackName}-${buildUid}`;
let taskDefCloudFormation = fs.readFileSync(`${__dirname}/cloud-formations/task-def-formation.yml`, 'utf8'); let taskDefCloudFormation = fs.readFileSync(`${__dirname}/cloud-formations/task-def-formation.yml`, 'utf8');
const p1string = 'p1 - input'; for (const secret of secrets) {
const p2string = 'p2 - secret'; const p1string = 'p1 - input';
const p3string = 'p3 - container def'; const p2string = 'p2 - secret';
const indexp1 = taskDefCloudFormation.search(p1string) + p1string.length + '\n'.length; const p3string = 'p3 - container def';
const template1 = ` const indexp1 = taskDefCloudFormation.search(p1string) + p1string.length + '\n'.length;
AWSSecretAccessKeyssss: const template1 = `
${secret.ParameterKey}:
Type: String Type: String
Default: '0'`; Default: ''
taskDefCloudFormation = [ `;
taskDefCloudFormation.slice(0, indexp1), taskDefCloudFormation = [
template1, taskDefCloudFormation.slice(0, indexp1),
taskDefCloudFormation.slice(indexp1), template1,
].join(''); taskDefCloudFormation.slice(indexp1),
const indexp2 = taskDefCloudFormation.search(p2string) + p2string.length + '\n'.length; ].join('');
const template2 = ` const indexp2 = taskDefCloudFormation.search(p2string) + p2string.length + '\n'.length;
TestSec: const template2 = `
${secret.ParameterKey}Secret:
Type: AWS::SecretsManager::Secret Type: AWS::SecretsManager::Secret
Properties: Properties:
Name: !Join [ "", [ 'testsec', !Ref BUILDID ] ] Name: !Join [ "", [ '${secret.ParameterKey}', !Ref BUILDID ] ]
SecretString: !Ref AWSSecretAccessKey`; SecretString: !Ref ${secret.ParameterKey}
taskDefCloudFormation = [ `;
taskDefCloudFormation.slice(0, indexp2), taskDefCloudFormation = [
template2, taskDefCloudFormation.slice(0, indexp2),
taskDefCloudFormation.slice(indexp2), template2,
].join(''); taskDefCloudFormation.slice(indexp2),
const indexp3 = taskDefCloudFormation.search(p3string) + p3string.length + '\n'.length; ].join('');
const template3 = ` const indexp3 = taskDefCloudFormation.search(p3string) + p3string.length + '\n'.length;
- Name: 'test' const template3 = `
ValueFrom: !Ref GithubTokenSecret`; - Name: '${secret.ParameterKey.toUpperCase()}'
taskDefCloudFormation = [ ValueFrom: !Ref ${secret.ParameterKey}Secret`;
taskDefCloudFormation.slice(0, indexp3), taskDefCloudFormation = [
template3, taskDefCloudFormation.slice(0, indexp3),
taskDefCloudFormation.slice(indexp3), template3,
].join(''); taskDefCloudFormation.slice(indexp3),
].join('');
}
core.info(taskDefCloudFormation); core.info(taskDefCloudFormation);