From 649fa74d2cd2055b0cafb7eb784932daad4f567c Mon Sep 17 00:00:00 2001 From: fernando Date: Fri, 9 Apr 2021 11:08:08 -0300 Subject: [PATCH 1/2] Compose password prompt fix Password in compose command is only requested when necessary, currently in the odd case of setting up a custom fauceet. fixes https://github.com/nemtech/symbol-bootstrap/issues/181 --- src/commands/compose.ts | 8 +------- src/service/ComposeService.ts | 20 +++++++++++++++---- test/service/BootstrapServce.test.ts | 1 + test/service/ComposeService.test.ts | 29 ++-------------------------- test/service/RunService.test.ts | 2 ++ 5 files changed, 22 insertions(+), 38 deletions(-) diff --git a/src/commands/compose.ts b/src/commands/compose.ts index 9b21ca1a5..950a5d6ed 100644 --- a/src/commands/compose.ts +++ b/src/commands/compose.ts @@ -42,12 +42,6 @@ export default class Compose extends Command { public async run(): Promise { const { flags } = this.parse(Compose); BootstrapUtils.showBanner(); - flags.password = await CommandUtils.resolvePassword( - flags.password, - flags.noPassword, - CommandUtils.passwordPromptDefaultMessage, - true, - ); - await new BootstrapService(this.config.root).compose(flags); + await new BootstrapService(this.config.root).compose({ ...flags, composeResolvePassword: !flags.noPassword }); } } diff --git a/src/service/ComposeService.ts b/src/service/ComposeService.ts index 404732c20..4e4637af4 100644 --- a/src/service/ComposeService.ts +++ b/src/service/ComposeService.ts @@ -22,9 +22,10 @@ import Logger from '../logger/Logger'; import LoggerFactory from '../logger/LoggerFactory'; import { Addresses, ConfigPreset, DockerCompose, DockerComposeService, DockerServicePreset } from '../model'; import { BootstrapUtils } from './BootstrapUtils'; +import { CommandUtils } from './CommandUtils'; import { ConfigLoader } from './ConfigLoader'; // eslint-disable-next-line @typescript-eslint/no-var-requires -export type ComposeParams = { target: string; user?: string; upgrade?: boolean; password?: string }; +export type ComposeParams = { target: string; user?: string; upgrade?: boolean; password?: string; composeResolvePassword: boolean }; const logger: Logger = LoggerFactory.getLogger(LogType.System); @@ -41,6 +42,7 @@ export interface PortConfiguration { export class ComposeService { public static defaultParams: ComposeParams = { + composeResolvePassword: false, target: BootstrapUtils.defaultTargetFolder, user: BootstrapUtils.CURRENT_USER, upgrade: false, @@ -383,7 +385,7 @@ export class ComposeService { stop_signal: 'SIGINT', environment: { FAUCET_PRIVATE_KEY: - n.environment?.FAUCET_PRIVATE_KEY || this.getMainAccountPrivateKey(passedAddresses) || '', + n.environment?.FAUCET_PRIVATE_KEY || (await this.getNemesisAccountPrivateKey(passedAddresses)) || '', NATIVE_CURRENCY_ID: BootstrapUtils.toSimpleHex( n.environment?.NATIVE_CURRENCY_ID || presetData.currencyMosaicId || '', ), @@ -424,8 +426,18 @@ export class ComposeService { return dockerCompose; } - private getMainAccountPrivateKey(passedAddresses: Addresses | undefined) { - const addresses = passedAddresses ?? this.configLoader.loadExistingAddresses(this.params.target, this.params.password); + private async getNemesisAccountPrivateKey(passedAddresses: Addresses | undefined) { + const addresses = + passedAddresses ?? + this.configLoader.loadExistingAddresses( + this.params.target, + await CommandUtils.resolvePassword( + this.params.password, + !this.params.composeResolvePassword, + CommandUtils.passwordPromptDefaultMessage, + false, + ), + ); return addresses?.mosaics?.[0]?.accounts[0].privateKey; } } diff --git a/test/service/BootstrapServce.test.ts b/test/service/BootstrapServce.test.ts index 25f50f631..d7f9c12c1 100644 --- a/test/service/BootstrapServce.test.ts +++ b/test/service/BootstrapServce.test.ts @@ -23,6 +23,7 @@ describe('BootstrapService', () => { const service = new BootstrapService(); const config: StartParams = { report: false, + composeResolvePassword: false, preset: Preset.bootstrap, reset: true, upgrade: false, diff --git a/test/service/ComposeService.test.ts b/test/service/ComposeService.test.ts index 2a831824b..1bf491f40 100644 --- a/test/service/ComposeService.test.ts +++ b/test/service/ComposeService.test.ts @@ -24,7 +24,8 @@ import { BootstrapUtils, ComposeService, ConfigLoader, ConfigService, LinkServic describe('ComposeService', () => { const password = '1234'; - const assertDockerCompose = async (params: StartParams, expectedComposeFile: string) => { + const assertDockerCompose = async (partialParams: Partial, expectedComposeFile: string) => { + const params = { ...ConfigService.defaultParams, ...ComposeService.defaultParams, ...LinkService.defaultParams, ...partialParams }; const root = '.'; const presetData = new ConfigLoader().createPresetData({ root, password, ...params }); const dockerCompose = await new ComposeService(root, params).run(presetData); @@ -68,8 +69,6 @@ ${BootstrapUtils.toYaml(dockerCompose)} it('Compose testnet dual', async () => { const params = { - ...ConfigService.defaultParams, - ...LinkService.defaultParams, target: 'target/tests/testnet-dual', password, reset: false, @@ -81,8 +80,6 @@ ${BootstrapUtils.toYaml(dockerCompose)} it('Compose testnet api', async () => { const params = { - ...ConfigService.defaultParams, - ...LinkService.defaultParams, target: 'target/tests/testnet-api', password, reset: false, @@ -94,8 +91,6 @@ ${BootstrapUtils.toYaml(dockerCompose)} it('Compose testnet peer', async () => { const params = { - ...ConfigService.defaultParams, - ...LinkService.defaultParams, target: 'target/tests/testnet-peer', password, reset: false, @@ -107,8 +102,6 @@ ${BootstrapUtils.toYaml(dockerCompose)} it('Compose mainnet dual', async () => { const params = { - ...ConfigService.defaultParams, - ...LinkService.defaultParams, target: 'target/tests/mainnet-dual', password, reset: false, @@ -120,8 +113,6 @@ ${BootstrapUtils.toYaml(dockerCompose)} it('Compose mainnet api', async () => { const params = { - ...ConfigService.defaultParams, - ...LinkService.defaultParams, target: 'target/tests/mainnet-api', password, reset: false, @@ -133,8 +124,6 @@ ${BootstrapUtils.toYaml(dockerCompose)} it('Compose mainnet peer', async () => { const params = { - ...ConfigService.defaultParams, - ...LinkService.defaultParams, target: 'target/tests/mainnet-peer', password, reset: false, @@ -146,8 +135,6 @@ ${BootstrapUtils.toYaml(dockerCompose)} it('Compose testnet supernode', async () => { const params = { - ...ConfigService.defaultParams, - ...LinkService.defaultParams, target: 'target/tests/testnet-supernode', password, customPreset: './test/unit-test-profiles/supernode.yml', @@ -160,8 +147,6 @@ ${BootstrapUtils.toYaml(dockerCompose)} it('Compose testnet dual voting', async () => { const params = { - ...ConfigService.defaultParams, - ...LinkService.defaultParams, target: 'target/tests/ComposeService-testnet-voting', password, reset: false, @@ -174,8 +159,6 @@ ${BootstrapUtils.toYaml(dockerCompose)} it('Compose bootstrap default', async () => { const params = { - ...ConfigService.defaultParams, - ...LinkService.defaultParams, customPresetObject: { faucets: [ { @@ -192,8 +175,6 @@ ${BootstrapUtils.toYaml(dockerCompose)} it('Compose bootstrap custom compose', async () => { const params = { - ...ConfigService.defaultParams, - ...LinkService.defaultParams, customPresetObject: { faucets: [ { @@ -212,8 +193,6 @@ ${BootstrapUtils.toYaml(dockerCompose)} it('Compose bootstrap custom preset', async () => { const params = { - ...ConfigService.defaultParams, - ...LinkService.defaultParams, customPresetObject: { faucets: [ { @@ -231,8 +210,6 @@ ${BootstrapUtils.toYaml(dockerCompose)} it('Compose bootstrap full with debug on', async () => { const params = { - ...ConfigService.defaultParams, - ...LinkService.defaultParams, customPresetObject: { dockerComposeDebugMode: true, faucets: [ @@ -252,8 +229,6 @@ ${BootstrapUtils.toYaml(dockerCompose)} it('Compose bootstrap repeat', async () => { const params = { - ...ConfigService.defaultParams, - ...LinkService.defaultParams, customPresetObject: { faucets: [ { diff --git a/test/service/RunService.test.ts b/test/service/RunService.test.ts index a1b462cd5..98ec2c154 100644 --- a/test/service/RunService.test.ts +++ b/test/service/RunService.test.ts @@ -34,6 +34,7 @@ describe('RunService', () => { detached: true, build: false, user: 'current', + composeResolvePassword: false, timeout: 1200, }; @@ -62,6 +63,7 @@ describe('RunService', () => { detached: true, build: false, user: 'current', + composeResolvePassword: false, timeout: 1200, }; From 14f0a2a3ff048f60658467d88a3a1546ec16da29 Mon Sep 17 00:00:00 2001 From: fernando Date: Sun, 11 Apr 2021 15:02:11 -0300 Subject: [PATCH 2/2] fixed compilation --- src/service/ComposeService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/ComposeService.ts b/src/service/ComposeService.ts index 4e4637af4..de704a930 100644 --- a/src/service/ComposeService.ts +++ b/src/service/ComposeService.ts @@ -25,7 +25,7 @@ import { BootstrapUtils } from './BootstrapUtils'; import { CommandUtils } from './CommandUtils'; import { ConfigLoader } from './ConfigLoader'; // eslint-disable-next-line @typescript-eslint/no-var-requires -export type ComposeParams = { target: string; user?: string; upgrade?: boolean; password?: string; composeResolvePassword: boolean }; +export type ComposeParams = { target: string; user?: string; upgrade?: boolean; password?: string; composeResolvePassword?: boolean }; const logger: Logger = LoggerFactory.getLogger(LogType.System);