@@ -3,13 +3,10 @@ package config
33import (
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