mirror of
https://github.com/hashicorp/vault.git
synced 2025-12-25 19:31:14 +01:00
* [UI] Ember Data Migration - PKI Config Setup (#10320) * adds api and capabilities services to pki engine * updates eslintrc to ignore rest siblings for no-unused-vars rule * adds ember-template-lint to pki engine * updates check-issuers decorator to use api service * adds constants for pki capabilities paths * updates pki configuration route to use api service and fetch capabilities * [UI] Ember Data Migration - PKI Config Generate Form (#10322) * updates form class data object to tracked * adds isNot validator * updates tsconfig to resolve json modules * updates open-api form class to use the spec file rather than help response for form field/group generation * adds pki config generate form * [UI] Ember Data Migration - PKI Config Create (#10331) * updates pki configure create route and component * updates pki generate csr component to use api service and form class * updates pki generate root component to use api service and form class * updates pki import bundle component to use api service * [UI] Ember Data Migration - PKI Config Generate Sub Components (#10332) * updates pki generate toggle groups component to support form class * updates pki key parameters component to support form class * updates pki generate immediate component based on csr component changes * updates pki generate root component based on root component changes * more pki config sub component updates * updates pki issuer rotate root component to use api serivce and form * updates pki acceptance tests (#10341) * [UI] Ember Data Migration - PKI Configuration Edit (#10339) * adds forms for pki config acme, cluster, crl and urls * updates pki config edit worflow to use api service and forms * updates pki config details workflow to use api service (#10340) * updates auth configure section route to pass schema key to OpenApiForm constructor Co-authored-by: Jordan Reimer <zofskeez@gmail.com>
89 lines
2.4 KiB
JavaScript
89 lines
2.4 KiB
JavaScript
/**
|
|
* Copyright IBM Corp. 2016, 2025
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { isPresent } from '@ember/utils';
|
|
import { capitalize } from '@ember/string';
|
|
|
|
/*
|
|
* Model Validators
|
|
these return false when the condition fails because false means "invalid"
|
|
for example containsWhiteSpace returns "false" when a value HAS whitespace
|
|
because that is an invalid value
|
|
*/
|
|
export const presence = (value) => isPresent(value);
|
|
|
|
export const length = (value, { nullable = false, min, max } = {}) => {
|
|
if (!min && !max) return;
|
|
// value could be an integer if the attr has a default value of some number
|
|
const valueLength = value?.toString().length;
|
|
if (valueLength) {
|
|
const underMin = min && valueLength < min;
|
|
const overMax = max && valueLength > max;
|
|
return underMin || overMax ? false : true;
|
|
}
|
|
return nullable;
|
|
};
|
|
|
|
export const number = (value, { nullable = false } = {}) => {
|
|
// since 0 is falsy, !value returns true even though 0 is a valid number
|
|
if (!value && value !== 0) return nullable;
|
|
return !isNaN(value);
|
|
};
|
|
|
|
export const containsWhiteSpace = (value) => {
|
|
return !hasWhitespace(value);
|
|
};
|
|
|
|
export const endsInSlash = (value) => {
|
|
const validation = new RegExp('/$');
|
|
return !validation.test(value);
|
|
};
|
|
|
|
/*
|
|
* General Validators
|
|
these utils return true or false relative to the function name
|
|
*/
|
|
|
|
export const hasWhitespace = (value) => {
|
|
const validation = new RegExp('\\s', 'g'); // search for whitespace
|
|
return validation.test(value);
|
|
};
|
|
|
|
// HTML form inputs transform values to a string type
|
|
// this returns if the value can be evaluated as non-string, i.e. "null"
|
|
export const isNonString = (value) => {
|
|
try {
|
|
// if parsable the value could be an object, array, number, null, true or false
|
|
JSON.parse(value);
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
// returns true if the value is NOT equal to the comparison value
|
|
export const isNot = (value, { value: comparisonValue }) => value !== comparisonValue;
|
|
|
|
export const WHITESPACE_WARNING = (item) =>
|
|
`${capitalize(
|
|
item
|
|
)} contains whitespace. If this is desired, you'll need to encode it with %20 in API requests.`;
|
|
|
|
export const NON_STRING_WARNING =
|
|
'This value will be saved as a string. If you need to save a non-string value, please use the JSON editor.';
|
|
|
|
export default {
|
|
presence,
|
|
length,
|
|
number,
|
|
containsWhiteSpace,
|
|
endsInSlash,
|
|
isNonString,
|
|
hasWhitespace,
|
|
isNot,
|
|
WHITESPACE_WARNING,
|
|
NON_STRING_WARNING,
|
|
};
|