@karmaniverous/get-dotenv 2.4.3 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/bin/getdotenv/index.js +15 -1
- package/dist/default/lib/getAwsSsoCredentials.js +33 -0
- package/dist/default/lib/index.js +7 -0
- package/dist/default/lib/parseBranch.js +1 -1
- package/lib/getAwsSsoCredentials.js +28 -0
- package/lib/index.js +1 -0
- package/lib/parseBranch.js +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -85,6 +85,7 @@ dotenv files. You can:
|
|
|
85
85
|
arguments for other options.
|
|
86
86
|
* Specify the token that identifies dotenv files (e.g. '.env').
|
|
87
87
|
* Specify the token that identifies private vatiables (e.g. '.local').
|
|
88
|
+
* Load AWS SSO session credentials from an AWS Toolkit profile.
|
|
88
89
|
|
|
89
90
|
Options:
|
|
90
91
|
-p, --paths <strings...> space-delimited paths to dotenv directory (default './')
|
|
@@ -103,6 +104,7 @@ Options:
|
|
|
103
104
|
-t, --dotenv-token <string> token indicating a dotenv file (default: '.env')
|
|
104
105
|
-i, --private-token <string> token indicating private variables (default: 'local')
|
|
105
106
|
-q, --quit-on-error terminate sequential process on error (default: false)
|
|
107
|
+
-a, --aws-sso-profile <string> local AWS SSO profile (follows dotenv-expand rules)
|
|
106
108
|
-h, --help display help for command
|
|
107
109
|
```
|
|
108
110
|
|
package/bin/getdotenv/index.js
CHANGED
|
@@ -6,7 +6,11 @@ import _ from 'lodash';
|
|
|
6
6
|
import { parseArgsStringToArgv } from 'string-argv';
|
|
7
7
|
|
|
8
8
|
// Import package exports.
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
getAwsSsoCredentials,
|
|
11
|
+
getDotenv,
|
|
12
|
+
parseBranch,
|
|
13
|
+
} from '@karmaniverous/get-dotenv';
|
|
10
14
|
|
|
11
15
|
// Create CLI.
|
|
12
16
|
import { program } from 'commander';
|
|
@@ -40,6 +44,7 @@ program
|
|
|
40
44
|
` arguments for other options.`,
|
|
41
45
|
`* Specify the token that identifies dotenv files (e.g. '.env').`,
|
|
42
46
|
`* Specify the token that identifies private vatiables (e.g. '.local').`,
|
|
47
|
+
`* Load AWS SSO session credentials from an AWS Toolkit profile.`,
|
|
43
48
|
].join('\n')
|
|
44
49
|
);
|
|
45
50
|
|
|
@@ -93,11 +98,17 @@ program
|
|
|
93
98
|
.option(
|
|
94
99
|
'-q, --quit-on-error',
|
|
95
100
|
'terminate sequential process on error (default: false)'
|
|
101
|
+
)
|
|
102
|
+
.option(
|
|
103
|
+
'-a, --aws-sso-profile <string>',
|
|
104
|
+
'local AWS SSO profile (follows dotenv-expand rules)',
|
|
105
|
+
envMerge
|
|
96
106
|
);
|
|
97
107
|
|
|
98
108
|
// Parse CLI options from command line.
|
|
99
109
|
program.parse();
|
|
100
110
|
const {
|
|
111
|
+
awsSsoProfile,
|
|
101
112
|
branchToDefault,
|
|
102
113
|
command,
|
|
103
114
|
defaultEnvironment,
|
|
@@ -140,6 +151,9 @@ await getDotenv({
|
|
|
140
151
|
privateToken,
|
|
141
152
|
});
|
|
142
153
|
|
|
154
|
+
// Get AWS SSO credentials.
|
|
155
|
+
if (awsSsoProfile) getAwsSsoCredentials(awsSsoProfile);
|
|
156
|
+
|
|
143
157
|
// Execute shell command.
|
|
144
158
|
if (command || program.args.length) {
|
|
145
159
|
const argvs = (command ?? program.args.join(' '))
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAwsSsoCredentials = void 0;
|
|
7
|
+
var _crossSpawn = _interopRequireDefault(require("cross-spawn"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
// npm imports
|
|
10
|
+
|
|
11
|
+
const getAwsSsoCredentials = localProfile => {
|
|
12
|
+
if (!localProfile) {
|
|
13
|
+
delete process.env.AWS_ACCESS_KEY_ID;
|
|
14
|
+
delete process.env.AWS_SECRET_ACCESS_KEY;
|
|
15
|
+
delete process.env.AWS_SESSION_TOKEN;
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const {
|
|
19
|
+
status,
|
|
20
|
+
stderr,
|
|
21
|
+
stdout
|
|
22
|
+
} = _crossSpawn.default.sync('aws', ['configure', 'export-credentials', '--profile', localProfile]);
|
|
23
|
+
if (status) throw new Error(stderr.toString());
|
|
24
|
+
const {
|
|
25
|
+
AccessKeyId,
|
|
26
|
+
SecretAccessKey,
|
|
27
|
+
SessionToken
|
|
28
|
+
} = JSON.parse(stdout.toString());
|
|
29
|
+
process.env.AWS_ACCESS_KEY_ID = AccessKeyId;
|
|
30
|
+
process.env.AWS_SECRET_ACCESS_KEY = SecretAccessKey;
|
|
31
|
+
process.env.AWS_SESSION_TOKEN = SessionToken;
|
|
32
|
+
};
|
|
33
|
+
exports.getAwsSsoCredentials = getAwsSsoCredentials;
|
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "getAwsSsoCredentials", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _getAwsSsoCredentials.getAwsSsoCredentials;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "getDotenv", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
@@ -21,5 +27,6 @@ Object.defineProperty(exports, "parseBranch", {
|
|
|
21
27
|
return _parseBranch.parseBranch;
|
|
22
28
|
}
|
|
23
29
|
});
|
|
30
|
+
var _getAwsSsoCredentials = require("./getAwsSsoCredentials.js");
|
|
24
31
|
var _getDotenv = require("./getDotenv.js");
|
|
25
32
|
var _parseBranch = require("./parseBranch.js");
|
|
@@ -15,6 +15,6 @@ const parseBranch = branchName => {
|
|
|
15
15
|
} catch {
|
|
16
16
|
branchName ??= '';
|
|
17
17
|
}
|
|
18
|
-
return _lodash.default.omitBy(branchName.match(/^(?<branchType>[^/\s]+)(
|
|
18
|
+
return _lodash.default.omitBy(branchName.match(/^(?:(?<branchType>[^/\s]+)\/(?:(?<branchLabel>[^/\s]+)))?(?:\/?(?<envToken>[^/\s]+))?$/)?.groups ?? {}, _lodash.default.isNil);
|
|
19
19
|
};
|
|
20
20
|
exports.parseBranch = parseBranch;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// npm imports
|
|
2
|
+
import spawn from 'cross-spawn';
|
|
3
|
+
|
|
4
|
+
export const getAwsSsoCredentials = (localProfile) => {
|
|
5
|
+
if (!localProfile) {
|
|
6
|
+
delete process.env.AWS_ACCESS_KEY_ID;
|
|
7
|
+
delete process.env.AWS_SECRET_ACCESS_KEY;
|
|
8
|
+
delete process.env.AWS_SESSION_TOKEN;
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { status, stderr, stdout } = spawn.sync('aws', [
|
|
13
|
+
'configure',
|
|
14
|
+
'export-credentials',
|
|
15
|
+
'--profile',
|
|
16
|
+
localProfile,
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
if (status) throw new Error(stderr.toString());
|
|
20
|
+
|
|
21
|
+
const { AccessKeyId, SecretAccessKey, SessionToken } = JSON.parse(
|
|
22
|
+
stdout.toString()
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
process.env.AWS_ACCESS_KEY_ID = AccessKeyId;
|
|
26
|
+
process.env.AWS_SECRET_ACCESS_KEY = SecretAccessKey;
|
|
27
|
+
process.env.AWS_SESSION_TOKEN = SessionToken;
|
|
28
|
+
};
|
package/lib/index.js
CHANGED
package/lib/parseBranch.js
CHANGED
|
@@ -11,7 +11,7 @@ export const parseBranch = (branchName) => {
|
|
|
11
11
|
|
|
12
12
|
return _.omitBy(
|
|
13
13
|
branchName.match(
|
|
14
|
-
/^(?<branchType>[^/\s]+)(
|
|
14
|
+
/^(?:(?<branchType>[^/\s]+)\/(?:(?<branchLabel>[^/\s]+)))?(?:\/?(?<envToken>[^/\s]+))?$/
|
|
15
15
|
)?.groups ?? {},
|
|
16
16
|
_.isNil
|
|
17
17
|
);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"bin": {
|
|
4
4
|
"getdotenv": "bin/getdotenv/index.js"
|
|
5
5
|
},
|
|
6
|
-
"version": "2.
|
|
6
|
+
"version": "2.5.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -85,12 +85,12 @@
|
|
|
85
85
|
},
|
|
86
86
|
"scripts": {
|
|
87
87
|
"cli": "node ./bin/getdotenv",
|
|
88
|
-
"lint": "eslint lib/** bin/**",
|
|
89
|
-
"test": "mocha",
|
|
90
88
|
"build": "babel lib -d dist/default/lib --delete-dir-on-start --config-file ./dist/default/.babelrc",
|
|
91
89
|
"doc": "jsdoc2md -c doc/jsdoc.config.json -f lib/**/*.* -t doc/api-template.hbs > doc/3-api.jsdoc2.md && concat-md doc --hide-anchor-links > README.md",
|
|
92
|
-
"
|
|
93
|
-
"
|
|
90
|
+
"lint": "eslint lib/** bin/**",
|
|
91
|
+
"prerelease": "npm run lint && npm run test && npm run build && npm run doc",
|
|
92
|
+
"release": "release-it",
|
|
93
|
+
"test": "mocha"
|
|
94
94
|
},
|
|
95
95
|
"type": "module"
|
|
96
96
|
}
|