[Management] Handle commas as separations in the query for CCS purposes (#16535)

* Handle commas as separations in the query for CCS purposes

* Add tests

* Limit this to ccs queries, which just means they contain a :
This commit is contained in:
Chris Roberson 2018-02-08 10:13:18 -05:00 committed by GitHub
parent 73de529a00
commit bf14b4e3e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View file

@ -21,6 +21,11 @@ describe('isQueryAMatch', () => {
it('for a pattern that is only a wildcard', () => {
expect(isQueryAMatch('*', 'es')).toBeTruthy();
});
it('for a pattern that contains commas', () => {
expect(isQueryAMatch('cluster_one:kibana,cluster_two:kibana', 'cluster_one:kibana')).toBeTruthy();
expect(isQueryAMatch('cluster_one:k*,cluster_two:kibana', 'cluster_one:kibana')).toBeTruthy();
});
});
describe('returns false', () => {
@ -31,5 +36,9 @@ describe('isQueryAMatch', () => {
it('for a pattern with wildcards but does not remotely match', () => {
expect(isQueryAMatch('k*b*', 'es')).toBeFalsy();
});
it('for a pattern that contains commas but is not a CCS query', () => {
expect(isQueryAMatch('kibana,es', 'kibana')).toBeFalsy();
});
});
});

View file

@ -1,3 +1,7 @@
function isCCSQuery(query) {
return query.includes(':');
}
export const isQueryAMatch = (query, name) => {
if (name === query) {
return true;
@ -20,5 +24,11 @@ export const isQueryAMatch = (query, name) => {
return false;
}
if (query.includes(',')) {
return query.split(',').reduce((isMatch, subQuery) => {
return isMatch || isCCSQuery(subQuery) && isQueryAMatch(subQuery, name);
}, false);
}
return false;
};