-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a53aea
commit 03d8aa1
Showing
19 changed files
with
600 additions
and
275 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
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,9 @@ | ||
{ | ||
"id": "remote_clusters", | ||
"version": "kibana", | ||
"requiredPlugins": [ | ||
"home" | ||
], | ||
"server": true, | ||
"ui": true | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* 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 { RemoteClustersServerPlugin } from './plugin'; | ||
|
||
export const plugin = () => new RemoteClustersServerPlugin(); |
26 changes: 26 additions & 0 deletions
26
...plugins/remote_clusters/server/lib/call_with_request_factory/call_with_request_factory.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,26 @@ | ||
/* | ||
* 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 { ElasticsearchServiceSetup } from 'kibana/server'; | ||
import { once } from 'lodash'; | ||
|
||
const callWithRequest = once((elasticsearchService: ElasticsearchServiceSetup) => { | ||
return elasticsearchService.createClient('remote_clusters', {}); | ||
}); | ||
|
||
export const callWithRequestFactory = ( | ||
elasticsearchService: ElasticsearchServiceSetup, | ||
request: any | ||
) => { | ||
return (...args: any[]) => { | ||
return ( | ||
callWithRequest(elasticsearchService) | ||
.asScoped(request) | ||
// @ts-ignore | ||
.callAsCurrentUser(...args) | ||
); | ||
}; | ||
}; |
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/remote_clusters/server/lib/call_with_request_factory/index.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,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { callWithRequestFactory } from './call_with_request_factory'; |
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/remote_clusters/server/lib/is_es_error/index.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,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { isEsError } from './is_es_error'; |
13 changes: 13 additions & 0 deletions
13
x-pack/legacy/plugins/remote_clusters/server/lib/is_es_error/is_es_error.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,13 @@ | ||
/* | ||
* 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 * as legacyElasticsearch from 'elasticsearch'; | ||
|
||
const esErrorsParent = legacyElasticsearch.errors._Abstract; | ||
|
||
export function isEsError(err: Error) { | ||
return err instanceof esErrorsParent; | ||
} |
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/remote_clusters/server/lib/license_pre_routing_factory/index.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,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { licensePreRoutingFactory } from './license_pre_routing_factory'; |
62 changes: 62 additions & 0 deletions
62
...emote_clusters/server/lib/license_pre_routing_factory/license_pre_routing_factory.test.js
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,62 @@ | ||
/* | ||
* 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 expect from '@kbn/expect'; | ||
import { licensePreRoutingFactory } from '.'; | ||
import { | ||
LICENSE_STATUS_VALID, | ||
LICENSE_STATUS_INVALID, | ||
} from '../../../../../common/constants/license_status'; | ||
import { kibanaResponseFactory } from '../../../../../../../src/core/server'; | ||
|
||
describe('licensePreRoutingFactory()', () => { | ||
let mockServer; | ||
let mockLicenseCheckResults; | ||
|
||
beforeEach(() => { | ||
mockServer = { | ||
plugins: { | ||
xpack_main: { | ||
info: { | ||
feature: () => ({ | ||
getLicenseCheckResults: () => mockLicenseCheckResults, | ||
}), | ||
}, | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
describe('status is invalid', () => { | ||
beforeEach(() => { | ||
mockLicenseCheckResults = { | ||
status: LICENSE_STATUS_INVALID, | ||
}; | ||
}); | ||
|
||
it('replies with 403', () => { | ||
const routeWithLicenseCheck = licensePreRoutingFactory(mockServer, () => {}); | ||
const stubRequest = {}; | ||
const response = routeWithLicenseCheck({}, stubRequest, kibanaResponseFactory); | ||
expect(response.status).to.be(403); | ||
}); | ||
}); | ||
|
||
describe('status is valid', () => { | ||
beforeEach(() => { | ||
mockLicenseCheckResults = { | ||
status: LICENSE_STATUS_VALID, | ||
}; | ||
}); | ||
|
||
it('replies with nothing', () => { | ||
const routeWithLicenseCheck = licensePreRoutingFactory(mockServer, () => null); | ||
const stubRequest = {}; | ||
const response = routeWithLicenseCheck({}, stubRequest, kibanaResponseFactory); | ||
expect(response).to.be(null); | ||
}); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
...ins/remote_clusters/server/lib/license_pre_routing_factory/license_pre_routing_factory.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,43 @@ | ||
/* | ||
* 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 { | ||
KibanaRequest, | ||
KibanaResponseFactory, | ||
RequestHandler, | ||
RequestHandlerContext, | ||
} from 'src/core/server'; | ||
import { PLUGIN } from '../../../common'; | ||
import { LICENSE_STATUS_VALID } from '../../../../../common/constants/license_status'; | ||
import { ServerShim } from '../../types'; | ||
|
||
export const licensePreRoutingFactory = ( | ||
server: ServerShim, | ||
handler: RequestHandler<any, any, any> | ||
): RequestHandler<any, any, any> => { | ||
const xpackMainPlugin = server.plugins.xpack_main; | ||
|
||
// License checking and enable/disable logic | ||
return function licensePreRouting( | ||
ctx: RequestHandlerContext, | ||
request: KibanaRequest, | ||
response: KibanaResponseFactory | ||
) { | ||
const licenseCheckResults = xpackMainPlugin.info.feature(PLUGIN.ID).getLicenseCheckResults(); | ||
const { status } = licenseCheckResults; | ||
|
||
if (status !== LICENSE_STATUS_VALID) { | ||
return response.customError({ | ||
body: { | ||
message: licenseCheckResults.messsage, | ||
}, | ||
statusCode: 403, | ||
}); | ||
} | ||
|
||
return handler(ctx, request, response); | ||
}; | ||
}; |
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,53 @@ | ||
/* | ||
* 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 { CoreSetup, Plugin } from 'src/core/server'; | ||
|
||
import { registerLicenseChecker } from '../../../server/lib/register_license_checker'; | ||
import { PLUGIN } from '../common'; | ||
import { ServerShim, RouteDependencies } from './types'; | ||
|
||
import { | ||
registerGetRoute, | ||
registerAddRoute, | ||
registerUpdateRoute, | ||
registerDeleteRoute, | ||
} from './routes/api'; | ||
|
||
export class RemoteClustersServerPlugin implements Plugin<void, void, any, any> { | ||
async setup( | ||
{ http, elasticsearch: elasticsearchService }: CoreSetup, | ||
{ | ||
__LEGACY: serverShim, | ||
}: { | ||
__LEGACY: ServerShim; | ||
} | ||
) { | ||
const elasticsearch = await elasticsearchService.adminClient; | ||
const router = http.createRouter(); | ||
const routeDependencies: RouteDependencies = { | ||
elasticsearch, | ||
elasticsearchService, | ||
router, | ||
}; | ||
|
||
registerLicenseChecker( | ||
serverShim as any, | ||
PLUGIN.ID, | ||
PLUGIN.getI18nName(), | ||
PLUGIN.MINIMUM_LICENSE_REQUIRED | ||
); | ||
|
||
// Register routes. | ||
registerGetRoute(routeDependencies, serverShim); | ||
registerAddRoute(routeDependencies, serverShim); | ||
registerUpdateRoute(routeDependencies, serverShim); | ||
registerDeleteRoute(routeDependencies, serverShim); | ||
} | ||
|
||
start() {} | ||
|
||
stop() {} | ||
} |
Oops, something went wrong.