@@ -47,36 +47,46 @@ import (
4747)
4848
4949var (
50- _flagClusterEnv string
51- _flagClusterConfig string
52- _flagClusterInfoDebug bool
53- _flagClusterDisallowPrompt bool
50+ _flagClusterEnv string
51+ _flagClusterConfig string
52+ _flagClusterInfoDebug bool
53+ _flagClusterDisallowPrompt bool
54+ _flagAWSAccessKeyID string
55+ _flagAWSSecretAccessKey string
56+ _flagClusterAWSAccessKeyID string
57+ _flagClusterAWSSecretAccessKey string
5458)
5559
5660func clusterInit () {
5761 defaultEnv := getDefaultEnv (_clusterCommandType )
5862
5963 _upCmd .Flags ().SortFlags = false
6064 addClusterConfigFlag (_upCmd )
61- _upCmd .Flags ().StringVarP (& _flagClusterEnv , "env" , "e" , defaultEnv , "environment to configure" )
65+ addAWSCredentials (_upCmd )
66+ _upCmd .Flags ().StringVar (& _flagClusterAWSAccessKeyID , "cluster-aws-key" , "" , "aws access key id to be used by the cluster" )
67+ _upCmd .Flags ().StringVar (& _flagClusterAWSSecretAccessKey , "cluster-aws-secret" , "" , "aws secret access key to be used by the cluster" )
68+ _upCmd .Flags ().StringVarP (& _flagClusterEnv , "env" , "e" , defaultEnv , "environment to create" )
6269 _upCmd .Flags ().BoolVarP (& _flagClusterDisallowPrompt , "yes" , "y" , false , "skip prompts" )
6370 _clusterCmd .AddCommand (_upCmd )
6471
6572 _infoCmd .Flags ().SortFlags = false
6673 addClusterConfigFlag (_infoCmd )
67- _infoCmd .Flags ().StringVarP (& _flagClusterEnv , "env" , "e" , defaultEnv , "environment to configure" )
74+ addAWSCredentials (_infoCmd )
75+ _infoCmd .Flags ().StringVarP (& _flagClusterEnv , "env" , "e" , defaultEnv , "environment to update" )
6876 _infoCmd .Flags ().BoolVarP (& _flagClusterInfoDebug , "debug" , "d" , false , "save the current cluster state to a file" )
6977 _infoCmd .Flags ().BoolVarP (& _flagClusterDisallowPrompt , "yes" , "y" , false , "skip prompts" )
7078 _clusterCmd .AddCommand (_infoCmd )
7179
7280 _configureCmd .Flags ().SortFlags = false
7381 addClusterConfigFlag (_configureCmd )
74- _configureCmd .Flags ().StringVarP (& _flagClusterEnv , "env" , "e" , defaultEnv , "environment to configure" )
82+ addAWSCredentials (_configureCmd )
83+ _configureCmd .Flags ().StringVarP (& _flagClusterEnv , "env" , "e" , defaultEnv , "environment to update" )
7584 _configureCmd .Flags ().BoolVarP (& _flagClusterDisallowPrompt , "yes" , "y" , false , "skip prompts" )
7685 _clusterCmd .AddCommand (_configureCmd )
7786
7887 _downCmd .Flags ().SortFlags = false
7988 addClusterConfigFlag (_downCmd )
89+ addAWSCredentials (_downCmd )
8090 _downCmd .Flags ().BoolVarP (& _flagClusterDisallowPrompt , "yes" , "y" , false , "skip prompts" )
8191 _clusterCmd .AddCommand (_downCmd )
8292}
@@ -86,6 +96,11 @@ func addClusterConfigFlag(cmd *cobra.Command) {
8696 cmd .Flags ().SetAnnotation ("config" , cobra .BashCompFilenameExt , _configFileExts )
8797}
8898
99+ func addAWSCredentials (cmd * cobra.Command ) {
100+ cmd .Flags ().StringVar (& _flagAWSAccessKeyID , "aws-key" , "" , "aws access key id" )
101+ cmd .Flags ().StringVar (& _flagAWSSecretAccessKey , "aws-secret" , "" , "aws secret access key" )
102+ }
103+
89104var _clusterCmd = & cobra.Command {
90105 Use : "cluster" ,
91106 Short : "manage a cluster" ,
@@ -110,7 +125,14 @@ var _upCmd = &cobra.Command{
110125 promptForEmail ()
111126 }
112127
113- awsCreds , err := getAWSCredentials (_flagClusterConfig , _flagClusterEnv , _flagClusterDisallowPrompt )
128+ if _flagClusterConfig != "" {
129+ // Deprecation: specifying aws creds in cluster configuration is no longer supported
130+ if err := detectAWSCredsInConfigFile (cmd .Use , _flagClusterConfig ); err != nil {
131+ exit .Error (err )
132+ }
133+ }
134+
135+ awsCreds , err := awsCredentialsForCreatingCluster (_flagClusterDisallowPrompt )
114136 if err != nil {
115137 exit .Error (err )
116138 }
@@ -254,15 +276,17 @@ var _upCmd = &cobra.Command{
254276 Name : _flagClusterEnv ,
255277 Provider : types .AWSProviderType ,
256278 OperatorEndpoint : pointer .String ("https://" + * loadBalancer .DNSName ),
257- AWSAccessKeyID : pointer .String (awsCreds .CortexAWSAccessKeyID ),
258- AWSSecretAccessKey : pointer .String (awsCreds .CortexAWSSecretAccessKey ),
279+ AWSAccessKeyID : pointer .String (awsCreds .ClusterAWSAccessKeyID ),
280+ AWSSecretAccessKey : pointer .String (awsCreds .ClusterAWSSecretAccessKey ),
259281 }
260282
261283 err = addEnvToCLIConfig (newEnvironment )
262284 if err != nil {
263285 exit .Error (errors .Append (err , fmt .Sprintf ("unable to configure cli environment; you can attempt to resolve this issue and configure your CLI environment by running `cortex cluster info --env %s`" , _flagClusterEnv )))
264286 }
265287
288+ cacheAWSCredentials (awsCreds , accessConfig )
289+
266290 fmt .Printf (console .Bold ("\n an environment named \" %s\" has been configured for this cluster; append `--env %s` to cortex commands to connect to it (e.g. `cortex deploy --env %s`), or set it as your default with `cortex env default %s`\n " ), _flagClusterEnv , _flagClusterEnv , _flagClusterEnv , _flagClusterEnv )
267291 },
268292}
@@ -282,12 +306,19 @@ var _configureCmd = &cobra.Command{
282306 exit .Error (err )
283307 }
284308
285- awsCreds , err := getAWSCredentials (_flagClusterConfig , _flagClusterEnv , _flagClusterDisallowPrompt )
309+ if _flagClusterConfig != "" {
310+ // Deprecation: specifying aws creds in cluster configuration is no longer supported
311+ if err := detectAWSCredsInConfigFile (cmd .Use , _flagClusterConfig ); err != nil {
312+ exit .Error (err )
313+ }
314+ }
315+
316+ accessConfig , err := getClusterAccessConfig (_flagClusterDisallowPrompt )
286317 if err != nil {
287318 exit .Error (err )
288319 }
289320
290- accessConfig , err := getClusterAccessConfig ( _flagClusterDisallowPrompt )
321+ awsCreds , err := awsCredentialsForManagingCluster ( * accessConfig , _flagClusterDisallowPrompt )
291322 if err != nil {
292323 exit .Error (err )
293324 }
@@ -324,6 +355,8 @@ var _configureCmd = &cobra.Command{
324355 fmt .Println (helpStr )
325356 exit .Error (ErrorClusterConfigure (out + helpStr ))
326357 }
358+
359+ cacheAWSCredentials (awsCreds , * accessConfig )
327360 },
328361}
329362
@@ -341,12 +374,19 @@ var _infoCmd = &cobra.Command{
341374 exit .Error (err )
342375 }
343376
344- awsCreds , err := getAWSCredentials (_flagClusterConfig , _flagClusterEnv , _flagClusterDisallowPrompt )
377+ if _flagClusterConfig != "" {
378+ // Deprecation: specifying aws creds in cluster configuration is no longer supported
379+ if err := detectAWSCredsInConfigFile (cmd .Use , _flagClusterConfig ); err != nil {
380+ exit .Error (err )
381+ }
382+ }
383+
384+ accessConfig , err := getClusterAccessConfig (_flagClusterDisallowPrompt )
345385 if err != nil {
346386 exit .Error (err )
347387 }
348388
349- accessConfig , err := getClusterAccessConfig ( _flagClusterDisallowPrompt )
389+ awsCreds , err := awsCredentialsForManagingCluster ( * accessConfig , _flagClusterDisallowPrompt )
350390 if err != nil {
351391 exit .Error (err )
352392 }
@@ -356,6 +396,8 @@ var _infoCmd = &cobra.Command{
356396 } else {
357397 cmdInfo (awsCreds , accessConfig , _flagClusterDisallowPrompt )
358398 }
399+
400+ cacheAWSCredentials (awsCreds , * accessConfig )
359401 },
360402}
361403
@@ -370,12 +412,19 @@ var _downCmd = &cobra.Command{
370412 exit .Error (err )
371413 }
372414
373- awsCreds , err := getAWSCredentials (_flagClusterConfig , _flagClusterEnv , _flagClusterDisallowPrompt )
415+ if _flagClusterConfig != "" {
416+ // Deprecation: specifying aws creds in cluster configuration is no longer supported
417+ if err := detectAWSCredsInConfigFile (cmd .Use , _flagClusterConfig ); err != nil {
418+ exit .Error (err )
419+ }
420+ }
421+
422+ accessConfig , err := getClusterAccessConfig (_flagClusterDisallowPrompt )
374423 if err != nil {
375424 exit .Error (err )
376425 }
377426
378- accessConfig , err := getClusterAccessConfig ( _flagClusterDisallowPrompt )
427+ awsCreds , err := awsCredentialsForManagingCluster ( * accessConfig , _flagClusterDisallowPrompt )
379428 if err != nil {
380429 exit .Error (err )
381430 }
@@ -480,6 +529,7 @@ var _downCmd = &cobra.Command{
480529
481530 cachedClusterConfigPath := cachedClusterConfigPath (* accessConfig .ClusterName , * accessConfig .Region )
482531 os .Remove (cachedClusterConfigPath )
532+ uncacheAWSCredentials (* accessConfig )
483533 },
484534}
485535
0 commit comments