Skip to content

Commit

Permalink
[8.x] [Connectors] Allow pre-configured connectors to opt-in to expos…
Browse files Browse the repository at this point in the history
…ing their config by setting `exposeConfig` (#207654) (#207902)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Connectors] Allow pre-configured connectors to opt-in to exposing
their config by setting `exposeConfig`
(#207654)](#207654)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Yuliia
Naumenko","email":"jo.naumenko@gmail.com"},"sourceCommit":{"committedDate":"2025-01-22T18:51:16Z","message":"[Connectors]
Allow pre-configured connectors to opt-in to exposing their config by
setting `exposeConfig` (#207654)\n\nResolves #206433\r\n\r\nAdded
optional `exposeConfig` field to the `preconfiguredActionSchema`\r\nto
allow return the configuration for the pre-configured
connectors,\r\nwhich set this value as `true`.\r\nThis change is
completely backward compatible, because this field is\r\noptional and
all the connectors, which don't have the value will remain\r\nto work
the same way as before the change (won't return the
config).\r\n\r\nChanged get and getAll methods of the ActionsClient to
reflect opt-in\r\nconfig based on the set `exposeConfig`
value.","sha":"c15674f6d1e670b4210e31031ed93a8c95fdba3b","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","v9.0.0","backport:version","8.18
candidate","v8.18.0"],"title":"[Connectors] Allow pre-configured
connectors to opt-in to exposing their config by setting
`exposeConfig`","number":207654,"url":"https://github.com/elastic/kibana/pull/207654","mergeCommit":{"message":"[Connectors]
Allow pre-configured connectors to opt-in to exposing their config by
setting `exposeConfig` (#207654)\n\nResolves #206433\r\n\r\nAdded
optional `exposeConfig` field to the `preconfiguredActionSchema`\r\nto
allow return the configuration for the pre-configured
connectors,\r\nwhich set this value as `true`.\r\nThis change is
completely backward compatible, because this field is\r\noptional and
all the connectors, which don't have the value will remain\r\nto work
the same way as before the change (won't return the
config).\r\n\r\nChanged get and getAll methods of the ActionsClient to
reflect opt-in\r\nconfig based on the set `exposeConfig`
value.","sha":"c15674f6d1e670b4210e31031ed93a8c95fdba3b"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/207654","number":207654,"mergeCommit":{"message":"[Connectors]
Allow pre-configured connectors to opt-in to exposing their config by
setting `exposeConfig` (#207654)\n\nResolves #206433\r\n\r\nAdded
optional `exposeConfig` field to the `preconfiguredActionSchema`\r\nto
allow return the configuration for the pre-configured
connectors,\r\nwhich set this value as `true`.\r\nThis change is
completely backward compatible, because this field is\r\noptional and
all the connectors, which don't have the value will remain\r\nto work
the same way as before the change (won't return the
config).\r\n\r\nChanged get and getAll methods of the ActionsClient to
reflect opt-in\r\nconfig based on the set `exposeConfig`
value.","sha":"c15674f6d1e670b4210e31031ed93a8c95fdba3b"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Yuliia Naumenko <jo.naumenko@gmail.com>
  • Loading branch information
kibanamachine and YulNaumenko authored Jan 23, 2025
1 parent e177f15 commit 0a10241
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/management/connectors/pre-configured-connectors.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ connector:
secrets: <5>
user: elastic
password: changeme
exposeConfig: true <6>
```

<1> The key is the connector identifier, `my-slack1` in this example.
<2> `actionTypeId` is the action type identifier.
<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]
==============================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ describe('getAllUnsecured()', () => {
config: {
foo: 'bar',
},
exposeConfig: true,
},
/**
* System actions will not
Expand Down Expand Up @@ -857,6 +858,7 @@ describe('getAllUnsecured()', () => {
isSystemAction: false,
isDeprecated: false,
referencedByCount: 2,
config: { foo: 'bar' },
},
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
1 change: 1 addition & 0 deletions x-pack/platform/plugins/shared/actions/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions x-pack/platform/plugins/shared/actions/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export interface InMemoryConnector<
> extends ActionResult {
secrets: Secrets;
config: Config;
exposeConfig?: boolean;
}

export type FindActionResult = ConnectorWithExtraFindData;
Expand Down

0 comments on commit 0a10241

Please sign in to comment.