@@ -55,6 +55,7 @@ var cloudLoginCmd = &cobra.Command{
5555 kubeConfigPath , _ := cmd .Flags ().GetString ("kubeconfigpath" )
5656
5757 gcpKeyJson , _ := cmd .Flags ().GetString ("gcp-key-json" )
58+ gcpKeyFilePath , _ := cmd .Flags ().GetString ("gcp-key-path" )
5859 gcpProjectName , _ := cmd .Flags ().GetString ("gcp-project-name" )
5960 gcpComputeRegion , _ := cmd .Flags ().GetString ("gcp-compute-region" )
6061 gcpComputeZone , _ := cmd .Flags ().GetString ("gcp-compute-zone" )
@@ -81,9 +82,15 @@ var cloudLoginCmd = &cobra.Command{
8182 if len (kubeConfig ) == 0 {
8283 kubeConfig = os .Getenv ("KUBECTL_CONFIG" )
8384 }
85+ if len (kubeConfigPath ) == 0 {
86+ kubeConfigPath = os .Getenv ("KUBECONFIG" )
87+ }
8488 if len (gcpKeyJson ) == 0 {
8589 gcpKeyJson = os .Getenv ("GCLOUD_KEY_JSON" )
8690 }
91+ if len (gcpKeyFilePath ) == 0 {
92+ gcpKeyFilePath = os .Getenv ("GOOGLE_APPLICATION_CREDENTIALS" )
93+ }
8794 if len (gcpProjectName ) == 0 {
8895 gcpProjectName = os .Getenv ("GCLOUD_PROJECT_NAME" )
8996 }
@@ -142,6 +149,21 @@ var cloudLoginCmd = &cobra.Command{
142149 log .Fatal ("Error writing kubeconfig:" , err )
143150 }
144151
152+ // Save key
153+ homedir , _ := os .UserHomeDir ()
154+ if len (gcpKeyFilePath ) == 0 {
155+ gcpKeyFilePath = fmt .Sprintf ("%s/%s" , homedir , "gcp-service-key.json" )
156+ }
157+ f , err := os .Create (gcpKeyFilePath )
158+ if err != nil {
159+ log .Fatal ("Error creating gcp service key file:" , err )
160+ }
161+ _ , err = io .WriteString (f , gcpKeyJson )
162+ // err := os.WriteFile(gcpKeyFilePath, gcpKeyJson, 0700)
163+ if err != nil {
164+ log .Fatal ("Error writing to gcp service key file:" , err )
165+ }
166+
145167 } else if len (gcpKeyJson ) > 0 {
146168
147169 // GCP gcloud login
@@ -156,7 +178,9 @@ var cloudLoginCmd = &cobra.Command{
156178
157179 // Save key
158180 homedir , _ := os .UserHomeDir ()
159- gcpKeyFilePath := fmt .Sprintf ("%s/%s" , homedir , "gcp-service-key.json" )
181+ if len (gcpKeyFilePath ) == 0 {
182+ gcpKeyFilePath = fmt .Sprintf ("%s/%s" , homedir , "gcp-service-key.json" )
183+ }
160184 f , err := os .Create (gcpKeyFilePath )
161185 if err != nil {
162186 log .Fatal ("Error creating gcp service key file:" , err )
@@ -239,6 +263,7 @@ func init() {
239263 cloudLoginCmd .Flags ().String ("kubeconfig" , "" , "Kubernetes config content (plaintext, base64 encoded)" )
240264 cloudLoginCmd .Flags ().String ("kubeconfigpath" , "~/.kube/config" , "Kubernetes config path" )
241265 cloudLoginCmd .Flags ().String ("gcp-key-json" , "" , "Google Cloud service account key (plaintext, json)" )
266+ cloudLoginCmd .Flags ().String ("gcp-key-path" , "" , "Location of Google Cloud service account key file" )
242267 cloudLoginCmd .Flags ().String ("gcp-project-name" , "" , "GCP project name (project id)" )
243268 cloudLoginCmd .Flags ().String ("gcp-compute-region" , "" , "GCP compute region" )
244269 cloudLoginCmd .Flags ().String ("gcp-compute-zone" , "" , "GCP compute zone" )
0 commit comments