Skip to content

Commit

Permalink
Merge pull request uswitch#33 from uswitch/nil-secret
Browse files Browse the repository at this point in the history
Add check for nil secret
  • Loading branch information
waiariki-koia authored Dec 11, 2020
2 parents abf3365 + b27a6d0 commit 6a41f71
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions pkg/vault/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ func (m *DefaultManager) Save() error {

func (m *DefaultManager) renewSecret(leaseID string) error {
secret, err := m.client.Sys().Renew(leaseID, int(m.lease.Seconds()))
if err != nil {
if err != nil || secret == nil {
if err == nil {
err = fmt.Errorf("secret is nil")
}
log.Errorf("error renewing lease: %s", err)
fatalError := checkFatalError(err)
if fatalError != nil {
Expand Down Expand Up @@ -189,7 +192,10 @@ func (m *DefaultManager) renewCertificate() error {

func renewAuth(client *api.Client, renew int) error {
secret, err := client.Auth().Token().RenewSelf(renew)
if err != nil {
if err != nil || secret == nil {
if err == nil {
err = fmt.Errorf("secret is nil")
}
log.Errorf("error renewing token: %s", err)
fatalError := checkFatalError(err)
if fatalError != nil {
Expand Down
10 changes: 8 additions & 2 deletions pkg/vault/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ func (c *VaultSecretsProvider) newCertificate() (*Certificate, error) {
}

secret, err := c.client.Logical().Write(c.path, params)
if err != nil {
if err != nil || secret == nil {
if err == nil {
return nil, fmt.Errorf("secret is nil")
}
return nil, err
}

Expand All @@ -73,7 +76,10 @@ func (c *VaultSecretsProvider) newCertificate() (*Certificate, error) {

func (c *VaultSecretsProvider) newCredentials() (*Credentials, error) {
secret, err := c.client.Logical().Read(c.path)
if err != nil {
if err != nil || secret == nil {
if err == nil {
return nil, fmt.Errorf("secret is nil")
}
return nil, err
}

Expand Down

0 comments on commit 6a41f71

Please sign in to comment.