-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LegacyUrlAlias and SavedObjectsClient.resolve()
New integration tests (except for Jest integration tests) are intentionally excluded. Will be added in a separate commit after conversion transforms include aliases.
- Loading branch information
Showing
26 changed files
with
1,098 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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. | ||
*/ | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const LEGACY_URL_ALIAS_TYPE = 'legacy-url-alias'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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. | ||
*/ | ||
|
||
export { LEGACY_URL_ALIAS_TYPE } from './constants'; | ||
export { LegacyUrlAlias } from './types'; | ||
export { registerCoreObjectTypes } from './registration'; |
36 changes: 36 additions & 0 deletions
36
src/core/server/saved_objects/object_types/registration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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 { typeRegistryMock } from '../saved_objects_type_registry.mock'; | ||
import { LEGACY_URL_ALIAS_TYPE } from './constants'; | ||
import { registerCoreObjectTypes } from './registration'; | ||
|
||
describe('Core saved object types registration', () => { | ||
describe('#registerCoreObjectTypes', () => { | ||
it('registers all expected types', () => { | ||
const typeRegistry = typeRegistryMock.create(); | ||
registerCoreObjectTypes(typeRegistry); | ||
|
||
expect(typeRegistry.registerType).toHaveBeenCalledTimes(1); | ||
expect(typeRegistry.registerType).toHaveBeenCalledWith( | ||
expect.objectContaining({ name: LEGACY_URL_ALIAS_TYPE }) | ||
); | ||
}); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
src/core/server/saved_objects/object_types/registration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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 { LEGACY_URL_ALIAS_TYPE } from './constants'; | ||
import { ISavedObjectTypeRegistry, SavedObjectTypeRegistry } from '..'; | ||
|
||
const legacyUrlAliasMappings = { | ||
properties: { | ||
targetNamespace: { type: 'keyword' }, | ||
targetType: { type: 'keyword' }, | ||
targetId: { type: 'keyword' }, | ||
lastResolved: { type: 'date' }, | ||
resolveCounter: { type: 'integer' }, | ||
disabled: { type: 'boolean' }, | ||
}, | ||
}; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function registerCoreObjectTypes( | ||
typeRegistry: ISavedObjectTypeRegistry & Pick<SavedObjectTypeRegistry, 'registerType'> | ||
) { | ||
typeRegistry.registerType({ | ||
name: LEGACY_URL_ALIAS_TYPE, | ||
namespaceType: 'agnostic', | ||
mappings: legacyUrlAliasMappings, | ||
hidden: true, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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. | ||
*/ | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface LegacyUrlAlias { | ||
targetNamespace: string; | ||
targetType: string; | ||
targetId: string; | ||
lastResolved?: string; | ||
resolveCounter?: number; | ||
disabled?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/core/server/saved_objects/routes/integration_tests/resolve.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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 supertest from 'supertest'; | ||
import { registerResolveRoute } from '../resolve'; | ||
import { ContextService } from '../../../context'; | ||
import { savedObjectsClientMock } from '../../service/saved_objects_client.mock'; | ||
import { HttpService, InternalHttpServiceSetup } from '../../../http'; | ||
import { createHttpServer, createCoreContext } from '../../../http/test_utils'; | ||
import { coreMock } from '../../../mocks'; | ||
|
||
const coreId = Symbol('core'); | ||
|
||
describe('GET /api/saved_objects/resolve/{type}/{id}', () => { | ||
let server: HttpService; | ||
let httpSetup: InternalHttpServiceSetup; | ||
let handlerContext: ReturnType<typeof coreMock.createRequestHandlerContext>; | ||
let savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>; | ||
|
||
beforeEach(async () => { | ||
const coreContext = createCoreContext({ coreId }); | ||
server = createHttpServer(coreContext); | ||
|
||
const contextService = new ContextService(coreContext); | ||
httpSetup = await server.setup({ | ||
context: contextService.setup({ pluginDependencies: new Map() }), | ||
}); | ||
|
||
handlerContext = coreMock.createRequestHandlerContext(); | ||
savedObjectsClient = handlerContext.savedObjects.client; | ||
|
||
httpSetup.registerRouteHandlerContext(coreId, 'core', async (ctx, req, res) => { | ||
return handlerContext; | ||
}); | ||
|
||
const router = httpSetup.createRouter('/api/saved_objects/'); | ||
registerResolveRoute(router); | ||
|
||
await server.start(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await server.stop(); | ||
}); | ||
|
||
it('formats successful response', async () => { | ||
const clientResponse = { | ||
saved_object: { | ||
id: 'logstash-*', | ||
title: 'logstash-*', | ||
type: 'logstash-type', | ||
attributes: {}, | ||
timeFieldName: '@timestamp', | ||
notExpandable: true, | ||
references: [], | ||
}, | ||
outcome: 'exactMatch' as 'exactMatch', | ||
}; | ||
|
||
savedObjectsClient.resolve.mockResolvedValue(clientResponse); | ||
|
||
const result = await supertest(httpSetup.server.listener) | ||
.get('/api/saved_objects/resolve/index-pattern/logstash-*') | ||
.expect(200); | ||
|
||
expect(result.body).toEqual(clientResponse); | ||
}); | ||
|
||
it('calls upon savedObjectClient.resolve', async () => { | ||
await supertest(httpSetup.server.listener) | ||
.get('/api/saved_objects/resolve/index-pattern/logstash-*') | ||
.expect(200); | ||
|
||
expect(savedObjectsClient.resolve).toHaveBeenCalled(); | ||
|
||
const args = savedObjectsClient.resolve.mock.calls[0]; | ||
expect(args).toEqual(['index-pattern', 'logstash-*']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License 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 { schema } from '@kbn/config-schema'; | ||
import { IRouter } from '../../http'; | ||
|
||
export const registerResolveRoute = (router: IRouter) => { | ||
router.get( | ||
{ | ||
path: '/resolve/{type}/{id}', | ||
validate: { | ||
params: schema.object({ | ||
type: schema.string(), | ||
id: schema.string(), | ||
}), | ||
}, | ||
}, | ||
router.handleLegacyErrors(async (context, req, res) => { | ||
const { type, id } = req.params; | ||
const result = await context.core.savedObjects.client.resolve(type, id); | ||
return res.ok({ body: result }); | ||
}) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.