diff --git a/README.md b/README.md index 2f6cf8e..7972a9b 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,8 @@ gitlab_url=https://my-personal-gitlab-instance.com/ The plugin will look for the `.gitlab.nvim` file in the root of the current project by default. However, you may provide a custom path to the configuration file via the `config_path` option. This must be an absolute path to the directory that holds your `.gitlab.nvim` file. +For more settings, please see `:h gitlab.nvim.connecting-to-gitlab` + ## Configuring the Plugin Here is the default setup function. All of these values are optional, and if you call this function with no values the defaults will be used: @@ -108,6 +110,9 @@ require("gitlab").setup({ imply_local = false, -- If true, will attempt to use --imply_local option when calling |:DiffviewOpen| }, }, + connection_settings = { + insecure = false, -- Like curl's --insecure option, ignore bad x509 certificates on connection + }, help = "g?", -- Opens a help popup for local keymaps when a relevant view is focused (popup, discussion panel, etc) popup = { -- The popup for comment creation, editing, and replying exit = "", diff --git a/cmd/client.go b/cmd/client.go index 46a5a7e..2694591 100644 --- a/cmd/client.go +++ b/cmd/client.go @@ -1,6 +1,7 @@ package main import ( + "crypto/tls" "encoding/json" "errors" "fmt" @@ -18,6 +19,10 @@ type DebugSettings struct { GoResponse bool `json:"go_response"` } +type ConnectionOptions struct { + Insecure bool `json:"insecure"` +} + type ProjectInfo struct { ProjectId string MergeId int @@ -40,8 +45,8 @@ type Client struct { /* initGitlabClient parses and validates the project settings and initializes the Gitlab client. */ func initGitlabClient() (error, *Client) { - if len(os.Args) < 6 { - return errors.New("Must provide gitlab url, port, auth token, debug settings, and log path"), nil + if len(os.Args) < 7 { + return errors.New("Must provide gitlab url, port, auth token, debug settings, log path, and connection settings"), nil } gitlabInstance := os.Args[1] @@ -62,6 +67,14 @@ func initGitlabClient() (error, *Client) { return fmt.Errorf("Could not parse debug settings: %w, %s", err, debugSettings), nil } + /* Parse connection options */ + connectionSettings := os.Args[6] + var connectionObject ConnectionOptions + err = json.Unmarshal([]byte(connectionSettings), &connectionObject) + if err != nil { + return fmt.Errorf("Could not parse connection settings: %w, %s", err, connectionSettings), nil + } + var apiCustUrl = fmt.Sprintf(gitlabInstance + "/api/v4") gitlabOptions := []gitlab.ClientOptionFunc{ @@ -76,6 +89,16 @@ func initGitlabClient() (error, *Client) { gitlabOptions = append(gitlabOptions, gitlab.WithResponseLogHook(responseLogger)) } + tr := &http.Transport{ + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: connectionObject.Insecure, + }, + } + + retryClient := retryablehttp.NewClient() + retryClient.HTTPClient.Transport = tr + gitlabOptions = append(gitlabOptions, gitlab.WithHTTPClient(retryClient.HTTPClient)) + client, err := gitlab.NewClient(authToken, gitlabOptions...) if err != nil { diff --git a/doc/gitlab.nvim.txt b/doc/gitlab.nvim.txt index 5d5ecb4..eb75a16 100644 --- a/doc/gitlab.nvim.txt +++ b/doc/gitlab.nvim.txt @@ -124,6 +124,8 @@ project by default. However, you may provide a custom path to the configuration file via the `config_path` option. This must be an absolute path to the directory that holds your `.gitlab.nvim` file. +The `connection_settings` block in the `state.lua` file will be used to +configure your connection to Gitlab. CONFIGURING THE PLUGIN *gitlab.nvim.configuring-the-plugin* diff --git a/lua/gitlab/server.lua b/lua/gitlab/server.lua index def61af..6004711 100644 --- a/lua/gitlab/server.lua +++ b/lua/gitlab/server.lua @@ -13,19 +13,16 @@ M.start = function(callback) local port = state.settings.port or empty_port local parsed_port = nil local callback_called = false - local command = state.settings.bin - .. " " - .. state.settings.gitlab_url - .. " " - .. port - .. " " - .. state.settings.auth_token - .. " " - .. "'" - .. vim.json.encode(state.settings.debug) - .. "'" - .. " " - .. state.settings.log_path + local command = string.format( + "%s %s %s %s '%s' %s '%s'", + state.settings.bin, + state.settings.gitlab_url, + port, + state.settings.auth_token, + vim.json.encode(state.settings.debug), + state.settings.log_path, + vim.json.encode(state.settings.connection_settings) + ) local job_id = vim.fn.jobstart(command, { on_stdout = function(_, data) diff --git a/lua/gitlab/state.lua b/lua/gitlab/state.lua index 41dda02..1b70711 100644 --- a/lua/gitlab/state.lua +++ b/lua/gitlab/state.lua @@ -20,6 +20,9 @@ M.settings = { imply_local = false, }, }, + connection_settings = { + insecure = true, + }, attachment_dir = "", help = "g?", popup = {