From f762e143c3860a5723cad0e1ce7ee63612b4df8a Mon Sep 17 00:00:00 2001 From: ricardo Date: Thu, 28 Apr 2022 12:06:22 -0400 Subject: [PATCH] :zap: Expose public api activation to the settings --- packages/cli/config/schema.ts | 6 +++--- packages/cli/src/Interfaces.ts | 4 ++++ packages/cli/src/Server.ts | 7 +++++-- packages/cli/test/integration/shared/constants.ts | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/cli/config/schema.ts b/packages/cli/config/schema.ts index 4ffde542aa..bef46f2007 100644 --- a/packages/cli/config/schema.ts +++ b/packages/cli/config/schema.ts @@ -576,11 +576,11 @@ export const schema = { }, }, - publicApiEndpoints: { - disable: { + publicApi: { + disabled: { format: Boolean, default: false, - env: 'N8N_PUBLIC_API_DISABLE', + env: 'N8N_PUBLIC_API_DISABLED', doc: 'Whether to disable the Public API', }, path: { diff --git a/packages/cli/src/Interfaces.ts b/packages/cli/src/Interfaces.ts index 53d96621dd..2461e84105 100644 --- a/packages/cli/src/Interfaces.ts +++ b/packages/cli/src/Interfaces.ts @@ -457,6 +457,7 @@ export interface IN8nUISettings { personalizationSurveyEnabled: boolean; defaultLocale: string; userManagement: IUserManagementSettings; + publicApi: IPublicApiSettings; workflowTagsDisabled: boolean; logLevel: 'info' | 'debug' | 'warn' | 'error' | 'verbose' | 'silent'; hiringBannerEnabled: boolean; @@ -480,6 +481,9 @@ export interface IUserManagementSettings { showSetupOnFirstLoad?: boolean; smtpSetup: boolean; } +export interface IPublicApiSettings { + enabled: boolean; +} export interface IPackageVersions { cli: string; diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index b33138493b..dd3eb54b1d 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -253,7 +253,7 @@ class App { this.payloadSizeMax = config.get('endpoints.payloadSizeMax'); this.timezone = config.get('generic.timezone'); this.restEndpoint = config.get('endpoints.rest'); - this.publicApiEndpoint = config.get('publicApiEndpoints.path'); + this.publicApiEndpoint = config.get('publicApi.path'); this.activeWorkflowRunner = ActiveWorkflowRunner.getInstance(); this.testWebhooks = TestWebhooks.getInstance(); @@ -324,6 +324,9 @@ class App { config.getEnv('userManagement.skipInstanceOwnerSetup') === false, smtpSetup: isEmailSetUp(), }, + publicApi: { + enabled: config.getEnv('publicApi.disabled') === false, + }, workflowTagsDisabled: config.getEnv('workflowTagsDisabled'), logLevel: config.getEnv('logs.level'), hiringBannerEnabled: config.getEnv('hiringBanner.enabled'), @@ -581,7 +584,7 @@ class App { return ResponseHelper.sendSuccessResponse(res, {}, true, 204); }); - if (!config.getEnv('publicApiEndpoints.disable')) { + if (!config.getEnv('publicApi.disabled')) { this.app.use(`/${this.publicApiEndpoint}`, ...(await loadPublicApiVersions())); } // Parse cookies for easier access diff --git a/packages/cli/test/integration/shared/constants.ts b/packages/cli/test/integration/shared/constants.ts index adae29cf1e..d7e165ab4a 100644 --- a/packages/cli/test/integration/shared/constants.ts +++ b/packages/cli/test/integration/shared/constants.ts @@ -2,7 +2,7 @@ import config from '../../../config'; export const REST_PATH_SEGMENT = config.getEnv('endpoints.rest') as Readonly; -export const PUBLIC_API_REST_PATH_SEGMENT = config.get('publicApiEndpoints.path') as Readonly; +export const PUBLIC_API_REST_PATH_SEGMENT = config.getEnv('publicApi.path') as Readonly; export const AUTHLESS_ENDPOINTS: Readonly = [ 'healthz',