Skip to content

Commit

Permalink
breaking change: #233 return error struct to avoid panic at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
missedone committed Sep 15, 2023
1 parent 4e88645 commit eb3c196
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions providers/appconfig/appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ type AppConfig struct {
}

// Provider returns an AWS AppConfig provider.
func Provider(cfg Config) *AppConfig {
func Provider(cfg Config) (*AppConfig, error) {
c, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
return nil
return nil, err
}

if cfg.AWSRegion != "" {
Expand All @@ -89,7 +89,7 @@ func Provider(cfg Config) *AppConfig {
}
client := appconfig.NewFromConfig(c)

return &AppConfig{client: client, config: cfg}
return &AppConfig{client: client, config: cfg}, nil
}

// ProviderWithClient returns an AWS AppConfig provider
Expand Down
6 changes: 3 additions & 3 deletions providers/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ type Consul struct {
}

// Provider returns an instance of the Consul provider.
func Provider(cfg Config) *Consul {
func Provider(cfg Config) (*Consul, error) {
c, err := api.NewClient(cfg.Cfg)
if err != nil {
return nil
return nil, err
}

return &Consul{client: c, cfg: cfg}
return &Consul{client: c, cfg: cfg}, nil
}

// ReadBytes is not supported by the Consul provider.
Expand Down
6 changes: 3 additions & 3 deletions providers/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ type Etcd struct {
}

// Provider returns a provider that takes etcd config.
func Provider(cfg Config) *Etcd {
func Provider(cfg Config) (*Etcd, error) {
eCfg := clientv3.Config{
Endpoints: cfg.Endpoints,
DialTimeout: cfg.DialTimeout,
}

c, err := clientv3.New(eCfg)
if err != nil {
return nil
return nil, err
}

return &Etcd{client: c, cfg: cfg}
return &Etcd{client: c, cfg: cfg}, nil
}

// ReadBytes is not supported by etcd provider.
Expand Down
6 changes: 3 additions & 3 deletions providers/parameterstore/parameterstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ type ParameterStore[T Input] struct {
// - AWS_ACCESS_KEY_ID
// - AWS_SECRET_ACCESS_KEY
// - AWS_SESSION_TOKEN
func Provider[T Input](config Config[T]) *ParameterStore[T] {
func Provider[T Input](config Config[T]) (*ParameterStore[T], error) {
c, err := awsconfig.LoadDefaultConfig(context.TODO())
if err != nil {
return nil
return nil, err
}
return ProviderWithClient[T](config, ssm.NewFromConfig(c))
return ProviderWithClient[T](config, ssm.NewFromConfig(c)), nil
}

// ProviderWithClient returns a ParameterStore provider
Expand Down
8 changes: 4 additions & 4 deletions providers/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ type Vault struct {
}

// Provider returns a provider that takes a Vault config.
func Provider(cfg Config) *Vault {
func Provider(cfg Config) (*Vault, error) {
httpClient := &http.Client{Timeout: cfg.Timeout, Transport: cfg.Transport}
client, err := api.NewClient(&api.Config{Address: cfg.Address, HttpClient: httpClient})
if err != nil {
return nil
return nil, err
}
if cfg.AuthMethod != nil {
if _, err := client.Auth().Login(context.Background(), cfg.AuthMethod); err != nil {
return nil
return nil, err
}
} else {
client.SetToken(cfg.Token)
}

return &Vault{client: client, cfg: cfg}
return &Vault{client: client, cfg: cfg}, nil
}

// ReadBytes is not supported by the vault provider.
Expand Down

0 comments on commit eb3c196

Please sign in to comment.