@@ -6,9 +6,15 @@ const chalk = require('chalk');
6
6
const { runCommand, logOperation, showError } = require ( './' ) ;
7
7
const { deploymentManifestSchema } = require ( './schemas' ) ;
8
8
const { checkForUpdates } = require ( './update' ) ;
9
+ const execa = require ( 'execa' ) ;
9
10
10
11
const getBinPath = bin => path . join ( __dirname , '../../.env/bin' , bin ) ;
11
12
13
+ const envAWSKeysExist = function ( ) {
14
+ const { AWS_ACCESS_KEY_ID , AWS_SECRET_ACCESS_KEY } = process . env ;
15
+ return AWS_ACCESS_KEY_ID && AWS_SECRET_ACCESS_KEY ;
16
+ }
17
+
12
18
const installEnvironment = async ( ) => {
13
19
if ( await fs . pathExists ( path . join ( __dirname , '../../.env' ) ) ) {
14
20
logOperation ( 'Environment already exists, skipping installation.' ) ;
@@ -23,6 +29,10 @@ const installEnvironment = async () => {
23
29
} ;
24
30
25
31
const installRequirements = async ( ) => {
32
+ if ( envAWSKeysExist ( ) ) {
33
+ logOperation ( 'AWS API key environment variables is set, `awsudo` not needed.' ) ;
34
+ return ;
35
+ }
26
36
if ( await fs . pathExists ( getBinPath ( 'awsudo' ) ) ) {
27
37
logOperation ( '`awsudo` exists, skipping installation.' ) ;
28
38
return ;
@@ -37,9 +47,9 @@ const installRequirements = async () => {
37
47
} ;
38
48
39
49
exports . checkEnvironment = async ( ) => {
40
- if ( ! process . env . AWS_PROFILE ) {
50
+ if ( ! process . env . AWS_PROFILE && ! envAWSKeysExist ( ) ) {
41
51
return showError (
42
- 'You have to set `AWS_PROFILE` environment variable before continuing . Visit https://docs.cxcloud.com for help.'
52
+ 'Some environment variables has to be set before running cxcloud . Visit https://docs.cxcloud.com for help.'
43
53
) ;
44
54
}
45
55
@@ -48,6 +58,21 @@ exports.checkEnvironment = async () => {
48
58
await installRequirements ( ) ;
49
59
} ;
50
60
61
+ exports . runCommandWithAWSCredentials = ( cmd , args ) => {
62
+ if ( envAWSKeysExist ( ) ) {
63
+ return execa ( getBinPath ( cmd ) , [
64
+ ...args
65
+ ] ) ;
66
+ } else {
67
+ return execa ( getBinPath ( 'awsudo' ) , [
68
+ '-u' ,
69
+ process . env . AWS_PROFILE ,
70
+ getBinPath ( cmd ) ,
71
+ ...args
72
+ ] ) ;
73
+ }
74
+ }
75
+
51
76
exports . getBinPath = getBinPath ;
52
77
53
78
exports . ensureDeployEnvironment = async ( ) => {
0 commit comments