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

[7.x] [code] Add option to turn the go dependency download on/off. (#43096) #43165

Merged
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
3 changes: 2 additions & 1 deletion x-pack/legacy/plugins/code/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { resolve } from 'path';

import { CoreSetup, PluginInitializerContext } from 'src/core/server';
import { APP_TITLE } from './common/constants';
import { LanguageServers, LanguageServersDeveloping } from './server/lsp/language_servers';
import { codePlugin } from './server';
import { DEFAULT_WATERMARK_LOW_PERCENTAGE } from './server/disk_watermark';
import { LanguageServers, LanguageServersDeveloping } from './server/lsp/language_servers';

export type RequestFacade = Legacy.Request;
export type RequestQueryFacade = RequestQuery;
Expand Down Expand Up @@ -88,6 +88,7 @@ export const code = (kibana: any) =>
security: Joi.object({
enableMavenImport: Joi.boolean().default(true),
enableGradleImport: Joi.boolean().default(false),
installGoDependency: Joi.boolean().default(false),
installNodeDependency: Joi.boolean().default(true),
gitHostWhitelist: Joi.array()
.items(Joi.string())
Expand Down
13 changes: 12 additions & 1 deletion x-pack/legacy/plugins/code/server/lsp/go_launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class GoServerLauncher extends AbstractLauncher {
maxWorkspace,
this.options,
{
initialOptions: {
installGoDependency: this.options.security.installGoDependency,
},
clientCapabilities: {
textDocument: {
hover: {
Expand Down Expand Up @@ -94,6 +97,14 @@ export class GoServerLauncher extends AbstractLauncher {
if (!fs.existsSync(goPath)) {
fs.mkdirSync(goPath);
}
let go111MODULE = 'off';
if (this.options.security.installGoDependency) {
// There are no proper approaches to disable downloading go dependencies except creating inconsistencies of the
// running environments of go-langserver. Given that go language server will do its best to convert the repos
// into modules, one of the doable approaches is setting 'GO111MODULE' to false to be incompatible with the
// moduled repos.
go111MODULE = 'on';
}

const params: string[] = ['-port=' + port.toString()];
const golsp = path.resolve(installationPath, launchersFound[0]);
Expand All @@ -107,7 +118,7 @@ export class GoServerLauncher extends AbstractLauncher {
GOROOT: goRoot,
GOPATH: goPath,
PATH: envPath,
GO111MODULE: 'on',
GO111MODULE: go111MODULE,
CGO_ENABLED: '0',
},
});
Expand Down
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/code/server/server_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface LspOptions {
export interface SecurityOptions {
enableMavenImport: boolean;
enableGradleImport: boolean;
installGoDependency: boolean;
installNodeDependency: boolean;
gitHostWhitelist: string[];
gitProtocolWhitelist: string[];
Expand Down