Read about our upcoming Code of Conduct on this issue

Commit edce299c authored by Nick Thomas's avatar Nick Thomas
Browse files

Merge branch 'update/newclientopts' into 'main'

refactor: update usage of NewHTTPClient to NewHTTPClientWithOpts

Closes #484

See merge request gitlab-org/gitlab-shell!507
......@@ -59,7 +59,8 @@
secret := "sssh, it's a secret"
httpClient := NewHTTPClient(url, tc.relativeURLRoot, tc.caFile, "", false, 1)
httpClient, err := NewHTTPClientWithOpts(url, tc.relativeURLRoot, tc.caFile, "", false, 1, nil)
require.NoError(t, err)
client, err := NewGitlabNetClient("", "", secret, httpClient)
require.NoError(t, err)
......
......@@ -17,7 +17,8 @@
func TestReadTimeout(t *testing.T) {
expectedSeconds := uint64(300)
client := NewHTTPClient("http://localhost:3000", "", "", "", false, expectedSeconds)
client, err := NewHTTPClientWithOpts("http://localhost:3000", "", "", "", false, expectedSeconds, nil)
require.NoError(t, err)
require.NotNil(t, client)
require.Equal(t, time.Duration(expectedSeconds)*time.Second, client.Client.Timeout)
......@@ -122,7 +123,8 @@
func setup(t *testing.T, username, password string, requests []testserver.TestRequestHandler) *GitlabNetClient {
url := testserver.StartHttpServer(t, requests)
httpClient := NewHTTPClient(url, "", "", "", false, 1)
httpClient, err := NewHTTPClientWithOpts(url, "", "", "", false, 1, nil)
require.NoError(t, err)
client, err := NewGitlabNetClient(username, password, "", httpClient)
require.NoError(t, err)
......
......@@ -58,6 +58,7 @@
Server ServerConfig `yaml:"sshd"`
httpClient *client.HttpClient
httpClientErr error
httpClientOnce sync.Once
}
......@@ -95,5 +96,5 @@
}
}
func (c *Config) HttpClient() *client.HttpClient {
func (c *Config) HttpClient() (*client.HttpClient, error) {
c.httpClientOnce.Do(func() {
......@@ -99,8 +100,8 @@
c.httpClientOnce.Do(func() {
client := client.NewHTTPClient(
client, err := client.NewHTTPClientWithOpts(
c.GitlabUrl,
c.GitlabRelativeURLRoot,
c.HttpSettings.CaFile,
c.HttpSettings.CaPath,
c.HttpSettings.SelfSignedCert,
c.HttpSettings.ReadTimeoutSeconds,
......@@ -101,7 +102,8 @@
c.GitlabUrl,
c.GitlabRelativeURLRoot,
c.HttpSettings.CaFile,
c.HttpSettings.CaPath,
c.HttpSettings.SelfSignedCert,
c.HttpSettings.ReadTimeoutSeconds,
nil,
)
......@@ -107,4 +109,8 @@
)
if err != nil {
c.httpClientErr = err
return
}
tr := client.Transport
client.Transport = promhttp.InstrumentRoundTripperDuration(metrics.HttpRequestDuration, tr)
......@@ -112,7 +118,7 @@
c.httpClient = client
})
return c.httpClient
return c.httpClient, c.httpClientErr
}
// NewFromDirExternal returns a new config from a given root dir. It also applies defaults appropriate for
......
......@@ -29,5 +29,6 @@
url := testserver.StartHttpServer(t, []testserver.TestRequestHandler{})
config := &Config{GitlabUrl: url}
client := config.HttpClient()
client, err := config.HttpClient()
require.NoError(t, err)
......@@ -33,5 +34,5 @@
_, err := client.Get("http://host.com/path")
_, err = client.Get("http://host.com/path")
require.NoError(t, err)
ms, err := prometheus.DefaultGatherer.Gather()
......
......@@ -15,7 +15,10 @@
)
func GetClient(config *config.Config) (*client.GitlabNetClient, error) {
httpClient := config.HttpClient()
httpClient, err := config.HttpClient()
if err != nil {
return nil, err
}
if httpClient == nil {
return nil, fmt.Errorf("Unsupported protocol")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment