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.
This commit is contained in:
committed by
GitHub
parent
670f08849f
commit
4f1fe4ae25
@@ -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 = "<Esc>",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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*
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -20,6 +20,9 @@ M.settings = {
|
||||
imply_local = false,
|
||||
},
|
||||
},
|
||||
connection_settings = {
|
||||
insecure = true,
|
||||
},
|
||||
attachment_dir = "",
|
||||
help = "g?",
|
||||
popup = {
|
||||
|
||||
Reference in New Issue
Block a user