Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const API_AUTH_LOGOUT = '/auth/logout';

export const ERROR_MISSING_ROLE_PATH = '/missing-role';

export const MAX_INTEGER = 2147483647;

export enum AuthType {
BASIC = 'basicauth',
OPEN_ID = 'openid',
Expand Down
13 changes: 9 additions & 4 deletions server/multitenancy/tenant_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import { createIndexMap } from '../../../../src/core/server/saved_objects/migrations/core/build_index_map';
import { mergeTypes } from '../../../../src/core/server/saved_objects/migrations/kibana/kibana_migrator';
import { SecurityClient } from '../backend/opendistro_security_client';
import { MAX_INTEGER } from '../../common';

export async function setupIndexTemplate(
esClient: ElasticsearchClient,
Expand All @@ -38,9 +39,11 @@ export async function setupIndexTemplate(
) {
const mappings: IndexMapping = buildActiveMappings(mergeTypes(typeRegistry.getAllTypes()));
try {
await esClient.indices.putTemplate({
await esClient.indices.putIndexTemplate({
name: 'tenant_template',
body: {
// Setting priority to the max value to avoid being overridden by custom index templates.
priority: MAX_INTEGER,
index_patterns: [
kibanaIndex + '_-*_*',
kibanaIndex + '_0*_*',
Expand All @@ -54,10 +57,12 @@ export async function setupIndexTemplate(
kibanaIndex + '_8*_*',
kibanaIndex + '_9*_*',
],
settings: {
number_of_shards: 1,
template: {
settings: {
number_of_shards: 1,
},
mappings,
},
mappings,
},
});
} catch (error) {
Expand Down
44 changes: 44 additions & 0 deletions server/multitenancy/test/tenant_index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import { MAX_INTEGER } from '../../../common';

describe('Tenant index template', () => {
const mockESClient = {
indices: {
putIndexTemplate: jest.fn().mockImplementation((template) => {
return template;
}),
},
};

const priority = MAX_INTEGER;

it('put template', () => {
const result = mockESClient.indices.putIndexTemplate({
name: 'test_index_template_a',
body: {
priority,
index_patterns: 'test_index_patterns_a',
template: {
settings: {
number_of_shards: 1,
},
},
},
});
expect(result.body.priority).toEqual(priority);
});
});