2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2020-09-30 11:33:01 +00:00
|
|
|
import {
|
|
|
|
validateInclusion,
|
|
|
|
validatePresence,
|
|
|
|
validateFormat,
|
|
|
|
} from 'ember-changeset-validations/validators';
|
2023-02-10 21:32:19 +00:00
|
|
|
import validateSometimes from 'consul-ui/validations/sometimes';
|
2020-09-30 11:33:01 +00:00
|
|
|
|
|
|
|
const name = 'intention-permission';
|
2022-09-15 08:43:17 +00:00
|
|
|
export default (schema) => ({
|
2023-02-10 21:32:19 +00:00
|
|
|
'*': [
|
|
|
|
validateSometimes(validatePresence(true), function () {
|
|
|
|
const methods = this.get('HTTP.Methods') || [];
|
|
|
|
const headers = this.get('HTTP.Header') || [];
|
|
|
|
const pathType = this.get('HTTP.PathType') || 'NoPath';
|
|
|
|
const path = this.get('HTTP.Path') || '';
|
|
|
|
const isValid = [
|
|
|
|
methods.length !== 0,
|
|
|
|
headers.length !== 0,
|
|
|
|
pathType !== 'NoPath' && path !== '',
|
|
|
|
].includes(true);
|
|
|
|
return !isValid;
|
|
|
|
}),
|
|
|
|
],
|
2020-09-30 11:33:01 +00:00
|
|
|
Action: [validateInclusion({ in: schema[name].Action.allowedValues })],
|
|
|
|
HTTP: {
|
2023-02-10 21:32:19 +00:00
|
|
|
Path: [
|
|
|
|
validateSometimes(validateFormat({ regex: /^\// }), function () {
|
|
|
|
const pathType = this.get('HTTP.PathType');
|
|
|
|
return typeof pathType !== 'undefined' && pathType !== 'NoPath';
|
|
|
|
}),
|
|
|
|
],
|
2020-09-30 11:33:01 +00:00
|
|
|
},
|
|
|
|
});
|