From 2369c1d5c96d1851569845d77d830f372ba02b21 Mon Sep 17 00:00:00 2001 From: Jordan Hotmann Date: Thu, 4 Jan 2024 09:55:57 -0700 Subject: [PATCH] Fix infisical opts --- pkg/config/config.go | 9 +++------ pkg/infisical/api.go | 11 +++++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 595e027..ad0ab90 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -50,8 +50,7 @@ type HatsConfig struct { ConfigDir string `config:"CONFIG_DIR" default:"/config"` - infisicalClient *infisical.InfisicalClient - infisicalRetrievalOpts *infisical.RetrieveSecretOptions + infisicalClient *infisical.InfisicalClient } func New() (*HatsConfig, error) { @@ -67,9 +66,7 @@ func New() (*HatsConfig, error) { return cfg, fmt.Errorf("error logging in to Infisical: %w", err) } - secrets, err := cfg.infisicalClient.ListSecrets( - infisical.WithWorkspaceID(cfg.InfisicalProjectID), - infisical.WithEnvironment(cfg.InfisicalEnvironment)) + secrets, err := cfg.infisicalClient.ListSecrets(cfg.InfisicalProjectID, cfg.InfisicalEnvironment) if err != nil { return cfg, fmt.Errorf("error getting Infisical secrets: %w", err) } @@ -145,7 +142,7 @@ func (c *HatsConfig) GetCustomSetting(name string, defaultValue string) string { } if c.InfisicalConfigured() { - secret, _ := c.infisicalClient.GetSecret(name, c.infisicalRetrievalOpts) + secret, _ := c.infisicalClient.GetSecret(name, c.InfisicalProjectID, c.InfisicalEnvironment) if secret.SecretValue != "" { returnValue = secret.SecretValue } diff --git a/pkg/infisical/api.go b/pkg/infisical/api.go index c9ff9e2..b6da1d9 100644 --- a/pkg/infisical/api.go +++ b/pkg/infisical/api.go @@ -70,8 +70,9 @@ func (c *InfisicalClient) CheckToken() error { return nil } -func (c *InfisicalClient) ListSecrets(optFuncs ...RetrieveSecretOptionFunc) ([]Secret, error) { +func (c *InfisicalClient) ListSecrets(workspaceId string, environment string, optFuncs ...RetrieveSecretOptionFunc) ([]Secret, error) { opts := DefaultRetrieveSecretOptions() + optFuncs = append(optFuncs, WithWorkspaceID(workspaceId), WithEnvironment(environment)) for _, f := range optFuncs { f(opts) } @@ -96,7 +97,13 @@ func (c *InfisicalClient) ListSecrets(optFuncs ...RetrieveSecretOptionFunc) ([]S return result.Secrets, nil } -func (c *InfisicalClient) GetSecret(name string, opts *RetrieveSecretOptions) (Secret, error) { +func (c *InfisicalClient) GetSecret(name string, workspaceId string, environment string, optFuncs ...RetrieveSecretOptionFunc) (Secret, error) { + opts := DefaultRetrieveSecretOptions() + optFuncs = append(optFuncs, WithWorkspaceID(workspaceId), WithEnvironment(environment)) + for _, f := range optFuncs { + f(opts) + } + err := c.CheckToken() if err != nil { return Secret{}, err