Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResponseOps][Stack Connectors] Adding custom validators to sub actions framework #142376

Merged

Conversation

jonathan-buttner
Copy link
Contributor

The actions framework supports custom validators. A common one is to ensure the url used for an external integration is specified within the Kibana allowed URLs. This PR adds the custom validators logic to the sub actions framework and adds a common url validator for use by consumers.

@jonathan-buttner jonathan-buttner added release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting Feature:Actions Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.6.0 labels Sep 30, 2022
@jonathan-buttner jonathan-buttner marked this pull request as ready for review September 30, 2022 15:37
@jonathan-buttner jonathan-buttner requested a review from a team as a code owner September 30, 2022 15:37
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@jonathan-buttner
Copy link
Contributor Author

@elasticmachine merge upstream

@jonathan-buttner
Copy link
Contributor Author

@elasticmachine merge upstream

}

interface Validate<T> {
validate: ValidateFn<T>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe change it to validator

validate: ValidateFn<T>;
}

export type ValidateFn<T> = (obj: T, services: ValidatorServices) => void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use ValidatorType['customValidator']<T> that is defined x-pack/plugins/actions/server/types.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah great point.

@@ -42,3 +52,40 @@ export const buildValidators = <
},
};
};

const buildCustomValidators = <Config, Secrets>(
validators?: Array<ConfigValidator<Config> | SecretsValidator<Secrets>>
Copy link
Member

@cnasikas cnasikas Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can create a type in x-pack/plugins/actions/server/sub_action_framework/types.ts and use it here.

const buildCustomValidators = <Config, Secrets>(
validators?: Array<ConfigValidator<Config> | SecretsValidator<Secrets>>
) => {
const partitionedValidators = validators?.reduce<{
Copy link
Member

@cnasikas cnasikas Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: To improve readability this can be turned to a normal for-of-loop.

@jonathan-buttner jonathan-buttner enabled auto-merge (squash) October 4, 2022 14:10
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
actions 209 211 +2

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
actions 19 21 +2
Unknown metric groups

API count

id before after diff
actions 214 216 +2

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jonathan-buttner jonathan-buttner merged commit 0e7070a into elastic:main Oct 4, 2022
@jonathan-buttner jonathan-buttner deleted the sub-actions-validators branch October 4, 2022 15:44
WafaaNasr pushed a commit to WafaaNasr/kibana that referenced this pull request Oct 11, 2022
…ns framework (elastic#142376)

* Adding custom validators

* Updating README and tests

* Fixing translation error

* Addressing feedback

Co-authored-by: Kibana Machine <[email protected]>
WafaaNasr pushed a commit to WafaaNasr/kibana that referenced this pull request Oct 14, 2022
…ns framework (elastic#142376)

* Adding custom validators

* Updating README and tests

* Fixing translation error

* Addressing feedback

Co-authored-by: Kibana Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Actions release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants