-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
150 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"github.com/kyma-project/cli.v3/internal/clierror" | ||
"github.com/kyma-project/cli.v3/internal/cmdcommon" | ||
"github.com/kyma-project/cli.v3/internal/registry" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
type cfgConfig struct { | ||
*cmdcommon.KymaConfig | ||
cmdcommon.KubeClientConfig | ||
|
||
externalurl bool | ||
output string | ||
} | ||
|
||
func NewConfigCMD(kymaConfig *cmdcommon.KymaConfig) *cobra.Command { | ||
cfg := cfgConfig{ | ||
KymaConfig: kymaConfig, | ||
KubeClientConfig: cmdcommon.KubeClientConfig{}, | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "config", | ||
Short: "Saves Kyma registry dockerconfig to a file", | ||
Long: "Use this command to save Kyma registry dockerconfig to a file", | ||
PreRun: func(_ *cobra.Command, _ []string) { | ||
clierror.Check(cfg.KubeClientConfig.Complete()) | ||
}, | ||
Run: func(_ *cobra.Command, _ []string) { | ||
clierror.Check(runConfig(&cfg)) | ||
}, | ||
} | ||
|
||
cfg.KubeClientConfig.AddFlag(cmd) | ||
cmd.Flags().BoolVar(&cfg.externalurl, "externalurl", false, "External URL for the Kyma registry.") | ||
cmd.Flags().StringVar(&cfg.output, "output", "", "Path where the output file should be saved to. NOTE: docker expects the file to be named `config.json`.") | ||
|
||
return cmd | ||
} | ||
|
||
func runConfig(cfg *cfgConfig) clierror.Error { | ||
registryConfig, err := registry.GetExternalConfig(cfg.Ctx, cfg.KubeClient) | ||
if err != nil { | ||
return clierror.WrapE(err, clierror.New("failed to load in-cluster registry configuration")) | ||
} | ||
|
||
if cfg.externalurl && cfg.output == "" { | ||
fmt.Print(registryConfig.SecretData.PushRegAddr) | ||
return nil | ||
} | ||
|
||
if cfg.externalurl && cfg.output != "" { | ||
writeErr := os.WriteFile(cfg.output, []byte(registryConfig.SecretData.PushRegAddr), os.ModePerm) | ||
if writeErr != nil { | ||
return clierror.New("failed to write docker config to file") | ||
} | ||
return nil | ||
} | ||
|
||
if cfg.output == "" { | ||
fmt.Print(registryConfig.SecretData.DockerConfigJSON) | ||
} else { | ||
writeErr := os.WriteFile(cfg.output, []byte(registryConfig.SecretData.DockerConfigJSON), os.ModePerm) | ||
if writeErr != nil { | ||
return clierror.New("failed to write docker config to file") | ||
} | ||
fmt.Print("Docker config saved to ", cfg.output) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package registry | ||
|
||
import ( | ||
"github.com/kyma-project/cli.v3/internal/cmd/alpha/registry/config" | ||
"github.com/kyma-project/cli.v3/internal/cmdcommon" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewRegistryCMD(kymaConfig *cmdcommon.KymaConfig) *cobra.Command { | ||
|
||
cmd := &cobra.Command{ | ||
Use: "registry", | ||
Short: "Set of commands for Kyma registry", | ||
Long: `Use this command manage resources related to Kyma registry`, | ||
} | ||
|
||
cmd.AddCommand(config.NewConfigCMD(kymaConfig)) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters