| 229 | } |
| 230 | |
| 231 | export function setUpCloudShellEnvironment(envFilePath: string | null): void { |
| 232 | // Special handling for GOOGLE_CLOUD_PROJECT in Cloud Shell: |
| 233 | // Because GOOGLE_CLOUD_PROJECT in Cloud Shell tracks the project |
| 234 | // set by the user using "gcloud config set project" we do not want to |
| 235 | // use its value. So, unless the user overrides GOOGLE_CLOUD_PROJECT in |
| 236 | // one of the .env files, we set the Cloud Shell-specific default here. |
| 237 | if (envFilePath && fs.existsSync(envFilePath)) { |
| 238 | const envFileContent = fs.readFileSync(envFilePath); |
| 239 | const parsedEnv = dotenv.parse(envFileContent); |
| 240 | if (parsedEnv['GOOGLE_CLOUD_PROJECT']) { |
| 241 | // .env file takes precedence in Cloud Shell |
| 242 | process.env['GOOGLE_CLOUD_PROJECT'] = parsedEnv['GOOGLE_CLOUD_PROJECT']; |
| 243 | } else { |
| 244 | // If not in .env, set to default and override global |
| 245 | process.env['GOOGLE_CLOUD_PROJECT'] = 'cloudshell-gca'; |
| 246 | } |
| 247 | } else { |
| 248 | // If no .env file, set to default and override global |
| 249 | process.env['GOOGLE_CLOUD_PROJECT'] = 'cloudshell-gca'; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | export function loadEnvironment(settings?: Settings): void { |
| 254 | const envFilePath = findEnvFile(process.cwd()); |