Skip to content

Commit

Permalink
feat: export config only values
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ruan committed Sep 7, 2021
1 parent f67ecfb commit bb74c15
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 23 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[![NPM Status][npm-image]][npm-url]
[![dependencies Status][dependencies-image]][dependencies-url]


# 🐝 Oprah

Node module to push configuration and encrypted secrets to AWS.
Expand Down Expand Up @@ -51,7 +50,6 @@ $ oprah run --stage <stage> --interactive

Following is the configuration file will all possible options:


```
service: oprah-service
provider: ssm # Only supports ssm for now.
Expand Down Expand Up @@ -181,6 +179,8 @@ Options:
-t, --target [target] The output target, available options are json|env
(default:json)
-C, --config-only [configOnly] Only export `config` section
-h, --help display help for command
```

Expand All @@ -203,9 +203,9 @@ Feel free to use the code, it's released using the MIT license.

[github-actions-image]: https://github.com/acloudguru/oprah/actions/workflows/publish.yml/badge.svg
[github-actions-url]: https://github.com/ACloudGuru/oprah/actions/workflows/publish.yml
[dependencies-image]:https://david-dm.org/ACloudGuru/oprah/status.svg
[dependencies-url]:https://david-dm.org/ACloudGuru/oprah
[npm-image]:https://img.shields.io/npm/v/oprah.svg
[npm-url]:https://www.npmjs.com/package/oprah
[codacy-image]:https://api.codacy.com/project/badge/Grade/6464d14b26214357ba838d2cdbdfcb8e
[codacy-url]:https://www.codacy.com/app/subash.adhikari/oprah?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=ACloudGuru/oprah&amp;utm_campaign=Badge_Grade
[dependencies-image]: https://david-dm.org/ACloudGuru/oprah/status.svg
[dependencies-url]: https://david-dm.org/ACloudGuru/oprah
[npm-image]: https://img.shields.io/npm/v/oprah.svg
[npm-url]: https://www.npmjs.com/package/oprah
[codacy-image]: https://api.codacy.com/project/badge/Grade/6464d14b26214357ba838d2cdbdfcb8e
[codacy-url]: https://www.codacy.com/app/subash.adhikari/oprah?utm_source=github.com&utm_medium=referral&utm_content=ACloudGuru/oprah&utm_campaign=Badge_Grade
6 changes: 4 additions & 2 deletions bin/oprah
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ program
'-t, --target [target]',
'The output target, available options are json|env (default:json)'
)
.action(({ path, target }) => {
.option('-C, --config-only [configOnly]', 'Only export configs')
.action(({ path, target, configOnly = false }) => {
const { stage, config } = program.opts();
oprahPromise = makeOprah({ stage, config }).export(
path || (target === 'env' ? '.env_oprah' : '/tmp/oprah-exports.json'),
target || 'json'
target || 'json',
configOnly
);
});

Expand Down
11 changes: 7 additions & 4 deletions lib/commands/import-export/make-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ const { log } = require('../../utils/logger');

const makeExport = ({ settingsService, parameterStore }) => async (
filePath,
target
target,
configOnly = false
) => {
const settings = await settingsService.getSettings();

log(chalk.white(`Getting parameters..`));

const secretsPromise = parameterStore.getParameters({
parameterNames: get(settings, 'secretParameters')
});
const secretsPromise = configOnly
? Promise.resolve({})
: parameterStore.getParameters({
parameterNames: get(settings, 'secretParameters')
});

const configsPromise = parameterStore.getParameters({
parameterNames: get(settings, 'configParameters')
Expand Down
41 changes: 34 additions & 7 deletions lib/commands/import-export/make-export.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ describe('export', () => {
configParameters: ['path/to/config1']
})
);
});

afterEach(() => {
fs.writeFileSync.mockClear();
});

it('should write JSON version to the specified file path', () => {
getParametersMock
.mockImplementationOnce(() =>
Promise.resolve({
Expand All @@ -40,13 +46,7 @@ describe('export', () => {
'path/to/config1': 'config1Value'
})
);
});

afterEach(() => {
fs.writeFileSync.mockClear();
});

it('should write JSON version to the specified file path', () => {
const filePath = './test.json';

return exportFunction(filePath).then(() => {
Expand All @@ -69,12 +69,39 @@ describe('export', () => {
it('should write ENV version to the specified file path', () => {
const filePath = './.env.test';
const target = 'env';

getParametersMock
.mockImplementationOnce(() =>
Promise.resolve({
'path/to/secret1': 'secret1Value'
})
)
.mockImplementationOnce(() =>
Promise.resolve({
'path/to/config1': 'config1Value'
})
);
return exportFunction(filePath, target).then(() => {
expect(fs.writeFileSync).toHaveBeenCalledWith(
filePath,
'path_to_config1="config1Value"\npath_to_secret1="secret1Value"\n'
);
});
});

it('should only get parameters for configs if configOnly is true', async () => {
getParametersMock.mockImplementationOnce(() =>
Promise.resolve({
'path/to/config1': 'config1Value'
})
);
const filePath = './.env.test';
const target = 'env';

return exportFunction(filePath, target, true).then(() => {
expect(fs.writeFileSync).toHaveBeenCalledWith(
filePath,
'path_to_config1="config1Value"\n'
);
});
});
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oprah",
"version": "5.2.1",
"version": "5.3.0",
"description": "Package to deploy parameters to AWS",
"repository": "https://github.com/ACloudGuru/oprah.git",
"author": "subash adhikari <subash.adhikari@acloud.guru>",
Expand Down Expand Up @@ -60,4 +60,4 @@
"pinst": "^2.1.6",
"prettier": "^1.18.2"
}
}
}

0 comments on commit bb74c15

Please sign in to comment.