[SR] Support capitalized date formats in snapshot names (#53751)

Snapshot names that contain date math may require capital letters, e.g. "<snapshot-{now/d{yyyy.MM.dd|+09:00}}>". This change fixes a bug which complained that capital letters are not allowed in snapshot names, by scoping this validation to only the name part of this pattern, ignoring the date math part.
This commit is contained in:
Jimmy Kuang 2020-01-13 09:58:20 -08:00 committed by CJ Cenizal
parent 70aa7b3c5c
commit 79ee978fc4
3 changed files with 20 additions and 1 deletions

View file

@ -347,7 +347,7 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({
onChange={e => {
updatePolicy(
{
snapshotName: e.target.value.toLowerCase(),
snapshotName: e.target.value,
},
{
managedRepository,

View file

@ -15,6 +15,16 @@ const isStringEmpty = (str: string | null): boolean => {
return str ? !Boolean(str.trim()) : true;
};
// strExcludeDate is the concat results of the SnapshotName ...{...}>... without the date
// This way we can check only the SnapshotName portion for lowercasing
// For example: <logstash-{now/d}> would give strExcludeDate = <logstash->
const isSnapshotNameNotLowerCase = (str: string): boolean => {
const strExcludeDate =
str.substring(0, str.search('{')) + str.substring(str.search('}>') + 1, str.length);
return strExcludeDate !== strExcludeDate.toLowerCase() ? true : false;
};
export const validatePolicy = (
policy: SlmPolicyPayload,
validationHelperData: {
@ -61,6 +71,14 @@ export const validatePolicy = (
);
}
if (isSnapshotNameNotLowerCase(snapshotName)) {
validation.errors.snapshotName.push(
i18n.translate('xpack.snapshotRestore.policyValidation.snapshotNameLowerCaseErrorMessage', {
defaultMessage: 'Snapshot name needs to be lowercase.',
})
);
}
if (isStringEmpty(schedule)) {
validation.errors.schedule.push(
i18n.translate('xpack.snapshotRestore.policyValidation.scheduleRequiredErrorMessage', {

View file

@ -25,6 +25,7 @@ export class WebhookAction extends BaseAction {
this.username = get(props, 'username');
this.password = get(props, 'password');
this.contentType = get(props, 'contentType');
this.fullPath = `${this.host}:${this.port}${this.path ? '/' + this.path : ''}`;
}