1
0
Fork 0

Fix infisical opts

main v0.21.1
Jordan Hotmann 2024-01-04 09:55:57 -07:00
parent f281e82499
commit 2369c1d5c9
No known key found for this signature in database
GPG Key ID: 01B504170C2A2EA3
2 changed files with 12 additions and 8 deletions

View File

@ -51,7 +51,6 @@ type HatsConfig struct {
ConfigDir string `config:"CONFIG_DIR" default:"/config"` ConfigDir string `config:"CONFIG_DIR" default:"/config"`
infisicalClient *infisical.InfisicalClient infisicalClient *infisical.InfisicalClient
infisicalRetrievalOpts *infisical.RetrieveSecretOptions
} }
func New() (*HatsConfig, error) { func New() (*HatsConfig, error) {
@ -67,9 +66,7 @@ func New() (*HatsConfig, error) {
return cfg, fmt.Errorf("error logging in to Infisical: %w", err) return cfg, fmt.Errorf("error logging in to Infisical: %w", err)
} }
secrets, err := cfg.infisicalClient.ListSecrets( secrets, err := cfg.infisicalClient.ListSecrets(cfg.InfisicalProjectID, cfg.InfisicalEnvironment)
infisical.WithWorkspaceID(cfg.InfisicalProjectID),
infisical.WithEnvironment(cfg.InfisicalEnvironment))
if err != nil { if err != nil {
return cfg, fmt.Errorf("error getting Infisical secrets: %w", err) 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() { if c.InfisicalConfigured() {
secret, _ := c.infisicalClient.GetSecret(name, c.infisicalRetrievalOpts) secret, _ := c.infisicalClient.GetSecret(name, c.InfisicalProjectID, c.InfisicalEnvironment)
if secret.SecretValue != "" { if secret.SecretValue != "" {
returnValue = secret.SecretValue returnValue = secret.SecretValue
} }

View File

@ -70,8 +70,9 @@ func (c *InfisicalClient) CheckToken() error {
return nil return nil
} }
func (c *InfisicalClient) ListSecrets(optFuncs ...RetrieveSecretOptionFunc) ([]Secret, error) { func (c *InfisicalClient) ListSecrets(workspaceId string, environment string, optFuncs ...RetrieveSecretOptionFunc) ([]Secret, error) {
opts := DefaultRetrieveSecretOptions() opts := DefaultRetrieveSecretOptions()
optFuncs = append(optFuncs, WithWorkspaceID(workspaceId), WithEnvironment(environment))
for _, f := range optFuncs { for _, f := range optFuncs {
f(opts) f(opts)
} }
@ -96,7 +97,13 @@ func (c *InfisicalClient) ListSecrets(optFuncs ...RetrieveSecretOptionFunc) ([]S
return result.Secrets, nil 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() err := c.CheckToken()
if err != nil { if err != nil {
return Secret{}, err return Secret{}, err