From cce5af5e525f3674a5f815778bb0e9311859380c Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Wed, 22 Jan 2025 10:51:16 -0800 Subject: [PATCH] [Connectors] Allow pre-configured connectors to opt-in to exposing their config by setting `exposeConfig` (#207654) Resolves #206433 Added optional `exposeConfig` field to the `preconfiguredActionSchema` to allow return the configuration for the pre-configured connectors, which set this value as `true`. This change is completely backward compatible, because this field is optional and all the connectors, which don't have the value will remain to work the same way as before the change (won't return the config). Changed get and getAll methods of the ActionsClient to reflect opt-in config based on the set `exposeConfig` value. --- docs/management/connectors/pre-configured-connectors.asciidoc | 2 ++ .../actions/server/application/connector/methods/get/get.ts | 4 ++++ .../application/connector/methods/get_all/get_all.test.ts | 2 ++ .../server/application/connector/methods/get_all/get_all.ts | 1 + x-pack/platform/plugins/shared/actions/server/config.ts | 1 + x-pack/platform/plugins/shared/actions/server/types.ts | 1 + 6 files changed, 11 insertions(+) diff --git a/docs/management/connectors/pre-configured-connectors.asciidoc b/docs/management/connectors/pre-configured-connectors.asciidoc index 06a77a12beab3..49e7b8b8c7b43 100644 --- a/docs/management/connectors/pre-configured-connectors.asciidoc +++ b/docs/management/connectors/pre-configured-connectors.asciidoc @@ -48,6 +48,7 @@ connector: secrets: <5> user: elastic password: changeme + exposeConfig: true <6> ``` <1> The key is the connector identifier, `my-slack1` in this example. @@ -55,6 +56,7 @@ connector: <3> `name` is the name of the preconfigured connector. <4> `config` is the configuration specific to the connector type. <5> `secrets` is the sensitive configuration, such as username, password, and keys, specific to the connector type. +<6> `exposeConfig` is the optional boolean flag, which identify if connector config will be exposed in the actions API [NOTE] ============================================== diff --git a/x-pack/platform/plugins/shared/actions/server/application/connector/methods/get/get.ts b/x-pack/platform/plugins/shared/actions/server/application/connector/methods/get/get.ts index 2d4a94f5615d7..9e2ce49095ec6 100644 --- a/x-pack/platform/plugins/shared/actions/server/application/connector/methods/get/get.ts +++ b/x-pack/platform/plugins/shared/actions/server/application/connector/methods/get/get.ts @@ -66,6 +66,10 @@ export async function get({ isSystemAction: foundInMemoryConnector.isSystemAction, isDeprecated: isConnectorDeprecated(foundInMemoryConnector), }; + + if (foundInMemoryConnector.exposeConfig) { + connector.config = foundInMemoryConnector.config; + } } else { const result = await getConnectorSo({ unsecuredSavedObjectsClient: context.unsecuredSavedObjectsClient, diff --git a/x-pack/platform/plugins/shared/actions/server/application/connector/methods/get_all/get_all.test.ts b/x-pack/platform/plugins/shared/actions/server/application/connector/methods/get_all/get_all.test.ts index 5ff37776cf2dc..b2a13bc988cd1 100644 --- a/x-pack/platform/plugins/shared/actions/server/application/connector/methods/get_all/get_all.test.ts +++ b/x-pack/platform/plugins/shared/actions/server/application/connector/methods/get_all/get_all.test.ts @@ -787,6 +787,7 @@ describe('getAllUnsecured()', () => { config: { foo: 'bar', }, + exposeConfig: true, }, /** * System actions will not @@ -829,6 +830,7 @@ describe('getAllUnsecured()', () => { isSystemAction: false, isDeprecated: false, referencedByCount: 2, + config: { foo: 'bar' }, }, ]); diff --git a/x-pack/platform/plugins/shared/actions/server/application/connector/methods/get_all/get_all.ts b/x-pack/platform/plugins/shared/actions/server/application/connector/methods/get_all/get_all.ts index 15aa19452a6f9..8ee6dccbfb896 100644 --- a/x-pack/platform/plugins/shared/actions/server/application/connector/methods/get_all/get_all.ts +++ b/x-pack/platform/plugins/shared/actions/server/application/connector/methods/get_all/get_all.ts @@ -120,6 +120,7 @@ async function getAllHelper({ isPreconfigured: inMemoryConnector.isPreconfigured, isDeprecated: isConnectorDeprecated(inMemoryConnector), isSystemAction: inMemoryConnector.isSystemAction, + ...(inMemoryConnector.exposeConfig ? { config: inMemoryConnector.config } : {}), })), ].sort((a, b) => a.name.localeCompare(b.name)); diff --git a/x-pack/platform/plugins/shared/actions/server/config.ts b/x-pack/platform/plugins/shared/actions/server/config.ts index f16a9830678cd..52adae782f55c 100644 --- a/x-pack/platform/plugins/shared/actions/server/config.ts +++ b/x-pack/platform/plugins/shared/actions/server/config.ts @@ -32,6 +32,7 @@ const preconfiguredActionSchema = schema.object({ actionTypeId: schema.string({ minLength: 1 }), config: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }), secrets: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }), + exposeConfig: schema.maybe(schema.boolean({ defaultValue: false })), }); const customHostSettingsSchema = schema.object({ diff --git a/x-pack/platform/plugins/shared/actions/server/types.ts b/x-pack/platform/plugins/shared/actions/server/types.ts index c07f900a02217..84647700257cf 100644 --- a/x-pack/platform/plugins/shared/actions/server/types.ts +++ b/x-pack/platform/plugins/shared/actions/server/types.ts @@ -102,6 +102,7 @@ export interface InMemoryConnector< > extends ActionResult { secrets: Secrets; config: Config; + exposeConfig?: boolean; } export type FindActionResult = ConnectorWithExtraFindData;