[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:
Rui Tomé 2023-07-03 21:43:22 +01:00 committed by GitHub
parent b0d7a71b38
commit db2427e05c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 59 additions and 5 deletions

View File

@ -66,7 +66,7 @@
<a
bitButton
buttonType="secondary"
href="https://vault.bitwarden.com"
href="{{ this.cloudWebVaultUrl }}"
target="_blank"
rel="noopener"
>

View File

@ -12,6 +12,7 @@ import { Organization } from "@bitwarden/common/admin-console/models/domain/orga
import { OrganizationConnectionResponse } from "@bitwarden/common/admin-console/models/response/organization-connection.response";
import { BillingSyncConfigApi } from "@bitwarden/common/billing/models/api/billing-sync-config.api";
import { SelfHostedOrganizationSubscriptionView } from "@bitwarden/common/billing/models/view/self-hosted-organization-subscription.view";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
@ -34,6 +35,7 @@ export class OrganizationSubscriptionSelfhostComponent implements OnInit, OnDest
subscription: SelfHostedOrganizationSubscriptionView;
organizationId: string;
userOrg: Organization;
cloudWebVaultUrl: string;
licenseOptions = LicenseOptions;
form = new FormGroup({
@ -82,8 +84,11 @@ export class OrganizationSubscriptionSelfhostComponent implements OnInit, OnDest
private route: ActivatedRoute,
private organizationApiService: OrganizationApiServiceAbstraction,
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService
) {}
private i18nService: I18nService,
private environmentService: EnvironmentService
) {
this.cloudWebVaultUrl = this.environmentService.getCloudWebVaultUrl();
}
async ngOnInit() {
this.route.params

View File

@ -102,7 +102,7 @@
<a
bitButton
buttonType="secondary"
href="https://vault.bitwarden.com/#/settings/subscription"
href="{{ this.cloudWebVaultUrl }}/#/settings/subscription"
target="_blank"
rel="noopener"
>

View File

@ -4,6 +4,7 @@ import { Router } from "@angular/router";
import { DialogServiceAbstraction, SimpleDialogType } from "@bitwarden/angular/services/dialog";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { SubscriptionResponse } from "@bitwarden/common/billing/models/response/subscription.response";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
@ -22,6 +23,7 @@ export class UserSubscriptionComponent implements OnInit {
showUpdateLicense = false;
sub: SubscriptionResponse;
selfHosted = false;
cloudWebVaultUrl: string;
cancelPromise: Promise<any>;
reinstatePromise: Promise<any>;
@ -34,9 +36,11 @@ export class UserSubscriptionComponent implements OnInit {
private router: Router,
private logService: LogService,
private fileDownloadService: FileDownloadService,
private dialogService: DialogServiceAbstraction
private dialogService: DialogServiceAbstraction,
private environmentService: EnvironmentService
) {
this.selfHosted = platformUtilsService.isSelfHost();
this.cloudWebVaultUrl = this.environmentService.getCloudWebVaultUrl();
}
async ngOnInit() {

View File

@ -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;

View File

@ -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",

View File

@ -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;

View File

@ -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");

View File

@ -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;

View File

@ -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,