parent
f281e82499
commit
2369c1d5c9
|
@ -50,8 +50,7 @@ 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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue