Skip to content

Commit 1a34296

Browse files
committed
[APP] Refactor secret name
1 parent 2a76138 commit 1a34296

File tree

2 files changed

+2
-28
lines changed

2 files changed

+2
-28
lines changed

app/pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewConfiguration(logger *zap.Logger) (*Configuration, error) {
2929
}
3030

3131
// Load from secret
32-
secretName := os.Getenv("APP_SECRET")
32+
secretName := os.Getenv("APP_SECRET_NAME")
3333
if secretName != "" {
3434
config, err := loadFromSecret(secretName)
3535
if err != nil {

app/pkg/config/secretManager.go

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ package config
33
import (
44
"bytes"
55
"context"
6-
"errors"
76
"fmt"
8-
"os"
97

108
secretmanager "cloud.google.com/go/secretmanager/apiv1"
119
"github.com/spf13/viper"
12-
"golang.org/x/oauth2/google"
1310
secretmanagerpb "google.golang.org/genproto/googleapis/cloud/secretmanager/v1"
1411
)
1512

@@ -22,12 +19,8 @@ func loadFromSecret(secretName string) (*Configuration, error) {
2219
}
2320

2421
// Download secret
25-
projectId, err := getProjectId(ctx)
26-
if err != nil {
27-
return nil, err
28-
}
2922
secret, err := client.AccessSecretVersion(ctx, &secretmanagerpb.AccessSecretVersionRequest{
30-
Name: fmt.Sprintf("projects/%s/secrets/%s/versions/latest", projectId, secretName),
23+
Name: fmt.Sprintf("%s/versions/latest", secretName),
3124
})
3225
if err != nil {
3326
return nil, err
@@ -47,22 +40,3 @@ func loadFromSecret(secretName string) (*Configuration, error) {
4740

4841
return &config, nil
4942
}
50-
51-
func getProjectId(ctx context.Context) (string, error) {
52-
// Fetch from the credentials
53-
credentials, err := google.FindDefaultCredentials(ctx)
54-
if err != nil {
55-
return "", err
56-
}
57-
if credentials.ProjectID != "" {
58-
return credentials.ProjectID, nil
59-
}
60-
61-
// Fetch from the environment variable
62-
projectId := os.Getenv("APP_PROJECT_ID")
63-
if projectId != "" {
64-
return projectId, nil
65-
}
66-
67-
return "", errors.New("unable to retrieve project id")
68-
}

0 commit comments

Comments
 (0)