From a880fb8ed9a706b01d13b018819c7f489a1c2edb Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Wed, 17 Jul 2024 16:32:13 -0400 Subject: [PATCH] chore(internal/detect): export project sentinel value (#10560) This will allow dependent packages to use the value here, instead of repeating it. --- internal/detect/detect.go | 8 +++++--- internal/detect/detect_test.go | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/detect/detect.go b/internal/detect/detect.go index 91b8980fc806..6a17cbd43326 100644 --- a/internal/detect/detect.go +++ b/internal/detect/detect.go @@ -27,7 +27,9 @@ import ( ) const ( - projectIDSentinel = "*detect-project-id*" + // ProjectIDSentinel is the value that users should pass for the project ID + // to enable detection. + ProjectIDSentinel = "*detect-project-id*" envProjectID = "GOOGLE_CLOUD_PROJECT" ) @@ -41,8 +43,8 @@ var ( // 1. GOOGLE_CLOUD_PROJECT envvar // 2. ADC creds.ProjectID // 3. A static value if the environment is emulated. -func ProjectID(ctx context.Context, projectID string, emulatorEnvVar string, opts ...option.ClientOption) (string, error) { - if projectID != projectIDSentinel { +func ProjectID(ctx context.Context, projectID, emulatorEnvVar string, opts ...option.ClientOption) (string, error) { + if projectID != ProjectIDSentinel { return projectID, nil } // 1. Try a well known environment variable diff --git a/internal/detect/detect_test.go b/internal/detect/detect_test.go index 8a5afa7ca809..d9be2f32be72 100644 --- a/internal/detect/detect_test.go +++ b/internal/detect/detect_test.go @@ -37,19 +37,19 @@ func TestIt(t *testing.T) { }, { name: "environment project id", - projectID: projectIDSentinel, + projectID: ProjectIDSentinel, env: map[string]string{envProjectID: "environment-project-id"}, want: "environment-project-id", }, { name: "adc project id", - projectID: projectIDSentinel, + projectID: ProjectIDSentinel, adcProjectID: "adc-project-id", want: "adc-project-id", }, { name: "emulator project id", - projectID: projectIDSentinel, + projectID: ProjectIDSentinel, env: map[string]string{"EMULATOR_HOST": "something"}, want: "emulated-project", },