summaryrefslogtreecommitdiff
path: root/packages/cli/src/config
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src/config')
-rw-r--r--packages/cli/src/config/auth.ts2
-rw-r--r--packages/cli/src/config/settings.ts27
2 files changed, 28 insertions, 1 deletions
diff --git a/packages/cli/src/config/auth.ts b/packages/cli/src/config/auth.ts
index 439bd36b..4561f5d6 100644
--- a/packages/cli/src/config/auth.ts
+++ b/packages/cli/src/config/auth.ts
@@ -9,7 +9,7 @@ import { loadEnvironment } from './settings.js';
export const validateAuthMethod = (authMethod: string): string | null => {
loadEnvironment();
- if (authMethod === AuthType.LOGIN_WITH_GOOGLE) {
+ if (authMethod === AuthType.LOGIN_WITH_GOOGLE || AuthType.CLOUD_SHELL) {
return null;
}
diff --git a/packages/cli/src/config/settings.ts b/packages/cli/src/config/settings.ts
index 93f042aa..c2d03167 100644
--- a/packages/cli/src/config/settings.ts
+++ b/packages/cli/src/config/settings.ts
@@ -203,8 +203,35 @@ function findEnvFile(startDir: string): string | null {
}
}
+export function setUpCloudShellEnvironment(envFilePath: string | null): void {
+ // Special handling for GOOGLE_CLOUD_PROJECT in Cloud Shell:
+ // Because GOOGLE_CLOUD_PROJECT in Cloud Shell tracks the project
+ // set by the user using "gcloud config set project" we do not want to
+ // use its value. So, unless the user overrides GOOGLE_CLOUD_PROJECT in
+ // one of the .env files, we set the Cloud Shell-specific default here.
+ if (envFilePath && fs.existsSync(envFilePath)) {
+ const envFileContent = fs.readFileSync(envFilePath);
+ const parsedEnv = dotenv.parse(envFileContent);
+ if (parsedEnv.GOOGLE_CLOUD_PROJECT) {
+ // .env file takes precedence in Cloud Shell
+ process.env.GOOGLE_CLOUD_PROJECT = parsedEnv.GOOGLE_CLOUD_PROJECT;
+ } else {
+ // If not in .env, set to default and override global
+ process.env.GOOGLE_CLOUD_PROJECT = 'cloudshell-gca';
+ }
+ } else {
+ // If no .env file, set to default and override global
+ process.env.GOOGLE_CLOUD_PROJECT = 'cloudshell-gca';
+ }
+}
+
export function loadEnvironment(): void {
const envFilePath = findEnvFile(process.cwd());
+
+ if (process.env.CLOUD_SHELL === 'true') {
+ setUpCloudShellEnvironment(envFilePath);
+ }
+
if (envFilePath) {
dotenv.config({ path: envFilePath, quiet: true });
}