Add support for helpers in environment service (#353)

This commit is contained in:
Oscar Hinton 2021-07-23 22:46:32 +02:00 committed by GitHub
parent 230e00e423
commit 4ec06bbd1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 13 deletions

2
jslib

@ -1 +1 @@
Subproject commit 18bf616e2e0821a46b1cb71737d80b099a64b237 Subproject commit ecdd08624f61ccff8128b7cb3241f39e664e1c7f

1
package-lock.json generated
View File

@ -23,6 +23,7 @@
"node-forge": "0.10.0", "node-forge": "0.10.0",
"open": "^8.0.8", "open": "^8.0.8",
"papaparse": "^5.3.0", "papaparse": "^5.3.0",
"rxjs": "6.6.7",
"tldjs": "^2.3.1", "tldjs": "^2.3.1",
"zxcvbn": "^4.4.2" "zxcvbn": "^4.4.2"
}, },

View File

@ -87,6 +87,7 @@
"node-forge": "0.10.0", "node-forge": "0.10.0",
"open": "^8.0.8", "open": "^8.0.8",
"papaparse": "^5.3.0", "papaparse": "^5.3.0",
"rxjs": "6.6.7",
"tldjs": "^2.3.1", "tldjs": "^2.3.1",
"zxcvbn": "^4.4.2" "zxcvbn": "^4.4.2"
}, },

View File

@ -116,11 +116,11 @@ export class Main {
this.appIdService = new AppIdService(this.storageService); this.appIdService = new AppIdService(this.storageService);
this.tokenService = new TokenService(this.storageService); this.tokenService = new TokenService(this.storageService);
this.messagingService = new NoopMessagingService(); this.messagingService = new NoopMessagingService();
this.apiService = new NodeApiService(this.tokenService, this.platformUtilsService, this.environmentService = new EnvironmentService(this.storageService);
this.apiService = new NodeApiService(this.tokenService, this.platformUtilsService, this.environmentService,
async (expired: boolean) => await this.logout(), async (expired: boolean) => await this.logout(),
'Bitwarden_CLI/' + this.platformUtilsService.getApplicationVersion() + 'Bitwarden_CLI/' + this.platformUtilsService.getApplicationVersion() +
' (' + this.platformUtilsService.getDeviceString().toUpperCase() + ')'); ' (' + this.platformUtilsService.getDeviceString().toUpperCase() + ')');
this.environmentService = new EnvironmentService(this.apiService, this.storageService, null);
this.userService = new UserService(this.tokenService, this.storageService); this.userService = new UserService(this.tokenService, this.storageService);
this.containerService = new ContainerService(this.cryptoService); this.containerService = new ContainerService(this.cryptoService);
this.settingsService = new SettingsService(this.userService, this.storageService); this.settingsService = new SettingsService(this.userService, this.storageService);

View File

@ -23,8 +23,9 @@ export class ConfigCommand {
private async getOrSetServer(url: string, options: program.OptionValues): Promise<Response> { private async getOrSetServer(url: string, options: program.OptionValues): Promise<Response> {
if ((url == null || url.trim() === '') && if ((url == null || url.trim() === '') &&
!options.webVault && !options.api && !options.identity && !options.icons && !options.notifications && !options.events) { !options.webVault && !options.api && !options.identity && !options.icons && !options.notifications && !options.events) {
const baseUrl = this.environmentService.baseUrl; const stringRes = new StringResponse(
const stringRes = new StringResponse(baseUrl == null ? 'https://bitwarden.com' : baseUrl); this.environmentService.hasBaseUrl() ? this.environmentService.getUrls().base : 'https://bitwarden.com'
);
return Response.success(stringRes); return Response.success(stringRes);
} }

View File

@ -99,12 +99,13 @@ export class SendReceiveCommand extends DownloadCommand {
} }
private getApiUrl(url: URL) { private getApiUrl(url: URL) {
const urls = this.environmentService.getUrls();
if (url.origin === 'https://send.bitwarden.com') { if (url.origin === 'https://send.bitwarden.com') {
return 'https://vault.bitwarden.com/api'; return 'https://vault.bitwarden.com/api';
} else if (url.origin === this.apiService.apiBaseUrl) { } else if (url.origin === urls.api) {
return url.origin; return url.origin;
} else if (this.platformUtilsService.isDev() && url.origin === this.environmentService.getWebVaultUrl()) { } else if (this.platformUtilsService.isDev() && url.origin === urls.webVault) {
return this.apiService.apiBaseUrl; return urls.api;
} else { } else {
return url.origin + '/api'; return url.origin + '/api';
} }

View File

@ -35,11 +35,7 @@ export class StatusCommand {
} }
private baseUrl(): string { private baseUrl(): string {
let url = this.envService.baseUrl; return this.envService.getUrls().base;
if (url == null) {
url = 'https://bitwarden.com';
}
return url;
} }
private async status(): Promise<string> { private async status(): Promise<string> {