Skip to content

Commit

Permalink
fixed typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Oct 25, 2021
1 parent 06f609c commit 186caf8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
12 changes: 8 additions & 4 deletions x-pack/plugins/actions/server/builtin_action_types/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ function validateConfig(

export type ActionTypeSecretsType = TypeOf<typeof SecretsSchema>;

const SecretsSchema = schema.object({
const SecretsSchemaProps = {
user: schema.nullable(schema.string()),
password: schema.nullable(schema.string()),
clientSecret: schema.nullable(schema.string()),
});
};

const SecretsSchema = schema.object(SecretsSchemaProps);

// params definition

Expand Down Expand Up @@ -174,8 +176,10 @@ function validateConnector(connector: {
const config = connector.config;
const secrets = connector.secrets;

if (config.service === AdditionalEmailServices.EXCHANGE && secrets.clientSecret == null) {
return '[clientSecret] is required';
if (config.service === AdditionalEmailServices.EXCHANGE) {
if (secrets.clientSecret == null) {
return '[clientSecret] is required';
}
} else if (config.hasAuth && (secrets.password == null || secrets.user == null)) {
if (secrets.user == null) {
return '[user] is required';
Expand Down
11 changes: 2 additions & 9 deletions x-pack/plugins/actions/server/lib/validate_with_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,8 @@ export function validateConnector<
Secrets extends ActionTypeSecrets = ActionTypeSecrets,
Params extends ActionTypeParams = ActionTypeParams,
ExecutorResultData = void
>(
actionType: ActionType<Config, Secrets, Params, ExecutorResultData>,
config: unknown,
secrets?: unknown
) {
return validateWithSchema(actionType, 'connector', {
config,
secrets,
});
>(actionType: ActionType<Config, Secrets, Params, ExecutorResultData>, value: unknown) {
return validateWithSchema(actionType, 'connector', value);
}

type ValidKeys = 'params' | 'config' | 'secrets' | 'connector';
Expand Down

0 comments on commit 186caf8

Please sign in to comment.