mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-04-24 02:59:55 -05:00
fix: WithToken should override environment variable (#2706)
This commit is contained in:
@@ -14,7 +14,7 @@ repos:
|
||||
- id: check-yaml
|
||||
exclude: ^examples/
|
||||
- repo: https://github.com/golangci/golangci-lint
|
||||
rev: v2.4.0
|
||||
rev: v2.5.0
|
||||
hooks:
|
||||
- id: golangci-lint
|
||||
args: ["--config=.golangci.yml"]
|
||||
|
||||
@@ -114,7 +114,7 @@ func defaultClientOpts(token *string, cf *client.ClientConfigFile) *ClientOpts {
|
||||
if token != nil {
|
||||
cf.Token = *token
|
||||
}
|
||||
clientConfig, err = loader.GetClientConfigFromConfigFile(cf)
|
||||
clientConfig, err = loader.GetClientConfigFromConfigFile(token, cf)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -33,7 +33,7 @@ func (c *ConfigLoader) LoadClientConfig(token *string) (res *client.ClientConfig
|
||||
cf.Token = *token
|
||||
}
|
||||
|
||||
return GetClientConfigFromConfigFile(cf)
|
||||
return GetClientConfigFromConfigFile(token, cf)
|
||||
}
|
||||
|
||||
// LoadClientConfigFile loads the worker config file via viper
|
||||
@@ -46,7 +46,7 @@ func LoadClientConfigFile(files ...[]byte) (*client.ClientConfigFile, error) {
|
||||
return configFile, err
|
||||
}
|
||||
|
||||
func GetClientConfigFromConfigFile(cf *client.ClientConfigFile) (res *client.ClientConfig, err error) {
|
||||
func GetClientConfigFromConfigFile(tokenOverride *string, cf *client.ClientConfigFile) (res *client.ClientConfig, err error) {
|
||||
f := client.BindAllEnv
|
||||
|
||||
_, err = loaderutils.LoadConfigFromViper(f, cf)
|
||||
@@ -55,6 +55,10 @@ func GetClientConfigFromConfigFile(cf *client.ClientConfigFile) (res *client.Cli
|
||||
return nil, fmt.Errorf("could not load config from viper: %w", err)
|
||||
}
|
||||
|
||||
if tokenOverride != nil {
|
||||
cf.Token = *tokenOverride
|
||||
}
|
||||
|
||||
// if token is empty, throw an error
|
||||
if cf.Token == "" {
|
||||
return nil, fmt.Errorf("API token is required. Set it via the HATCHET_CLIENT_TOKEN environment variable")
|
||||
|
||||
Reference in New Issue
Block a user