From e9ee78b5cde74c0ab96b6cedba0877d4ab1e34ee Mon Sep 17 00:00:00 2001 From: fauna-chase Date: Tue, 17 Oct 2023 19:35:12 -0500 Subject: [PATCH 1/2] don't validate endpoint config with --secret ENG-5661 This came up while I was testing updating schema in a pipeline. In this scenario the endpoints present in the project configuration won't exist, which is ok as long as a secret is getting passed. --- src/lib/config/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/config/index.ts b/src/lib/config/index.ts index 1232f35c..4d7c819a 100644 --- a/src/lib/config/index.ts +++ b/src/lib/config/index.ts @@ -201,8 +201,6 @@ export class ShellConfig { ? ProjectConfig.fromConfig(new Config("config key", opts.projectConfig)) : undefined; - this.projectConfig?.validate(this.rootConfig); - const urlFlag = Endpoint.getURLFromFlags(this.flags); if (urlFlag !== undefined) { try { @@ -250,7 +248,7 @@ export class ShellConfig { ); } - if (endpointName === undefined) { + if (endpointName === undefined || secretFlag !== undefined) { // This is a dummy secret. `--secret` must be set in this case, which // `validate` enforces. this.endpoint = new Endpoint({ @@ -260,6 +258,7 @@ export class ShellConfig { graphqlPort: this.flags.numberOpt("graphqlPort"), }); } else { + this.projectConfig?.validate(this.rootConfig); this.endpoint = this.rootConfig.endpoints[endpointName]; if (this.endpoint === undefined) { throw new Error(`No such endpoint '${endpointName}'`); From 6a237deb6b04aa3802155e0fd6c142abf471fce9 Mon Sep 17 00:00:00 2001 From: fauna-chase Date: Wed, 18 Oct 2023 14:42:04 -0500 Subject: [PATCH 2/2] use root config emptiness to skip validation --- src/lib/config/index.ts | 10 +++++++++- src/lib/config/root-config.ts | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib/config/index.ts b/src/lib/config/index.ts index 4d7c819a..67097eb3 100644 --- a/src/lib/config/index.ts +++ b/src/lib/config/index.ts @@ -248,7 +248,15 @@ export class ShellConfig { ); } - if (endpointName === undefined || secretFlag !== undefined) { + // There are 2 scenarios where we want to execute the first if block: + // 1. no endpoint name is set + // 2. In a CI/CD environment where a secret is set but there is no + // root config. In this scenario endpoints may be set by the project + // configuration but won't exist in their pipeline workspace. + if ( + endpointName === undefined || + (secretFlag !== undefined && this.rootConfig.isEmpty()) + ) { // This is a dummy secret. `--secret` must be set in this case, which // `validate` enforces. this.endpoint = new Endpoint({ diff --git a/src/lib/config/root-config.ts b/src/lib/config/root-config.ts index 5ed3a3d0..8dc12d2a 100644 --- a/src/lib/config/root-config.ts +++ b/src/lib/config/root-config.ts @@ -59,6 +59,10 @@ export class RootConfig { } } + isEmpty(): boolean { + return Object.keys(this.endpoints).length === 0; + } + /** * If there is an endpoint object in the config, and it has a * object underneath it, we are saying that it uses the