Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,3 @@ import manifest from '../kibana.json';

export const PLUGIN_ID = manifest.id;
export const SAVED_OBJECT_TYPE = 'integrations-manager';
export const API_ROOT = `/api/${PLUGIN_ID}`;
export const API_INTEGRATIONS_LIST = `${API_ROOT}/list`;
export const API_INTEGRATIONS_INFO = `${API_ROOT}/package/{pkgkey}`;
export const API_SAVED_OBJECTS_ROOT = `${API_ROOT}/saved_objects`;
export const API_SAVED_OBJECTS_DETAIL = `${API_ROOT}/saved_objects/{oid}`;
28 changes: 28 additions & 0 deletions x-pack/legacy/plugins/integrations_manager/common/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 { PLUGIN_ID } from './constants';

export const API_ROOT = `/api/${PLUGIN_ID}`;
export const API_LIST_PATTERN = `${API_ROOT}/list`;
export const API_INFO_PATTERN = `${API_ROOT}/package/{pkgkey}`;
export const API_ZIP_PATTERN = `${API_INFO_PATTERN}.zip`;
export const API_TGZ_PATTERN = `${API_INFO_PATTERN}.tar.gz`;

export function getListPath() {
return API_LIST_PATTERN;
}

export function getInfoPath(pkgkey: string) {
return API_INFO_PATTERN.replace('{pkgkey}', pkgkey);
}

export function getZipPath(pkgkey: string) {
return API_ZIP_PATTERN.replace('{pkgkey}', pkgkey);
}

export function getTgzPath(pkgkey: string) {
return API_TGZ_PATTERN.replace('{pkgkey}', pkgkey);
}
6 changes: 3 additions & 3 deletions x-pack/legacy/plugins/integrations_manager/public/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { npStart } from 'ui/new_platform';
import { HttpHandler } from 'src/core/public/http';
import { IntegrationInfo, IntegrationList } from '../common/types';
import { API_INTEGRATIONS_INFO, API_INTEGRATIONS_LIST } from '../common/constants';
import { getListPath, getInfoPath } from '../common/routes';

let _fetch: HttpHandler = npStart.core.http.fetch;

Expand All @@ -16,14 +16,14 @@ export function setClient(client: HttpHandler): void {
}

export async function getIntegrationsList(): Promise<IntegrationList> {
const path = API_INTEGRATIONS_LIST;
const path = getListPath();
const list: IntegrationList = await _fetch(path);

return list;
}

export async function getIntegrationInfoByKey(pkgkey: string): Promise<IntegrationInfo> {
const path = API_INTEGRATIONS_INFO.replace('{pkgkey}', pkgkey);
const path = getInfoPath(pkgkey);
const info: IntegrationInfo = await _fetch(path);

return info;
Expand Down
62 changes: 17 additions & 45 deletions x-pack/legacy/plugins/integrations_manager/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,82 +3,54 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import {
PLUGIN_ID,
API_INTEGRATIONS_LIST,
API_INTEGRATIONS_INFO,
API_SAVED_OBJECTS_DETAIL,
API_SAVED_OBJECTS_ROOT,
SAVED_OBJECT_TYPE,
} from '../common/constants';
import { PLUGIN_ID } from '../common/constants';
import { Request, ServerRoute } from '../common/types';
import {
API_LIST_PATTERN,
API_INFO_PATTERN,
API_TGZ_PATTERN,
API_ZIP_PATTERN,
} from '../common/routes';
import { fetchInfo, fetchList, getArchiveInfo } from './registry';
import { getClient } from './saved_objects';

interface PostRequest extends Request {
payload: {
body: string;
interface PackageRequest extends Request {
params: {
pkgkey: string;
};
}

// Manager public API paths (currently essentially a proxy to registry service)
export const routes: ServerRoute[] = [
{
method: 'GET',
path: API_INTEGRATIONS_LIST,
path: API_LIST_PATTERN,
options: { tags: [`access:${PLUGIN_ID}`] },
handler: fetchList,
},
{
method: 'GET',
path: API_INTEGRATIONS_INFO,
path: API_INFO_PATTERN,
options: { tags: [`access:${PLUGIN_ID}`] },
handler: async (req: Request) => fetchInfo(req.params.pkgkey),
handler: async (req: PackageRequest) => fetchInfo(req.params.pkgkey),
},
{
method: 'GET',
path: `${API_INTEGRATIONS_INFO}.zip`,
path: API_ZIP_PATTERN,
options: { tags: [`access:${PLUGIN_ID}`] },
handler: async (req: Request) => {
handler: async (req: PackageRequest) => {
const { pkgkey } = req.params;
const paths = await getArchiveInfo(`${pkgkey}.zip`);
return { meta: { pkgkey, paths } };
},
},
{
method: 'GET',
path: `${API_INTEGRATIONS_INFO}.tar.gz`,
path: API_TGZ_PATTERN,
options: { tags: [`access:${PLUGIN_ID}`] },
handler: async (req: Request) => {
handler: async (req: PackageRequest) => {
const { pkgkey } = req.params;
const paths = await getArchiveInfo(`${pkgkey}.tar.gz`);
return { meta: { pkgkey, paths } };
},
},
{
method: 'GET',
path: API_SAVED_OBJECTS_ROOT,
options: { tags: [`access:${PLUGIN_ID}`] },
handler: async (req: Request) => getClient(req).find({ type: SAVED_OBJECT_TYPE }),
},
{
method: 'GET',
path: API_SAVED_OBJECTS_DETAIL,
options: { tags: [`access:${PLUGIN_ID}`] },
handler: async (req: Request) => getClient(req).get(SAVED_OBJECT_TYPE, req.params.oid),
},
{
method: 'POST',
path: API_SAVED_OBJECTS_ROOT,
options: { tags: [`access:${PLUGIN_ID}`] },
handler: async (req: PostRequest) =>
getClient(req).create(
SAVED_OBJECT_TYPE,
{
is_working: true,
other: req.payload.body,
},
{ id: 'TBD', overwrite: true }
),
},
];