Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions app/cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func NewRootCmd(l zerolog.Logger) *cobra.Command {
logger.Warn().Msg("API contacted in insecure mode")
}

authToken, isUserToken, err := LoadAuthToken(cmd)
authToken, isUserToken, err := loadAuthToken(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -205,27 +205,27 @@ func NewRootCmd(l zerolog.Logger) *cobra.Command {

rootCmd.PersistentFlags().StringVarP(&flagCfgFile, "config", "c", "", "Path to an existing config file (default is $HOME/.config/chainloop/config.toml)")

rootCmd.PersistentFlags().String(confOptions.controlplaneAPI.flagName, defaultCPAPI, fmt.Sprintf("URL for the Control Plane API ($%s)", calculateEnvVarName(confOptions.controlplaneAPI.viperKey)))
rootCmd.PersistentFlags().String(confOptions.controlplaneAPI.flagName, defaultCPAPI, fmt.Sprintf("URL for the Control Plane API ($%s)", CalculateEnvVarName(confOptions.controlplaneAPI.viperKey)))
cobra.CheckErr(viper.BindPFlag(confOptions.controlplaneAPI.viperKey, rootCmd.PersistentFlags().Lookup(confOptions.controlplaneAPI.flagName)))
cobra.CheckErr(viper.BindEnv(confOptions.controlplaneAPI.viperKey, calculateEnvVarName(confOptions.controlplaneAPI.viperKey)))
cobra.CheckErr(viper.BindEnv(confOptions.controlplaneAPI.viperKey, CalculateEnvVarName(confOptions.controlplaneAPI.viperKey)))

// Custom CAs for the control plane
rootCmd.PersistentFlags().String(confOptions.controlplaneCA.flagName, "", fmt.Sprintf("CUSTOM CA file for the Control Plane API (optional) ($%s)", calculateEnvVarName(confOptions.controlplaneCA.viperKey)))
rootCmd.PersistentFlags().String(confOptions.controlplaneCA.flagName, "", fmt.Sprintf("CUSTOM CA file for the Control Plane API (optional) ($%s)", CalculateEnvVarName(confOptions.controlplaneCA.viperKey)))
cobra.CheckErr(viper.BindPFlag(confOptions.controlplaneCA.viperKey, rootCmd.PersistentFlags().Lookup(confOptions.controlplaneCA.flagName)))
cobra.CheckErr(viper.BindEnv(confOptions.controlplaneCA.viperKey, calculateEnvVarName(confOptions.controlplaneCA.viperKey)))
cobra.CheckErr(viper.BindEnv(confOptions.controlplaneCA.viperKey, CalculateEnvVarName(confOptions.controlplaneCA.viperKey)))

rootCmd.PersistentFlags().String(confOptions.CASAPI.flagName, defaultCASAPI, fmt.Sprintf("URL for the Artifacts Content Addressable Storage API ($%s)", calculateEnvVarName(confOptions.CASAPI.viperKey)))
rootCmd.PersistentFlags().String(confOptions.CASAPI.flagName, defaultCASAPI, fmt.Sprintf("URL for the Artifacts Content Addressable Storage API ($%s)", CalculateEnvVarName(confOptions.CASAPI.viperKey)))
cobra.CheckErr(viper.BindPFlag(confOptions.CASAPI.viperKey, rootCmd.PersistentFlags().Lookup(confOptions.CASAPI.flagName)))
cobra.CheckErr(viper.BindEnv(confOptions.CASAPI.viperKey, calculateEnvVarName(confOptions.CASAPI.viperKey)))
cobra.CheckErr(viper.BindEnv(confOptions.CASAPI.viperKey, CalculateEnvVarName(confOptions.CASAPI.viperKey)))

// Custom CAs for the CAS
rootCmd.PersistentFlags().String(confOptions.CASCA.flagName, "", fmt.Sprintf("CUSTOM CA file for the Artifacts CAS API (optional) ($%s)", calculateEnvVarName(confOptions.CASCA.viperKey)))
rootCmd.PersistentFlags().String(confOptions.CASCA.flagName, "", fmt.Sprintf("CUSTOM CA file for the Artifacts CAS API (optional) ($%s)", CalculateEnvVarName(confOptions.CASCA.viperKey)))
cobra.CheckErr(viper.BindPFlag(confOptions.CASCA.viperKey, rootCmd.PersistentFlags().Lookup(confOptions.CASCA.flagName)))
cobra.CheckErr(viper.BindEnv(confOptions.CASCA.viperKey, calculateEnvVarName(confOptions.CASCA.viperKey)))
cobra.CheckErr(viper.BindEnv(confOptions.CASCA.viperKey, CalculateEnvVarName(confOptions.CASCA.viperKey)))

rootCmd.PersistentFlags().BoolP("insecure", "i", false, fmt.Sprintf("Skip TLS transport during connection to the control plane ($%s)", calculateEnvVarName(confOptions.insecure.viperKey)))
rootCmd.PersistentFlags().BoolP("insecure", "i", false, fmt.Sprintf("Skip TLS transport during connection to the control plane ($%s)", CalculateEnvVarName(confOptions.insecure.viperKey)))
cobra.CheckErr(viper.BindPFlag(confOptions.insecure.viperKey, rootCmd.PersistentFlags().Lookup("insecure")))
cobra.CheckErr(viper.BindEnv(confOptions.insecure.viperKey, calculateEnvVarName(confOptions.insecure.viperKey)))
cobra.CheckErr(viper.BindEnv(confOptions.insecure.viperKey, CalculateEnvVarName(confOptions.insecure.viperKey)))

rootCmd.PersistentFlags().BoolVar(&flagDebug, "debug", false, "Enable debug/verbose logging mode")
rootCmd.PersistentFlags().StringVarP(&flagOutputFormat, "output", "o", "table", "Output format, valid options are json and table")
Expand Down Expand Up @@ -261,7 +261,7 @@ func NewRootCmd(l zerolog.Logger) *cobra.Command {
// viper.AutomaticEnv()
// viper.SetEnvPrefix(envPrefix)
// viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_"))
func calculateEnvVarName(key string) string {
func CalculateEnvVarName(key string) string {
// replace - with _ and . with _
s := strings.ReplaceAll(key, "-", "_")
s = strings.ReplaceAll(s, ".", "_")
Expand Down Expand Up @@ -353,7 +353,7 @@ func cleanup(conn *grpc.ClientConn) error {
// 2.2 Load the token from the environment variable and from the auth login config file
// 2.3 if they both exist, we default to the user token
// 2.4 otherwise to the one that's set
func LoadAuthToken(cmd *cobra.Command) (string, bool, error) {
func loadAuthToken(cmd *cobra.Command) (string, bool, error) {
// Load the APIToken from the env variable
apiTokenFromVar := os.Getenv(tokenEnvVarName)

Expand Down
Loading