Skip to content

Commit e480a63

Browse files
ashmckenzieArchish27
authored andcommitted
Merge branch '794-authorizedprincipals-lint' into 'main'
Lint fixes for authorized keys and principal packages Closes #794 See merge request https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/1151 Merged-by: Ash McKenzie <[email protected]> Approved-by: Ash McKenzie <[email protected]> Co-authored-by: Archish <[email protected]>
2 parents d7dcb4b + b946259 commit e480a63

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

internal/command/authorizedkeys/authorized_keys.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package authorizedkeys handles fetching and printing authorized SSH keys.
12
package authorizedkeys
23

34
import (
@@ -12,12 +13,14 @@ import (
1213
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/keyline"
1314
)
1415

16+
// Command contains the configuration, arguments, and I/O interfaces.
1517
type Command struct {
1618
Config *config.Config
1719
Args *commandargs.AuthorizedKeys
1820
ReadWriter *readwriter.ReadWriter
1921
}
2022

23+
// Execute runs the command to fetch and print the authorized SSH key.
2124
func (c *Command) Execute(ctx context.Context) (context.Context, error) {
2225
// Do and return nothing when the expected and actual user don't match.
2326
// This can happen when the user in sshd_config doesn't match the user
@@ -38,7 +41,7 @@ func (c *Command) Execute(ctx context.Context) (context.Context, error) {
3841
func (c *Command) printKeyLine(ctx context.Context) error {
3942
response, err := c.getAuthorizedKey(ctx)
4043
if err != nil {
41-
fmt.Fprintln(c.ReadWriter.Out, fmt.Sprintf("# No key was found for %s", c.Args.Key))
44+
_, _ = fmt.Fprintf(c.ReadWriter.Out, "# No key was found for %s\n", c.Args.Key)
4245
return nil
4346
}
4447

@@ -47,7 +50,7 @@ func (c *Command) printKeyLine(ctx context.Context) error {
4750
return err
4851
}
4952

50-
fmt.Fprintln(c.ReadWriter.Out, keyLine.ToString())
53+
_, _ = fmt.Fprintln(c.ReadWriter.Out, keyLine.ToString())
5154

5255
return nil
5356
}

internal/command/authorizedprincipals/authorized_principals.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package authorizedprincipals handles printing authorized principals in GitLab Shell.
12
package authorizedprincipals
23

34
import (
@@ -10,12 +11,14 @@ import (
1011
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/keyline"
1112
)
1213

14+
// Command contains the configuration, arguments, and I/O interfaces.
1315
type Command struct {
1416
Config *config.Config
1517
Args *commandargs.AuthorizedPrincipals
1618
ReadWriter *readwriter.ReadWriter
1719
}
1820

21+
// Execute runs the command to print authorized principals.
1922
func (c *Command) Execute(ctx context.Context) (context.Context, error) {
2023
if err := c.printPrincipalLines(); err != nil {
2124
return ctx, err
@@ -42,7 +45,7 @@ func (c *Command) printPrincipalLine(principal string) error {
4245
return err
4346
}
4447

45-
fmt.Fprintln(c.ReadWriter.Out, principalKeyLine.ToString())
48+
_, _ = fmt.Fprintln(c.ReadWriter.Out, principalKeyLine.ToString())
4649

4750
return nil
4851
}

support/lint_last_known_acceptable.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,7 @@ cmd/gitlab-sshd/main.go:30:5: var-naming: var gitlabUrl should be gitlabURL (rev
7878
cmd/gitlab-sshd/main.go:44: Function 'main' is too long (73 > 60) (funlen)
7979
cmd/gitlab-sshd/main.go:70:23: Error return value of `logCloser.Close` is not checked (errcheck)
8080
cmd/gitlab-sshd/main.go:108:18: Error return value of `server.Shutdown` is not checked (errcheck)
81-
internal/command/authorizedkeys/authorized_keys.go:1:1: package-comments: should have a package comment (revive)
82-
internal/command/authorizedkeys/authorized_keys.go:15:6: exported: exported type Command should have comment or be unexported (revive)
83-
internal/command/authorizedkeys/authorized_keys.go:21:1: exported: exported method Command.Execute should have comment or be unexported (revive)
84-
internal/command/authorizedkeys/authorized_keys.go:26: internal/command/authorizedkeys/authorized_keys.go:26: Line contains TODO/BUG/FIXME/NOTE/OPTIMIZE/HACK: "TODO: Log this event once we have a cons..." (godox)
85-
internal/command/authorizedkeys/authorized_keys.go:41:15: Error return value of `fmt.Fprintln` is not checked (errcheck)
86-
internal/command/authorizedkeys/authorized_keys.go:50:14: Error return value of `fmt.Fprintln` is not checked (errcheck)
87-
internal/command/authorizedprincipals/authorized_principals.go:1:1: package-comments: should have a package comment (revive)
88-
internal/command/authorizedprincipals/authorized_principals.go:13:6: exported: exported type Command should have comment or be unexported (revive)
89-
internal/command/authorizedprincipals/authorized_principals.go:19:1: exported: exported method Command.Execute should have comment or be unexported (revive)
90-
internal/command/authorizedprincipals/authorized_principals.go:45:14: Error return value of `fmt.Fprintln` is not checked (errcheck)
81+
internal/command/authorizedkeys/authorized_keys.go:29: internal/command/authorizedkeys/authorized_keys.go:29: Line contains TODO/BUG/FIXME/NOTE/OPTIMIZE/HACK: "TODO: Log this event once we have a cons..." (godox)
9182
internal/command/command.go:1:1: package-comments: should have a package comment (revive)
9283
internal/command/command.go:15:6: exported: exported type Command should have comment or be unexported (revive)
9384
internal/command/command.go:19:6: exported: exported type LogMetadata should have comment or be unexported (revive)

0 commit comments

Comments
 (0)