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
Unverified Commit fbc2c2cd authored by Ash McKenzie's avatar Ash McKenzie Committed by GitLab
Browse files

Merge branch '795-gitlab-shell-check-lint' into 'main'

parents b15c5c73 151a2216
No related branches found
No related tags found
No related merge requests found
// Package command handles command creation and initialization in GitLab Shell.
package command
import (
Loading
Loading
@@ -9,6 +10,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/config"
)
// New creates a new command based on provided arguments, config, and I/O.
func New(arguments []string, config *config.Config, readWriter *readwriter.ReadWriter) (command.Command, error) {
args, err := Parse(arguments)
if err != nil {
Loading
Loading
@@ -22,6 +24,7 @@ func New(arguments []string, config *config.Config, readWriter *readwriter.ReadW
return nil, disallowedcommand.Error
}
// Parse parses command-line arguments into a CommandArgs structure.
func Parse(arguments []string) (*commandargs.AuthorizedPrincipals, error) {
args := &commandargs.AuthorizedPrincipals{Arguments: arguments}
Loading
Loading
// Package main is the entry point for the GitLab Shell authorized principals check command.
package main
import (
Loading
Loading
@@ -21,6 +22,10 @@ var (
)
func main() {
os.Exit(run())
}
func run() int {
command.CheckForVersionFlag(os.Args, Version, BuildTime)
readWriter := &readwriter.ReadWriter{
Loading
Loading
@@ -31,32 +36,33 @@ func main() {
executable, err := executable.New(executable.AuthorizedPrincipalsCheck)
if err != nil {
fmt.Fprintln(readWriter.ErrOut, "Failed to determine executable, exiting")
os.Exit(1)
_, _ = fmt.Fprintln(readWriter.ErrOut, "Failed to determine executable, exiting")
return 1
}
config, err := config.NewFromDirExternal(executable.RootDir)
if err != nil {
fmt.Fprintln(readWriter.ErrOut, "Failed to read config, exiting")
os.Exit(1)
_, _ = fmt.Fprintln(readWriter.ErrOut, "Failed to read config, exiting")
return 1
}
logCloser := logger.Configure(config)
defer logCloser.Close()
defer logCloser.Close() //nolint:errcheck
cmd, err := cmd.New(os.Args[1:], config, readWriter)
if err != nil {
// For now this could happen if `SSH_CONNECTION` is not set on
// the environment
fmt.Fprintf(readWriter.ErrOut, "%v\n", err)
os.Exit(1)
_, _ = fmt.Fprintf(readWriter.ErrOut, "%v\n", err)
return 1
}
ctx, finished := command.Setup(executable.Name, config)
defer finished()
if ctx, err = cmd.Execute(ctx); err != nil {
if _, err = cmd.Execute(ctx); err != nil {
console.DisplayWarningMessage(err.Error(), readWriter.ErrOut)
os.Exit(1)
return 1
}
return 0
}
// Package main is the entry point for the GitLab Shell health check command.
package main
import (
Loading
Loading
@@ -20,6 +21,10 @@ var (
)
func main() {
os.Exit(run())
}
func run() int {
command.CheckForVersionFlag(os.Args, Version, BuildTime)
readWriter := &readwriter.ReadWriter{
Loading
Loading
@@ -28,32 +33,38 @@ func main() {
ErrOut: os.Stderr,
}
exitOnError := func(err error, message string) int {
if err != nil {
_, _ = fmt.Fprintf(readWriter.ErrOut, "%s: %v\n", message, err)
return 1
}
return 0
}
executable, err := executable.New(executable.Healthcheck)
if err != nil {
fmt.Fprintln(readWriter.ErrOut, "Failed to determine executable, exiting")
os.Exit(1)
if code := exitOnError(err, "Failed to determine executable, exiting"); code != 0 {
return code
}
config, err := config.NewFromDirExternal(executable.RootDir)
if err != nil {
fmt.Fprintln(readWriter.ErrOut, "Failed to read config, exiting")
os.Exit(1)
if code := exitOnError(err, "Failed to read config, exiting"); code != 0 {
return code
}
logCloser := logger.Configure(config)
defer logCloser.Close()
defer logCloser.Close() //nolint:errcheck
cmd, err := checkCmd.New(config, readWriter)
if err != nil {
fmt.Fprintf(readWriter.ErrOut, "%v\n", err)
os.Exit(1)
if code := exitOnError(err, "Failed to create command"); code != 0 {
return code
}
ctx, finished := command.Setup(executable.Name, config)
defer finished()
if ctx, err = cmd.Execute(ctx); err != nil {
fmt.Fprintf(readWriter.ErrOut, "%v\n", err)
os.Exit(1)
if _, err = cmd.Execute(ctx); err != nil {
_, _ = fmt.Fprintf(readWriter.ErrOut, "%v\n", err)
return 1
}
return 0
}
Loading
Loading
@@ -42,24 +42,6 @@ client/transport.go:58:1: exported: exported function DefaultTransport should ha
client/transport.go:62:1: exported: exported function NewTransport should have comment or be unexported (revive)
cmd/gitlab-shell-authorized-keys-check/main.go:40:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
cmd/gitlab-shell-authorized-keys-check/main.go:43:13: unnecessary conversion (unconvert)
cmd/gitlab-shell-authorized-principals-check/command/command.go:1:1: package-comments: should have a package comment (revive)
cmd/gitlab-shell-authorized-principals-check/command/command.go:12:1: exported: exported function New should have comment or be unexported (revive)
cmd/gitlab-shell-authorized-principals-check/command/command.go:25:1: exported: exported function Parse should have comment or be unexported (revive)
cmd/gitlab-shell-authorized-principals-check/main.go:1:1: package-comments: should have a package comment (revive)
cmd/gitlab-shell-authorized-principals-check/main.go:34:15: Error return value of `fmt.Fprintln` is not checked (errcheck)
cmd/gitlab-shell-authorized-principals-check/main.go:40:15: Error return value of `fmt.Fprintln` is not checked (errcheck)
cmd/gitlab-shell-authorized-principals-check/main.go:45:23: Error return value of `logCloser.Close` is not checked (errcheck)
cmd/gitlab-shell-authorized-principals-check/main.go:51:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
cmd/gitlab-shell-authorized-principals-check/main.go:52:3: exitAfterDefer: os.Exit will exit, and `defer logCloser.Close()` will not run (gocritic)
cmd/gitlab-shell-authorized-principals-check/main.go:58:5: ineffectual assignment to ctx (ineffassign)
cmd/gitlab-shell-check/main.go:1:1: package-comments: should have a package comment (revive)
cmd/gitlab-shell-check/main.go:33:15: Error return value of `fmt.Fprintln` is not checked (errcheck)
cmd/gitlab-shell-check/main.go:39:15: Error return value of `fmt.Fprintln` is not checked (errcheck)
cmd/gitlab-shell-check/main.go:44:23: Error return value of `logCloser.Close` is not checked (errcheck)
cmd/gitlab-shell-check/main.go:48:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
cmd/gitlab-shell-check/main.go:49:3: exitAfterDefer: os.Exit will exit, and `defer logCloser.Close()` will not run (gocritic)
cmd/gitlab-shell-check/main.go:55:5: ineffectual assignment to ctx (ineffassign)
cmd/gitlab-shell-check/main.go:56:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
cmd/gitlab-shell/command/command.go:74: cmd/gitlab-shell/command/command.go:74: Line contains TODO/BUG/FIXME/NOTE/OPTIMIZE/HACK: "FIXME: When 1.21+ only Golang is support..." (godox)
cmd/gitlab-shell/main.go:1:1: package-comments: should have a package comment (revive)
cmd/gitlab-shell/main.go:42:15: Error return value of `fmt.Fprintln` is not checked (errcheck)
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