in authui-container/server/auth-server.ts [317:356]
private getFallbackConfig(hostname: string): Promise<UiConfig | null> {
// Parse config from environment variable first.
if (process.env.UI_CONFIG) {
try {
const config: UiConfig = JSON.parse(process.env.UI_CONFIG);
DefaultUiConfigBuilder.validateConfig(config);
return Promise.resolve(config);
} catch (error) {
// Ignore but log error.
log(`Invalid configuration in environment variable UI_CONFIG: ${error.message}`);
}
}
// Parse config from GCS bucket if available.
const cloudStorageHandler = new CloudStorageHandler(this.metadataServer, this.metadataServer);
return this.getBucketName()
.then((bucketName) => {
return cloudStorageHandler.readFile(bucketName, CONFIG_FILE_NAME);
})
.catch((error) => {
// If not available in GCS, use default config.
if (!this.defaultConfigPromise) {
// Default config should be retrieved once and cached in memory.
this.defaultConfigPromise = this.getDefaultConfig(hostname);
}
return this.defaultConfigPromise.then((config) => {
if (!config) {
// Do not cache config if IAP is not yet enabled.
this.defaultConfigPromise = null;
// Return default config.
return null;
}
return config;
})
.catch((err) => {
// Do not cache errors in building default config.
this.defaultConfigPromise = null;
throw err;
});
});
}