As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit a014db05 authored by Archish's avatar Archish
Browse files

Lint fixes for personalaccesstoken pacakge

parent 3dba026f
No related branches found
No related tags found
No related merge requests found
// Package personalaccesstoken handles operations related to personal access tokens,
// including parsing arguments, requesting tokens, and formatting responses.
package personalaccesstoken
import (
Loading
Loading
@@ -18,10 +20,11 @@ import (
)
const (
usageText = "Usage: personal_access_token <name> <scope1[,scope2,...]> [ttl_days]"
usageText = "usage: personal_access_token <name> <scope1[,scope2,...]> [ttl_days]"
expiresDateFormat = "2006-01-02"
)
// Command represents a command to manage personal access tokens.
type Command struct {
Config *config.Config
Args *commandargs.Shell
Loading
Loading
@@ -35,6 +38,7 @@ type tokenArgs struct {
ExpiresDate string // Calculated, a TTL is passed from command-line.
}
// Execute processes the command, requests a personal access token, and prints the result.
func (c *Command) Execute(ctx context.Context) (context.Context, error) {
err := c.parseTokenArgs()
if err != nil {
Loading
Loading
@@ -50,9 +54,9 @@ func (c *Command) Execute(ctx context.Context) (context.Context, error) {
return ctx, err
}
fmt.Fprint(c.ReadWriter.Out, "Token: "+response.Token+"\n")
fmt.Fprint(c.ReadWriter.Out, "Scopes: "+strings.Join(response.Scopes, ",")+"\n")
fmt.Fprint(c.ReadWriter.Out, "Expires: "+response.ExpiresAt+"\n")
_, _ = fmt.Fprint(c.ReadWriter.Out, "Token: "+response.Token+"\n")
_, _ = fmt.Fprint(c.ReadWriter.Out, "Scopes: "+strings.Join(response.Scopes, ",")+"\n")
_, _ = fmt.Fprint(c.ReadWriter.Out, "Expires: "+response.ExpiresAt+"\n")
return ctx, nil
}
Loading
Loading
@@ -86,7 +90,7 @@ func (c *Command) parseTokenArgs() error {
TTL, err := strconv.Atoi(rawTTL)
if err != nil || TTL < 0 {
return fmt.Errorf("Invalid value for days_ttl: '%s'", rawTTL)
return fmt.Errorf("invalid value for days_ttl: '%s'", rawTTL)
}
c.TokenArgs.ExpiresDate = time.Now().AddDate(0, 0, TTL+1).Format(expiresDateFormat)
Loading
Loading
Loading
Loading
@@ -9,6 +9,7 @@ import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
Loading
Loading
@@ -28,7 +29,7 @@ func setup(t *testing.T) {
b, err := io.ReadAll(r.Body)
defer r.Body.Close()
require.NoError(t, err)
assert.NoError(t, err)
var requestBody *personalaccesstoken.RequestBody
json.Unmarshal(b, &requestBody)
Loading
Loading
@@ -111,7 +112,7 @@ func TestExecute(t *testing.T) {
arguments: &commandargs.Shell{
SshArgs: []string{cmdname, "newtoken", "api", "bad_ttl"},
},
expectedError: "Invalid value for days_ttl: 'bad_ttl'",
expectedError: "invalid value for days_ttl: 'bad_ttl'",
},
{
desc: "Without a ttl argument",
Loading
Loading
@@ -177,7 +178,7 @@ func TestExecute(t *testing.T) {
},
{
desc: "With unknown configured scopes",
PATConfig: config.PATConfig{AllowedScopes: []string{"read_reposotory"}},
PATConfig: config.PATConfig{AllowedScopes: []string{"unknown_repository"}},
arguments: &commandargs.Shell{
GitlabKeyId: "default",
SshArgs: []string{cmdname, "newtoken", "read_api,read_repository"},
Loading
Loading
@@ -191,7 +192,7 @@ func TestExecute(t *testing.T) {
PATConfig: config.PATConfig{AllowedScopes: []string{"read_api", "read_repository"}},
arguments: &commandargs.Shell{
GitlabKeyId: "default",
SshArgs: []string{cmdname, "newtoken", "read_api,read_reposotory"},
SshArgs: []string{cmdname, "newtoken", "read_api,unknown_repository"},
},
expectedOutput: "Token: YXuxvUgCEmeePY3G1YAa\n" +
"Scopes: read_api\n" +
Loading
Loading
@@ -199,12 +200,12 @@ func TestExecute(t *testing.T) {
},
{
desc: "With matching unknown requested scopes",
PATConfig: config.PATConfig{AllowedScopes: []string{"read_api", "read_reposotory"}},
PATConfig: config.PATConfig{AllowedScopes: []string{"read_api", "unknown_repository"}},
arguments: &commandargs.Shell{
GitlabKeyId: "invalidscope",
SshArgs: []string{cmdname, "newtoken", "read_reposotory"},
SshArgs: []string{cmdname, "newtoken", "unknown_repository"},
},
expectedError: "Invalid scope: 'read_reposotory'. Valid scopes are: [\"api\", \"create_runner\", \"k8s_proxy\", \"read_api\", \"read_registry\", \"read_repository\", \"read_user\", \"write_registry\", \"write_repository\"]",
expectedError: "Invalid scope: 'unknown_repository'. Valid scopes are: [\"api\", \"create_runner\", \"k8s_proxy\", \"read_api\", \"read_registry\", \"read_repository\", \"read_user\", \"write_registry\", \"write_repository\"]",
},
}
Loading
Loading
Loading
Loading
@@ -7,6 +7,7 @@ import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-shell/v14/client"
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
Loading
Loading
@@ -27,7 +28,7 @@ func initialize(t *testing.T) {
b, err := io.ReadAll(r.Body)
defer r.Body.Close()
require.NoError(t, err)
assert.NoError(t, err)
var requestBody *RequestBody
json.Unmarshal(b, &requestBody)
Loading
Loading
Loading
Loading
@@ -53,7 +53,7 @@ describe 'bin/gitlab-shell personal_access_token' do
remote:
remote: ========================================================================
remote:
remote: Usage: personal_access_token <name> <scope1[,scope2,...]> [ttl_days]
remote: usage: personal_access_token <name> <scope1[,scope2,...]> [ttl_days]
remote:
remote: ========================================================================
remote:
Loading
Loading
Loading
Loading
@@ -230,19 +230,6 @@ internal/command/lfstransfer/lfstransfer_test.go:1436:5: go-require: do not use
internal/command/lfstransfer/lfstransfer_test.go:1451:5: go-require: do not use require in http handlers (testifylint)
internal/command/lfstransfer/lfstransfer_test.go:1453:5: go-require: do not use require in http handlers (testifylint)
internal/command/lfstransfer/lfstransfer_test.go:1454:5: go-require: do not use require in http handlers (testifylint)
internal/command/personalaccesstoken/personalaccesstoken.go:1:1: package-comments: should have a package comment (revive)
internal/command/personalaccesstoken/personalaccesstoken.go:25:6: exported: exported type Command should have comment or be unexported (revive)
internal/command/personalaccesstoken/personalaccesstoken.go:38:1: exported: exported method Command.Execute should have comment or be unexported (revive)
internal/command/personalaccesstoken/personalaccesstoken.go:53:12: Error return value of `fmt.Fprint` is not checked (errcheck)
internal/command/personalaccesstoken/personalaccesstoken.go:54:12: Error return value of `fmt.Fprint` is not checked (errcheck)
internal/command/personalaccesstoken/personalaccesstoken.go:55:12: Error return value of `fmt.Fprint` is not checked (errcheck)
internal/command/personalaccesstoken/personalaccesstoken.go:62:10: ST1005: error strings should not be capitalized (stylecheck)
internal/command/personalaccesstoken/personalaccesstoken.go:89:10: ST1005: error strings should not be capitalized (stylecheck)
internal/command/personalaccesstoken/personalaccesstoken_test.go:31:5: go-require: do not use require in http handlers (testifylint)
internal/command/personalaccesstoken/personalaccesstoken_test.go:180:62: `reposotory` is a misspelling of `repository` (misspell)
internal/command/personalaccesstoken/personalaccesstoken_test.go:194:63: `reposotory` is a misspelling of `repository` (misspell)
internal/command/personalaccesstoken/personalaccesstoken_test.go:202:74: `reposotory` is a misspelling of `repository` (misspell)
internal/command/personalaccesstoken/personalaccesstoken_test.go:205:54: `reposotory` is a misspelling of `repository` (misspell)
internal/command/readwriter/readwriter.go:1:1: package-comments: should have a package comment (revive)
internal/command/readwriter/readwriter.go:7:6: exported: exported type ReadWriter should have comment or be unexported (revive)
internal/command/receivepack/gitalycall_test.go:24:4: S1038: should use t.Logf(...) instead of t.Log(fmt.Sprintf(...)) (gosimple)
Loading
Loading
@@ -380,7 +367,6 @@ internal/gitlabnet/lfstransfer/client.go:125: internal/gitlabnet/lfstransfer/cli
internal/gitlabnet/lfstransfer/client.go:214:1: exported: exported method Client.Lock should have comment or be unexported (revive)
internal/gitlabnet/lfstransfer/client.go:271:1: exported: exported method Client.Unlock should have comment or be unexported (revive)
internal/gitlabnet/lfstransfer/client.go:321:1: exported: exported method Client.ListLocksVerify should have comment or be unexported (revive)
internal/gitlabnet/personalaccesstoken/client_test.go:30:5: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/twofactorrecover/client_test.go:30:5: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/twofactorverify/client_test.go:24:3: go-require: do not use require in http handlers (testifylint)
internal/gitlabnet/twofactorverify/client_test.go:27:3: go-require: do not use require in http handlers (testifylint)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment