Skip to content

Commit

Permalink
Merge pull request #120 from sapcc/vault-remove-stat
Browse files Browse the repository at this point in the history
Remove useless stat call
  • Loading branch information
majewsky committed Apr 12, 2024
2 parents 95b87ec + a1688ed commit b302448
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions vault/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,15 @@ func CreateClient() (*api.Client, error) {
return nil, fmt.Errorf("while fetching home directory: %w", err)
}
vaultTokenFile := homeDir + "/.vault-token"
if _, err := os.Stat(vaultTokenFile); err == nil {
bytes, err := os.ReadFile(vaultTokenFile)
if err != nil {
return nil, fmt.Errorf("failed reading %s: %w", vaultTokenFile, err)
}
client.SetToken(strings.TrimSpace(string(bytes)))
bytes, err := os.ReadFile(vaultTokenFile)
if errors.Is(err, os.ErrNotExist) {
return nil, errors.New("Some environment variables are missing! For pipelines makes sure VAULT_ROLE_ID and VAULT_SECRET_ID are set and for manual invocations make sure VAULT_TOKEN is set or you previously logged into vault cli. DO NOT use the variables the other way around!") //nolint:stylecheck // we want it like this
} else if err != nil {
return nil, fmt.Errorf("failed reading %s: %w", vaultTokenFile, err)
}
client.SetToken(strings.TrimSpace(string(bytes)))
}
}

if client.Token() == "" {
return nil, errors.New("Some environment variables are missing! For pipelines makes sure VAULT_ROLE_ID and VAULT_SECRET_ID are set and for manual invocations make sure VAULT_TOKEN is set or you previously logged into vault cli. DO NOT use the variables the other way around!") //nolint:stylecheck // we want it like this
}

return client, nil
}

0 comments on commit b302448

Please sign in to comment.