summaryrefslogtreecommitdiff
path: root/go/internal/gitlabnet
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2019-08-05 05:03:16 +0000
committerAsh McKenzie <amckenzie@gitlab.com>2019-08-05 05:03:16 +0000
commitc577eb9ed8bd0336870f7a83302f70821d510169 (patch)
treeed7f7281633d97933e4465a2ac0f86d62c9a216e /go/internal/gitlabnet
parented0460374a5ca13d9ea17c6a9c21151319b7fd53 (diff)
parent3b6f9f7583755e041e76142d7caf7716937907fa (diff)
downloadgitlab-shell-c577eb9ed8bd0336870f7a83302f70821d510169.tar.gz
Merge branch '181-migrate-gitlab-shell-checks-fallback' into 'master'
Support falling back to ruby version of checkers See merge request gitlab-org/gitlab-shell!318
Diffstat (limited to 'go/internal/gitlabnet')
-rw-r--r--go/internal/gitlabnet/accessverifier/client.go4
-rw-r--r--go/internal/gitlabnet/accessverifier/client_test.go10
-rw-r--r--go/internal/gitlabnet/discover/client.go2
-rw-r--r--go/internal/gitlabnet/lfsauthenticate/client.go4
-rw-r--r--go/internal/gitlabnet/lfsauthenticate/client_test.go10
-rw-r--r--go/internal/gitlabnet/twofactorrecover/client.go4
-rw-r--r--go/internal/gitlabnet/twofactorrecover/client_test.go8
7 files changed, 21 insertions, 21 deletions
diff --git a/go/internal/gitlabnet/accessverifier/client.go b/go/internal/gitlabnet/accessverifier/client.go
index d87c4ad..92a7434 100644
--- a/go/internal/gitlabnet/accessverifier/client.go
+++ b/go/internal/gitlabnet/accessverifier/client.go
@@ -71,7 +71,7 @@ func NewClient(config *config.Config) (*Client, error) {
return &Client{client: client}, nil
}
-func (c *Client) Verify(args *commandargs.CommandArgs, action commandargs.CommandType, repo string) (*Response, error) {
+func (c *Client) Verify(args *commandargs.Shell, action commandargs.CommandType, repo string) (*Response, error) {
request := &Request{Action: action, Repo: repo, Protocol: protocol, Changes: anyChanges}
if args.GitlabUsername != "" {
@@ -89,7 +89,7 @@ func (c *Client) Verify(args *commandargs.CommandArgs, action commandargs.Comman
return parse(response, args)
}
-func parse(hr *http.Response, args *commandargs.CommandArgs) (*Response, error) {
+func parse(hr *http.Response, args *commandargs.Shell) (*Response, error) {
response := &Response{}
if err := gitlabnet.ParseJSON(hr, response); err != nil {
return nil, err
diff --git a/go/internal/gitlabnet/accessverifier/client_test.go b/go/internal/gitlabnet/accessverifier/client_test.go
index 31175ae..f534185 100644
--- a/go/internal/gitlabnet/accessverifier/client_test.go
+++ b/go/internal/gitlabnet/accessverifier/client_test.go
@@ -57,16 +57,16 @@ func TestSuccessfulResponses(t *testing.T) {
testCases := []struct {
desc string
- args *commandargs.CommandArgs
+ args *commandargs.Shell
who string
}{
{
desc: "Provide key id within the request",
- args: &commandargs.CommandArgs{GitlabKeyId: "1"},
+ args: &commandargs.Shell{GitlabKeyId: "1"},
who: "key-1",
}, {
desc: "Provide username within the request",
- args: &commandargs.CommandArgs{GitlabUsername: "first"},
+ args: &commandargs.Shell{GitlabUsername: "first"},
who: "user-1",
},
}
@@ -86,7 +86,7 @@ func TestGetCustomAction(t *testing.T) {
client, cleanup := setup(t)
defer cleanup()
- args := &commandargs.CommandArgs{GitlabUsername: "custom"}
+ args := &commandargs.Shell{GitlabUsername: "custom"}
result, err := client.Verify(args, action, repo)
require.NoError(t, err)
@@ -134,7 +134,7 @@ func TestErrorResponses(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- args := &commandargs.CommandArgs{GitlabKeyId: tc.fakeId}
+ args := &commandargs.Shell{GitlabKeyId: tc.fakeId}
resp, err := client.Verify(args, action, repo)
require.EqualError(t, err, tc.expectedError)
diff --git a/go/internal/gitlabnet/discover/client.go b/go/internal/gitlabnet/discover/client.go
index 675670d..46ab2de 100644
--- a/go/internal/gitlabnet/discover/client.go
+++ b/go/internal/gitlabnet/discover/client.go
@@ -30,7 +30,7 @@ func NewClient(config *config.Config) (*Client, error) {
return &Client{config: config, client: client}, nil
}
-func (c *Client) GetByCommandArgs(args *commandargs.CommandArgs) (*Response, error) {
+func (c *Client) GetByCommandArgs(args *commandargs.Shell) (*Response, error) {
params := url.Values{}
if args.GitlabUsername != "" {
params.Add("username", args.GitlabUsername)
diff --git a/go/internal/gitlabnet/lfsauthenticate/client.go b/go/internal/gitlabnet/lfsauthenticate/client.go
index 2a7cb03..51cb7a4 100644
--- a/go/internal/gitlabnet/lfsauthenticate/client.go
+++ b/go/internal/gitlabnet/lfsauthenticate/client.go
@@ -13,7 +13,7 @@ import (
type Client struct {
config *config.Config
client *gitlabnet.GitlabClient
- args *commandargs.CommandArgs
+ args *commandargs.Shell
}
type Request struct {
@@ -30,7 +30,7 @@ type Response struct {
ExpiresIn int `json:"expires_in"`
}
-func NewClient(config *config.Config, args *commandargs.CommandArgs) (*Client, error) {
+func NewClient(config *config.Config, args *commandargs.Shell) (*Client, error) {
client, err := gitlabnet.GetClient(config)
if err != nil {
return nil, fmt.Errorf("Error creating http client: %v", err)
diff --git a/go/internal/gitlabnet/lfsauthenticate/client_test.go b/go/internal/gitlabnet/lfsauthenticate/client_test.go
index 7fd7aca..07484a7 100644
--- a/go/internal/gitlabnet/lfsauthenticate/client_test.go
+++ b/go/internal/gitlabnet/lfsauthenticate/client_test.go
@@ -59,22 +59,22 @@ func TestFailedRequests(t *testing.T) {
testCases := []struct {
desc string
- args *commandargs.CommandArgs
+ args *commandargs.Shell
expectedOutput string
}{
{
desc: "With bad response",
- args: &commandargs.CommandArgs{GitlabKeyId: "-1", CommandType: commandargs.UploadPack},
+ args: &commandargs.Shell{GitlabKeyId: "-1", CommandType: commandargs.UploadPack},
expectedOutput: "Parsing failed",
},
{
desc: "With API returns an error",
- args: &commandargs.CommandArgs{GitlabKeyId: "forbidden", CommandType: commandargs.UploadPack},
+ args: &commandargs.Shell{GitlabKeyId: "forbidden", CommandType: commandargs.UploadPack},
expectedOutput: "Internal API error (403)",
},
{
desc: "With API fails",
- args: &commandargs.CommandArgs{GitlabKeyId: "broken", CommandType: commandargs.UploadPack},
+ args: &commandargs.Shell{GitlabKeyId: "broken", CommandType: commandargs.UploadPack},
expectedOutput: "Internal API error (500)",
},
}
@@ -99,7 +99,7 @@ func TestSuccessfulRequests(t *testing.T) {
url, cleanup := testserver.StartHttpServer(t, requests)
defer cleanup()
- args := &commandargs.CommandArgs{GitlabKeyId: keyId, CommandType: commandargs.LfsAuthenticate}
+ args := &commandargs.Shell{GitlabKeyId: keyId, CommandType: commandargs.LfsAuthenticate}
client, err := NewClient(&config.Config{GitlabUrl: url}, args)
require.NoError(t, err)
diff --git a/go/internal/gitlabnet/twofactorrecover/client.go b/go/internal/gitlabnet/twofactorrecover/client.go
index f90a85c..37067db 100644
--- a/go/internal/gitlabnet/twofactorrecover/client.go
+++ b/go/internal/gitlabnet/twofactorrecover/client.go
@@ -36,7 +36,7 @@ func NewClient(config *config.Config) (*Client, error) {
return &Client{config: config, client: client}, nil
}
-func (c *Client) GetRecoveryCodes(args *commandargs.CommandArgs) ([]string, error) {
+func (c *Client) GetRecoveryCodes(args *commandargs.Shell) ([]string, error) {
requestBody, err := c.getRequestBody(args)
if err != nil {
@@ -65,7 +65,7 @@ func parse(hr *http.Response) ([]string, error) {
return response.RecoveryCodes, nil
}
-func (c *Client) getRequestBody(args *commandargs.CommandArgs) (*RequestBody, error) {
+func (c *Client) getRequestBody(args *commandargs.Shell) (*RequestBody, error) {
client, err := discover.NewClient(c.config)
if err != nil {
diff --git a/go/internal/gitlabnet/twofactorrecover/client_test.go b/go/internal/gitlabnet/twofactorrecover/client_test.go
index 4b15ac5..a560fb1 100644
--- a/go/internal/gitlabnet/twofactorrecover/client_test.go
+++ b/go/internal/gitlabnet/twofactorrecover/client_test.go
@@ -85,7 +85,7 @@ func TestGetRecoveryCodesByKeyId(t *testing.T) {
client, cleanup := setup(t)
defer cleanup()
- args := &commandargs.CommandArgs{GitlabKeyId: "0"}
+ args := &commandargs.Shell{GitlabKeyId: "0"}
result, err := client.GetRecoveryCodes(args)
assert.NoError(t, err)
assert.Equal(t, []string{"recovery 1", "codes 1"}, result)
@@ -95,7 +95,7 @@ func TestGetRecoveryCodesByUsername(t *testing.T) {
client, cleanup := setup(t)
defer cleanup()
- args := &commandargs.CommandArgs{GitlabUsername: "jane-doe"}
+ args := &commandargs.Shell{GitlabUsername: "jane-doe"}
result, err := client.GetRecoveryCodes(args)
assert.NoError(t, err)
assert.Equal(t, []string{"recovery 2", "codes 2"}, result)
@@ -105,7 +105,7 @@ func TestMissingUser(t *testing.T) {
client, cleanup := setup(t)
defer cleanup()
- args := &commandargs.CommandArgs{GitlabKeyId: "1"}
+ args := &commandargs.Shell{GitlabKeyId: "1"}
_, err := client.GetRecoveryCodes(args)
assert.Equal(t, "missing user", err.Error())
}
@@ -138,7 +138,7 @@ func TestErrorResponses(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- args := &commandargs.CommandArgs{GitlabKeyId: tc.fakeId}
+ args := &commandargs.Shell{GitlabKeyId: tc.fakeId}
resp, err := client.GetRecoveryCodes(args)
assert.EqualError(t, err, tc.expectedError)