diff --git a/pkg/providers/onepassword/onepassword.go b/pkg/providers/onepassword/onepassword.go index 0ec9159..9996b8e 100644 --- a/pkg/providers/onepassword/onepassword.go +++ b/pkg/providers/onepassword/onepassword.go @@ -26,18 +26,21 @@ func (p *provider) GetString(key string) (string, error) { var err error ctx := context.Background() - token := os.Getenv("OP_SERVICE_ACCOUNT_TOKEN") - client, err := onepassword.NewClient( - ctx, - onepassword.WithServiceAccountToken(token), - onepassword.WithIntegrationInfo("Vals op integration", "v1.0.0"), - ) - if err != nil { - return "", fmt.Errorf("storage.NewClient: %v", err) - } + if p.client == nil { + token := os.Getenv("OP_SERVICE_ACCOUNT_TOKEN") - p.client = client + client, err := onepassword.NewClient( + ctx, + onepassword.WithServiceAccountToken(token), + onepassword.WithIntegrationInfo("Vals op integration", "v1.0.0"), + ) + if err != nil { + return "", fmt.Errorf("storage.NewClient: %v", err) + } + + p.client = client + } prefixedKey := fmt.Sprintf("op://%s", key) item, err := p.client.Secrets.Resolve(ctx, prefixedKey) diff --git a/pkg/providers/onepasswordconnect/onepasswordconnect.go b/pkg/providers/onepasswordconnect/onepasswordconnect.go index 63a05a2..be7f45b 100644 --- a/pkg/providers/onepasswordconnect/onepasswordconnect.go +++ b/pkg/providers/onepasswordconnect/onepasswordconnect.go @@ -31,14 +31,16 @@ func (p *provider) GetString(key string) (string, error) { return "", fmt.Errorf("invalid URI: %v", errors.New("vault or item missing")) } - client, err := connect.NewClientFromEnvironment() - if err != nil { - return "", fmt.Errorf("storage.NewClient: %v", err) - } + if p.client == nil { + client, err := connect.NewClientFromEnvironment() + if err != nil { + return "", fmt.Errorf("storage.NewClient: %v", err) + } - p.client = client + p.client = client + } - item, err := client.GetItem(splits[1], splits[0]) + item, err := p.client.GetItem(splits[1], splits[0]) if err != nil { return "", fmt.Errorf("error retrieving item: %v", err) }