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

@ -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
}

View File

@ -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