Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom NP plugin paths in production #53562

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 1 addition & 11 deletions src/cli/serve/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,12 @@ function applyConfigOverrides(rawConfig, opts, extraCliOptions) {
}

set('plugins.scanDirs', _.compact([].concat(get('plugins.scanDirs'), opts.pluginDir)));

set(
'plugins.paths',
_.compact(
[].concat(
get('plugins.paths'),
opts.pluginPath,
opts.runExamples
? [
// Ideally this would automatically include all plugins in the examples dir
fromRoot('examples/demo_search'),
fromRoot('examples/search_explorer'),
fromRoot('examples/embeddable_examples'),
fromRoot('examples/embeddable_explorer'),
]
: [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stacey-gammon FYI you won't have to manually add these anymore

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, thanks!!


XPACK_INSTALLED && !opts.oss ? [XPACK_DIR] : []
)
)
Expand Down Expand Up @@ -253,6 +242,7 @@ export default function(program) {
silent: !!opts.silent,
watch: !!opts.watch,
repl: !!opts.repl,
runExamples: !!opts.runExamples,
// We want to run without base path when the `--run-examples` flag is given so that we can use local
// links in other documentation sources, like "View this tutorial [here](http://localhost:5601/app/tutorial/xyz)".
// We can tell users they only have to run with `yarn start --run-examples` to get those
Expand Down
1 change: 1 addition & 0 deletions src/core/server/config/__mocks__/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function getEnvOptions(options: DeepPartial<EnvOptions> = {}): EnvOptions
basePath: false,
optimize: false,
oss: false,
runExamples: false,
...(options.cliArgs || {}),
},
isDevClusterMaster:
Expand Down
12 changes: 6 additions & 6 deletions src/core/server/config/__snapshots__/env.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/core/server/config/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,25 @@ test('pluginSearchPaths does not contains x-pack plugins path if --oss flag is t

expect(env.pluginSearchPaths).not.toContain('/some/home/dir/x-pack/plugins');
});

test('pluginSearchPaths contains examples plugins path if --run-examples flag is true', () => {
const env = new Env(
'/some/home/dir',
getEnvOptions({
cliArgs: { runExamples: true },
})
);

expect(env.pluginSearchPaths).toContain('/some/home/dir/examples');
});

test('pluginSearchPaths does not contains examples plugins path if --run-examples flag is false', () => {
const env = new Env(
'/some/home/dir',
getEnvOptions({
cliArgs: { runExamples: false },
})
);

expect(env.pluginSearchPaths).not.toContain('/some/home/dir/examples');
});
9 changes: 4 additions & 5 deletions src/core/server/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface CliArgs {
optimize: boolean;
open: boolean;
oss: boolean;
runExamples: boolean;
}

export class Env {
Expand All @@ -61,8 +62,6 @@ export class Env {
/** @internal */
public readonly logDir: string;
/** @internal */
public readonly staticFilesDir: string;
/** @internal */
public readonly pluginSearchPaths: readonly string[];

/**
Expand Down Expand Up @@ -100,14 +99,14 @@ export class Env {
this.configDir = resolve(this.homeDir, 'config');
this.binDir = resolve(this.homeDir, 'bin');
this.logDir = resolve(this.homeDir, 'log');
this.staticFilesDir = resolve(this.homeDir, 'ui');

this.pluginSearchPaths = [
resolve(this.homeDir, 'src', 'plugins'),
options.cliArgs.oss ? '' : resolve(this.homeDir, 'x-pack', 'plugins'),
...(options.cliArgs.oss ? [] : [resolve(this.homeDir, 'x-pack', 'plugins')]),
resolve(this.homeDir, 'plugins'),
...(options.cliArgs.runExamples ? [resolve(this.homeDir, 'examples')] : []),
resolve(this.homeDir, '..', 'kibana-extra'),
].filter(Boolean);
];

this.cliArgs = Object.freeze(options.cliArgs);
this.configs = Object.freeze(options.configs);
Expand Down
11 changes: 3 additions & 8 deletions src/core/server/http/http_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import uuid from 'uuid';
import { config, HttpConfig } from '.';
import { Env } from '../config';
import { getEnvOptions } from '../config/__mocks__/env';

const validHostnames = ['www.example.com', '8.8.8.8', '::1', 'localhost'];
const invalidHostname = 'asdf$%^';
Expand Down Expand Up @@ -265,8 +263,7 @@ describe('with TLS', () => {
clientAuthentication: 'none',
},
}),
{} as any,
Env.createDefault(getEnvOptions())
{} as any
);

expect(httpConfig.ssl.requestCert).toBe(false);
Expand All @@ -283,8 +280,7 @@ describe('with TLS', () => {
clientAuthentication: 'optional',
},
}),
{} as any,
Env.createDefault(getEnvOptions())
{} as any
);

expect(httpConfig.ssl.requestCert).toBe(true);
Expand All @@ -301,8 +297,7 @@ describe('with TLS', () => {
clientAuthentication: 'required',
},
}),
{} as any,
Env.createDefault(getEnvOptions())
{} as any
);

expect(httpConfig.ssl.requestCert).toBe(true);
Expand Down
5 changes: 1 addition & 4 deletions src/core/server/http/http_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import { ByteSizeValue, schema, TypeOf } from '@kbn/config-schema';
import { Env } from '../config';
import { CspConfigType, CspConfig, ICspConfig } from '../csp';
import { SslConfig, sslSchema } from './ssl_config';

Expand Down Expand Up @@ -135,7 +134,6 @@ export class HttpConfig {
public maxPayload: ByteSizeValue;
public basePath?: string;
public rewriteBasePath: boolean;
public publicDir: string;
public defaultRoute?: string;
public ssl: SslConfig;
public compression: { enabled: boolean; referrerWhitelist?: string[] };
Expand All @@ -144,7 +142,7 @@ export class HttpConfig {
/**
* @internal
*/
constructor(rawHttpConfig: HttpConfigType, rawCspConfig: CspConfigType, env: Env) {
constructor(rawHttpConfig: HttpConfigType, rawCspConfig: CspConfigType) {
this.autoListen = rawHttpConfig.autoListen;
this.host = rawHttpConfig.host;
this.port = rawHttpConfig.port;
Expand All @@ -154,7 +152,6 @@ export class HttpConfig {
this.keepaliveTimeout = rawHttpConfig.keepaliveTimeout;
this.socketTimeout = rawHttpConfig.socketTimeout;
this.rewriteBasePath = rawHttpConfig.rewriteBasePath;
this.publicDir = env.staticFilesDir;
this.ssl = new SslConfig(rawHttpConfig.ssl || {});
this.defaultRoute = rawHttpConfig.defaultRoute;
this.compression = rawHttpConfig.compression;
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/http/http_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ export class HttpService implements CoreService<InternalHttpServiceSetup, HttpSe
private requestHandlerContext?: RequestHandlerContextContainer;

constructor(private readonly coreContext: CoreContext) {
const { logger, configService, env } = coreContext;
const { logger, configService } = coreContext;

this.logger = logger;
this.log = logger.get('http');
this.config$ = combineLatest(
configService.atPath<HttpConfigType>(httpConfig.path),
configService.atPath<CspConfigType>(cspConfig.path)
).pipe(map(([http, csp]) => new HttpConfig(http, csp, env)));
).pipe(map(([http, csp]) => new HttpConfig(http, csp)));
this.httpServer = new HttpServer(logger, 'Kibana');
this.httpsRedirectServer = new HttpsRedirectServer(logger.get('http', 'redirect', 'server'));
}
Expand Down
8 changes: 2 additions & 6 deletions src/core/server/http/http_tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import { HttpConfig, config } from './http_config';
import { Router } from './router';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { ByteSizeValue } from '@kbn/config-schema';
import { Env } from '../config';
import { getEnvOptions } from '../config/__mocks__/env';

const emptyOutput = {
statusCode: 400,
Expand Down Expand Up @@ -122,8 +120,7 @@ describe('getServerOptions', () => {
certificate: 'some-certificate-path',
},
}),
{} as any,
Env.createDefault(getEnvOptions())
{} as any
);

expect(getServerOptions(httpConfig).tls).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -152,8 +149,7 @@ describe('getServerOptions', () => {
clientAuthentication: 'required',
},
}),
{} as any,
Env.createDefault(getEnvOptions())
{} as any
);

expect(getServerOptions(httpConfig).tls).toMatchInlineSnapshot(`
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class LegacyService implements CoreService {
private settings: Record<string, any> | undefined;

constructor(private readonly coreContext: CoreContext) {
const { logger, configService, env } = coreContext;
const { logger, configService } = coreContext;

this.log = logger.get('legacy-service');
this.devConfig$ = configService
Expand All @@ -122,7 +122,7 @@ export class LegacyService implements CoreService {
this.httpConfig$ = combineLatest(
configService.atPath<HttpConfigType>(httpConfig.path),
configService.atPath<CspConfigType>(cspConfig.path)
).pipe(map(([http, csp]) => new HttpConfig(http, csp, env)));
).pipe(map(([http, csp]) => new HttpConfig(http, csp)));
}

public async discoverPlugins(): Promise<LegacyServiceDiscoverPlugins> {
Expand Down
Loading