Skip to content

Commit 4f1fe4a

Browse files
Allow insecure connections to Gitlab (#234)
This MR makes it possible to ignore bad x509 certificates when connecting to Gitlab, by creating a custom HTTP connection. The option is exposed via the setup function. This is a PATCH release.
1 parent 670f088 commit 4f1fe4a

File tree

5 files changed

+45
-15
lines changed

5 files changed

+45
-15
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ gitlab_url=https://my-personal-gitlab-instance.com/
9292

9393
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.
9494

95+
For more settings, please see `:h gitlab.nvim.connecting-to-gitlab`
96+
9597
## Configuring the Plugin
9698

9799
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({
108110
imply_local = false, -- If true, will attempt to use --imply_local option when calling |:DiffviewOpen|
109111
},
110112
},
113+
connection_settings = {
114+
insecure = false, -- Like curl's --insecure option, ignore bad x509 certificates on connection
115+
},
111116
help = "g?", -- Opens a help popup for local keymaps when a relevant view is focused (popup, discussion panel, etc)
112117
popup = { -- The popup for comment creation, editing, and replying
113118
exit = "<Esc>",

cmd/client.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"crypto/tls"
45
"encoding/json"
56
"errors"
67
"fmt"
@@ -18,6 +19,10 @@ type DebugSettings struct {
1819
GoResponse bool `json:"go_response"`
1920
}
2021

22+
type ConnectionOptions struct {
23+
Insecure bool `json:"insecure"`
24+
}
25+
2126
type ProjectInfo struct {
2227
ProjectId string
2328
MergeId int
@@ -40,8 +45,8 @@ type Client struct {
4045
/* initGitlabClient parses and validates the project settings and initializes the Gitlab client. */
4146
func initGitlabClient() (error, *Client) {
4247

43-
if len(os.Args) < 6 {
44-
return errors.New("Must provide gitlab url, port, auth token, debug settings, and log path"), nil
48+
if len(os.Args) < 7 {
49+
return errors.New("Must provide gitlab url, port, auth token, debug settings, log path, and connection settings"), nil
4550
}
4651

4752
gitlabInstance := os.Args[1]
@@ -62,6 +67,14 @@ func initGitlabClient() (error, *Client) {
6267
return fmt.Errorf("Could not parse debug settings: %w, %s", err, debugSettings), nil
6368
}
6469

70+
/* Parse connection options */
71+
connectionSettings := os.Args[6]
72+
var connectionObject ConnectionOptions
73+
err = json.Unmarshal([]byte(connectionSettings), &connectionObject)
74+
if err != nil {
75+
return fmt.Errorf("Could not parse connection settings: %w, %s", err, connectionSettings), nil
76+
}
77+
6578
var apiCustUrl = fmt.Sprintf(gitlabInstance + "/api/v4")
6679

6780
gitlabOptions := []gitlab.ClientOptionFunc{
@@ -76,6 +89,16 @@ func initGitlabClient() (error, *Client) {
7689
gitlabOptions = append(gitlabOptions, gitlab.WithResponseLogHook(responseLogger))
7790
}
7891

92+
tr := &http.Transport{
93+
TLSClientConfig: &tls.Config{
94+
InsecureSkipVerify: connectionObject.Insecure,
95+
},
96+
}
97+
98+
retryClient := retryablehttp.NewClient()
99+
retryClient.HTTPClient.Transport = tr
100+
gitlabOptions = append(gitlabOptions, gitlab.WithHTTPClient(retryClient.HTTPClient))
101+
79102
client, err := gitlab.NewClient(authToken, gitlabOptions...)
80103

81104
if err != nil {

doc/gitlab.nvim.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ project by default. However, you may provide a custom path to the configuration
124124
file via the `config_path` option. This must be an absolute path to the
125125
directory that holds your `.gitlab.nvim` file.
126126

127+
The `connection_settings` block in the `state.lua` file will be used to
128+
configure your connection to Gitlab.
127129

128130
CONFIGURING THE PLUGIN *gitlab.nvim.configuring-the-plugin*
129131

lua/gitlab/server.lua

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,16 @@ M.start = function(callback)
1313
local port = state.settings.port or empty_port
1414
local parsed_port = nil
1515
local callback_called = false
16-
local command = state.settings.bin
17-
.. " "
18-
.. state.settings.gitlab_url
19-
.. " "
20-
.. port
21-
.. " "
22-
.. state.settings.auth_token
23-
.. " "
24-
.. "'"
25-
.. vim.json.encode(state.settings.debug)
26-
.. "'"
27-
.. " "
28-
.. state.settings.log_path
16+
local command = string.format(
17+
"%s %s %s %s '%s' %s '%s'",
18+
state.settings.bin,
19+
state.settings.gitlab_url,
20+
port,
21+
state.settings.auth_token,
22+
vim.json.encode(state.settings.debug),
23+
state.settings.log_path,
24+
vim.json.encode(state.settings.connection_settings)
25+
)
2926

3027
local job_id = vim.fn.jobstart(command, {
3128
on_stdout = function(_, data)

lua/gitlab/state.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ M.settings = {
2020
imply_local = false,
2121
},
2222
},
23+
connection_settings = {
24+
insecure = true,
25+
},
2326
attachment_dir = "",
2427
help = "g?",
2528
popup = {

0 commit comments

Comments
 (0)