Skip to content

Commit

Permalink
[SR] Support capitalized date formats in snapshot names (#53751) (#54610
Browse files Browse the repository at this point in the history
)

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.

Co-authored-by: Jimmy Kuang <jimmy@elastic.co>
  • Loading branch information
cjcenizal and jkelastic authored Jan 13, 2020
1 parent 55efa3b commit e5bfc13
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -347,7 +347,7 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({
onChange={e => {
updatePolicy(
{
snapshotName: e.target.value.toLowerCase(),
snapshotName: e.target.value,
},
{
managedRepository,
Original file line number Diff line number Diff line change
@@ -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', {
Original file line number Diff line number Diff line change
@@ -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 : ''}`;
}

0 comments on commit e5bfc13

Please sign in to comment.