kibana/x-pack/plugins/spaces/server/routes/api/v1/spaces.ts
Brandon Kobel ef0bfba39d
Switching from public/private to external/internal APIs (#36815) (#36886)
* Switching from public/private to external/internal APIs

We use the public folder a lot of other places to denote files which
should be exposed client-side. Using folders names public was causing
issues with some of the operations team's tooling, so we're renaming
these.

* Fixing forgotten import in test
2019-05-24 12:56:58 -04:00

53 lines
1.5 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import Boom from 'boom';
import { Space } from '../../../../common/model/space';
import { wrapError } from '../../../lib/errors';
import { SpacesClient } from '../../../lib/spaces_client';
import { addSpaceIdToPath } from '../../../lib/spaces_url_parser';
import { getSpaceById } from '../../lib';
export function initInternalSpacesApi(server: any, routePreCheckLicenseFn: any) {
server.route({
method: 'POST',
path: '/api/spaces/v1/space/{id}/select',
async handler(request: any) {
const { SavedObjectsClient } = server.savedObjects;
const spacesClient: SpacesClient = server.plugins.spaces.spacesClient.getScopedClient(
request
);
const id = request.params.id;
try {
const existingSpace: Space | null = await getSpaceById(
spacesClient,
id,
SavedObjectsClient.errors
);
if (!existingSpace) {
return Boom.notFound();
}
const config = server.config();
return {
location: addSpaceIdToPath(
config.get('server.basePath'),
existingSpace.id,
config.get('server.defaultRoute')
),
};
} catch (error) {
return wrapError(error);
}
},
config: {
pre: [routePreCheckLicenseFn],
},
});
}