mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 00:33:44 +00:00
[PM-2594] Replacing hardcoded cloud vault urls based on region obtained from ConfigService (#5629)
* [PM-2594] Added property "CloudVault" to EnvironmentServerConfigData and EnvironmentServerConfigResponse * [PM-2594] Replaced hardcoded vault urls with value obtained from ConfigService * [PM-2594] Renamed EnvironmentServerConfigResponse.cloudVault to cloudWebVault * [PM-2594] Updated unit test with new property "cloudWebVault" * [PM-2594] Added methods to get and set CloudWebVaultUrl on EnvironmentService. Configured ConfigurationService to set value based on cloudVaultRegion * [PM-2594] Added JSDOC comments to methods getCloudWebVaultUrl and setCloudWebVaultUrl * [PM-2594] Renamed EnvironmentServerConfigData.cloudVaultRegion to cloudRegion * [PM-2594] Fixed unit test
This commit is contained in:
@@ -39,6 +39,19 @@ export abstract class EnvironmentService {
|
||||
hasBaseUrl: () => boolean;
|
||||
getNotificationsUrl: () => string;
|
||||
getWebVaultUrl: () => string;
|
||||
/**
|
||||
* Retrieves the URL of the cloud web vault app.
|
||||
*
|
||||
* @returns {string} The URL of the cloud web vault app.
|
||||
* @remarks Use this method only in views exclusive to self-host instances.
|
||||
*/
|
||||
getCloudWebVaultUrl: () => string;
|
||||
/**
|
||||
* Sets the URL of the cloud web vault app based on the region parameter.
|
||||
*
|
||||
* @param {Region} region - The region of the cloud web vault app.
|
||||
*/
|
||||
setCloudWebVaultUrl: (region: Region) => void;
|
||||
getSendUrl: () => string;
|
||||
getIconsUrl: () => string;
|
||||
getApiUrl: () => string;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { Region } from "../../abstractions/environment.service";
|
||||
|
||||
import {
|
||||
EnvironmentServerConfigData,
|
||||
ServerConfigData,
|
||||
@@ -15,6 +17,7 @@ describe("ServerConfigData", () => {
|
||||
url: "https://test.com",
|
||||
},
|
||||
environment: {
|
||||
cloudRegion: Region.EU,
|
||||
vault: "https://vault.com",
|
||||
api: "https://api.com",
|
||||
identity: "https://identity.com",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { Region } from "../../abstractions/environment.service";
|
||||
import {
|
||||
ServerConfigResponse,
|
||||
ThirdPartyServerConfigResponse,
|
||||
@@ -50,6 +51,7 @@ export class ThirdPartyServerConfigData {
|
||||
}
|
||||
|
||||
export class EnvironmentServerConfigData {
|
||||
cloudRegion: Region;
|
||||
vault: string;
|
||||
api: string;
|
||||
identity: string;
|
||||
@@ -57,6 +59,7 @@ export class EnvironmentServerConfigData {
|
||||
sso: string;
|
||||
|
||||
constructor(response: Partial<EnvironmentServerConfigResponse>) {
|
||||
this.cloudRegion = response.cloudRegion;
|
||||
this.vault = response.vault;
|
||||
this.api = response.api;
|
||||
this.identity = response.identity;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { BaseResponse } from "../../../models/response/base.response";
|
||||
import { Region } from "../../abstractions/environment.service";
|
||||
|
||||
export class ServerConfigResponse extends BaseResponse {
|
||||
version: string;
|
||||
@@ -23,6 +24,7 @@ export class ServerConfigResponse extends BaseResponse {
|
||||
}
|
||||
|
||||
export class EnvironmentServerConfigResponse extends BaseResponse {
|
||||
cloudRegion: Region;
|
||||
vault: string;
|
||||
api: string;
|
||||
identity: string;
|
||||
@@ -36,6 +38,7 @@ export class EnvironmentServerConfigResponse extends BaseResponse {
|
||||
return;
|
||||
}
|
||||
|
||||
this.cloudRegion = this.getResponseProperty("CloudRegion");
|
||||
this.vault = this.getResponseProperty("Vault");
|
||||
this.api = this.getResponseProperty("Api");
|
||||
this.identity = this.getResponseProperty("Identity");
|
||||
|
||||
@@ -44,6 +44,7 @@ export class ConfigService implements ConfigServiceAbstraction {
|
||||
return serverConfig;
|
||||
}
|
||||
await this.stateService.setServerConfig(data);
|
||||
this.environmentService.setCloudWebVaultUrl(data.environment?.cloudRegion);
|
||||
}
|
||||
} catch {
|
||||
return null;
|
||||
|
||||
@@ -23,6 +23,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||
protected eventsUrl: string;
|
||||
private keyConnectorUrl: string;
|
||||
private scimUrl: string = null;
|
||||
private cloudWebVaultUrl: string;
|
||||
|
||||
readonly usUrls: Urls = {
|
||||
base: null,
|
||||
@@ -86,6 +87,26 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||
return "https://vault.bitwarden.com";
|
||||
}
|
||||
|
||||
getCloudWebVaultUrl() {
|
||||
if (this.cloudWebVaultUrl != null) {
|
||||
return this.cloudWebVaultUrl;
|
||||
}
|
||||
|
||||
return this.usUrls.webVault;
|
||||
}
|
||||
|
||||
setCloudWebVaultUrl(region: Region) {
|
||||
switch (region) {
|
||||
case Region.EU:
|
||||
this.cloudWebVaultUrl = this.euUrls.webVault;
|
||||
break;
|
||||
case Region.US:
|
||||
default:
|
||||
this.cloudWebVaultUrl = this.usUrls.webVault;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
getSendUrl() {
|
||||
return this.getWebVaultUrl() === "https://vault.bitwarden.com"
|
||||
? "https://send.bitwarden.com/#"
|
||||
@@ -239,6 +260,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
||||
return {
|
||||
base: this.baseUrl,
|
||||
webVault: this.webVaultUrl,
|
||||
cloudWebVault: this.cloudWebVaultUrl,
|
||||
api: this.apiUrl,
|
||||
identity: this.identityUrl,
|
||||
icons: this.iconsUrl,
|
||||
|
||||
Reference in New Issue
Block a user