From 2e13d9937ec137a24946b7f9222f03aae41490c4 Mon Sep 17 00:00:00 2001 From: Neil Macneale V Date: Mon, 18 Sep 2023 15:17:19 -0700 Subject: [PATCH] Pass role and scope in to lookupEndpoint instead of ShellConfig --- src/lib/config/index.ts | 28 +++++++++------------------- test/lib/config.test.ts | 9 +++++++-- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/lib/config/index.ts b/src/lib/config/index.ts index 3d66ca2b..8b6dd8b6 100644 --- a/src/lib/config/index.ts +++ b/src/lib/config/index.ts @@ -120,15 +120,13 @@ export class Config { * TODO: Remove and store a ShellConfig in `fauna-command` */ export const lookupEndpoint = (flags: any, scope: string, role: string) => { - return ShellConfig.read(flags, scope, role).lookupEndpoint(); + return ShellConfig.read(flags).lookupEndpoint({ scope, role }); }; export type ShellOpts = { flags?: { [key: string]: any }; rootConfig?: { [key: string]: any }; projectConfig?: { [key: string]: any }; - scope?: string; - role?: string; }; export type EndpointConfig = { @@ -143,17 +141,13 @@ export class ShellConfig { flags: Config; rootConfig: RootConfig; projectConfig: ProjectConfig | undefined; - args: { - scope?: string; - role?: string; - }; // The selected stack from the project config. If there is a project config, this will also be set. stack: Stack | undefined; // The fully configured endpoint, including command line flags that override things like the URL. endpoint: Endpoint; - static read(flags: any, scope: string, role: string) { + static read(flags: any) { const rootConfig = ini.parse(readFileOpt(getRootConfigPath())); const projectConfigPath = getProjectConfigPath(); const projectConfig = projectConfigPath @@ -164,8 +158,6 @@ export class ShellConfig { flags, rootConfig, projectConfig, - scope, - role, }); } @@ -181,11 +173,6 @@ export class ShellConfig { this.projectConfig?.validate(this.rootConfig); - this.args = { - scope: opts.scope, - role: opts.role, - }; - const urlFlag = Endpoint.getURLFromConfig(this.flags); if (urlFlag !== undefined) { try { @@ -258,16 +245,19 @@ export class ShellConfig { } } - lookupEndpoint = (): EndpointConfig => { + lookupEndpoint = (opts: { + scope?: string; + role?: string; + }): EndpointConfig => { let database = this.stack?.database ?? ""; - if (this.args.scope !== undefined) { + if (opts.scope !== undefined) { if (this.stack !== undefined) { database += "/"; } - database += this.args.scope; + database += opts.scope; } - return this.endpoint.makeScopedEndpoint(database, this.args.role); + return this.endpoint.makeScopedEndpoint(database, opts.role); }; } diff --git a/test/lib/config.test.ts b/test/lib/config.test.ts index ea83427d..4245cbf9 100644 --- a/test/lib/config.test.ts +++ b/test/lib/config.test.ts @@ -7,8 +7,13 @@ import { } from "../../src/lib/config"; import sinon from "sinon"; -const lookupEndpoint = (opts: ShellOpts) => { - return new ShellConfig(opts).lookupEndpoint(); +const lookupEndpoint = ( + opts: ShellOpts & { role?: string; scope?: string } +) => { + return new ShellConfig(opts).lookupEndpoint({ + role: opts.role, + scope: opts.scope, + }); }; describe("root config", () => {