diff --git a/internal/clierrors/missing_credentials.go b/internal/clierrors/missing_credentials.go index 2e579a6b..2b077517 100644 --- a/internal/clierrors/missing_credentials.go +++ b/internal/clierrors/missing_credentials.go @@ -5,7 +5,8 @@ import "fmt" var _ ClientError = MissingCredentialsError{} type MissingCredentialsError struct { - ConfigFile string + ConfigFile string + ServiceName string } func (err MissingCredentialsError) ErrorCode() int { @@ -13,5 +14,5 @@ func (err MissingCredentialsError) ErrorCode() int { } func (err MissingCredentialsError) Error() string { - return fmt.Sprintf("user credentials not found, these must be set in config file (%s) or via environment variables or in a keyring (upctl)", err.ConfigFile) + return fmt.Sprintf("user credentials not found, these must be set in config file (%s) or via environment variables or in a keyring (%s)", err.ConfigFile, err.ServiceName) } diff --git a/internal/config/config.go b/internal/config/config.go index a3f88d95..614793fb 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -34,6 +34,9 @@ const ( // env vars custom prefix envPrefix = "UPCLOUD" + + // serviceName is the name of the service + serviceName = "upctl" ) var ( @@ -77,7 +80,7 @@ func (s *Config) Load() error { v.SetEnvPrefix(envPrefix) v.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_")) v.AutomaticEnv() - v.SetConfigName("upctl") + v.SetConfigName(serviceName) v.SetConfigType("yaml") configFile := s.GlobalFlags.ConfigFile @@ -97,7 +100,7 @@ func (s *Config) Load() error { } if v.GetString("username") != "" && v.GetString("password") == "" { - password, err := keyring.Get("upctl", v.GetString("username")) + password, err := keyring.Get(serviceName, v.GetString("username")) if err == nil { v.MergeConfigMap(map[string]interface{}{"password": password}) } @@ -203,11 +206,11 @@ func (s *Config) CreateService() (internal.AllServices, error) { if s.GetString("config") != "" { configDetails = fmt.Sprintf("used %s", s.GetString("config")) } - return nil, clierrors.MissingCredentialsError{ConfigFile: configDetails} + return nil, clierrors.MissingCredentialsError{ConfigFile: configDetails, ServiceName: serviceName} } client := client.New(username, password, client.WithTimeout(s.ClientTimeout())) - client.UserAgent = fmt.Sprintf("upctl/%s", GetVersion()) + client.UserAgent = fmt.Sprintf("%s/%s", serviceName, GetVersion()) svc := service.New(client) return svc, nil