Skip to content

Commit

Permalink
Fixup comments in providers (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
neelayu committed Oct 4, 2022
1 parent 3e03354 commit d74a0d5
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion providers/confmap/confmap.go
Expand Up @@ -26,7 +26,7 @@ func Provider(mp map[string]interface{}, delim string) *Confmap {
return &Confmap{mp: cp}
}

// ReadBytes is not supported by the env provider.
// ReadBytes is not supported by the confmap provider.
func (e *Confmap) ReadBytes() ([]byte, error) {
return nil, errors.New("confmap provider does not support this method")
}
Expand Down
2 changes: 1 addition & 1 deletion providers/consul/consul.go
Expand Up @@ -144,7 +144,7 @@ func (c *Consul) Watch(cb func(event interface{}, err error)) error {
return err
}

plan.Handler = func(idx uint64, val interface{}) {
plan.Handler = func(_ uint64, val interface{}) {
cb(val, nil)
}

Expand Down
2 changes: 2 additions & 0 deletions providers/etcd/etcd.go
Expand Up @@ -49,10 +49,12 @@ func Provider(cfg Config) *Etcd {
return &Etcd{client: c, cfg: cfg}
}

// ReadBytes is not supported by etcd provider.
func (e *Etcd) ReadBytes() ([]byte, error) {
return nil, errors.New("etcd provider does not support this method")
}

// Read returns a nested config map.
func (e *Etcd) Read() (map[string]interface{}, error) {
ctx, cancel := context.WithTimeout(context.Background(), e.cfg.DialTimeout)
defer cancel()
Expand Down
5 changes: 3 additions & 2 deletions providers/posflag/posflag.go
Expand Up @@ -6,9 +6,10 @@ package posflag
import (
"errors"

"github.com/spf13/pflag"

"github.com/knadh/koanf"
"github.com/knadh/koanf/maps"
"github.com/spf13/pflag"
)

// Posflag implements a pflag command line provider.
Expand Down Expand Up @@ -126,7 +127,7 @@ func (p *Posflag) Read() (map[string]interface{}, error) {
return maps.Unflatten(mp, p.delim), nil
}

// ReadBytes is not supported by the env koanf.
// ReadBytes is not supported by the pflag provider.
func (p *Posflag) ReadBytes() ([]byte, error) {
return nil, errors.New("pflag provider does not support this method")
}
Expand Down
6 changes: 3 additions & 3 deletions providers/rawbytes/rawbytes.go
Expand Up @@ -20,12 +20,12 @@ func Provider(b []byte) *RawBytes {
return r
}

// ReadBytes is not supported by the env provider.
// ReadBytes returns the raw bytes for parsing.
func (r *RawBytes) ReadBytes() ([]byte, error) {
return r.b, nil
}

// Read returns the raw bytes for parsing.
// Read is not supported by rawbytes provider.
func (r *RawBytes) Read() (map[string]interface{}, error) {
return nil, errors.New("buf provider does not support this method")
return nil, errors.New("rawbytes provider does not support this method")
}
2 changes: 1 addition & 1 deletion providers/s3/s3.go
Expand Up @@ -64,7 +64,7 @@ func (r *S3) ReadBytes() ([]byte, error) {
return data, nil
}

// Read returns the raw bytes for parsing.
// Read is not supported for s3 provider.
func (r *S3) Read() (map[string]interface{}, error) {
return nil, errors.New("s3 provider does not support this method")
}
3 changes: 2 additions & 1 deletion providers/structs/structs.go
Expand Up @@ -6,6 +6,7 @@ import (
"errors"

"github.com/fatih/structs"

"github.com/knadh/koanf/maps"
)

Expand All @@ -16,7 +17,7 @@ type Structs struct {
delim string
}

// Provider returns a provider that takes a takes a struct and a struct tag
// Provider returns a provider that takes a takes a struct and a struct tag
// and uses structs to parse and provide it to koanf.
func Provider(s interface{}, tag string) *Structs {
return &Structs{s: s, tag: tag}
Expand Down
4 changes: 4 additions & 0 deletions providers/vault/vault.go
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/hashicorp/vault/api"

"github.com/knadh/koanf/maps"
)

Expand Down Expand Up @@ -40,6 +41,7 @@ type Vault struct {
cfg Config
}

// Provider returns a provider that takes a Vault config.
func Provider(cfg Config) *Vault {
httpClient := &http.Client{Timeout: cfg.Timeout}
client, err := api.NewClient(&api.Config{Address: cfg.Address, HttpClient: httpClient})
Expand All @@ -51,10 +53,12 @@ func Provider(cfg Config) *Vault {
return &Vault{client: client, cfg: cfg}
}

// ReadBytes is not supported by the vault provider.
func (r *Vault) ReadBytes() ([]byte, error) {
return nil, errors.New("vault provider does not support this method")
}

// Read fetches the configuration from the source and returns a nested config map.
func (r *Vault) Read() (map[string]interface{}, error) {
secret, err := r.client.Logical().Read(r.cfg.Path)
if err != nil {
Expand Down

0 comments on commit d74a0d5

Please sign in to comment.