Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Reuse 1Password client #548

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions pkg/providers/onepassword/onepassword.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions pkg/providers/onepasswordconnect/onepasswordconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading