From d0ac9f14aba908af2da273ed2c6e34ea6521cf41 Mon Sep 17 00:00:00 2001 From: Fabrizio Steiner Date: Fri, 2 Mar 2018 22:37:50 +0100 Subject: [PATCH] some linting --- container/client.go | 3 +- container/container.go | 2 +- container/filters_test.go | 9 +++--- container/mocks/FilterableContainer.go | 1 - container/trust.go | 43 ++++++++++---------------- 5 files changed, 23 insertions(+), 35 deletions(-) diff --git a/container/client.go b/container/client.go index 5a75163..476e3ca 100644 --- a/container/client.go +++ b/container/client.go @@ -216,10 +216,9 @@ func (client dockerClient) IsContainerStale(c Container) (bool, error) { if newImageInfo.ID != oldImageInfo.ID { log.Infof("Found new %s image (%s)", imageName, newImageInfo.ID) return true, nil - } else { - log.Debugf("No new images found for %s", c.Name()) } + log.Debugf("No new images found for %s", c.Name()) return false, nil } diff --git a/container/container.go b/container/container.go index e620d92..7453507 100644 --- a/container/container.go +++ b/container/container.go @@ -155,7 +155,7 @@ func (c Container) runtimeConfig() *dockercontainer.Config { config.Volumes = structMapSubtract(config.Volumes, imageConfig.Volumes) // subtract ports exposed in image from container - for k, _ := range config.ExposedPorts { + for k := range config.ExposedPorts { if _, ok := imageConfig.ExposedPorts[k]; ok { delete(config.ExposedPorts, k) } diff --git a/container/filters_test.go b/container/filters_test.go index 1129be3..25a0118 100644 --- a/container/filters_test.go +++ b/container/filters_test.go @@ -26,10 +26,11 @@ func TestNoFilter(t *testing.T) { } func TestFilterByNames(t *testing.T) { - filter := filterByNames(make([]string, 0), nil) + var names []string + + filter := filterByNames(names, nil) assert.Nil(t, filter) - names := make([]string, 0) names = append(names, "test") filter = filterByNames(names, noFilter) @@ -87,7 +88,7 @@ func TestFilterByDisabledLabel(t *testing.T) { } func TestBuildFilter(t *testing.T) { - names := make([]string, 0) + var names []string names = append(names, "test") filter := BuildFilter(names, false) @@ -123,7 +124,7 @@ func TestBuildFilter(t *testing.T) { } func TestBuildFilterEnableLabel(t *testing.T) { - names := make([]string, 0) + var names []string names = append(names, "test") filter := BuildFilter(names, true) diff --git a/container/mocks/FilterableContainer.go b/container/mocks/FilterableContainer.go index 15f9db5..508bd7c 100644 --- a/container/mocks/FilterableContainer.go +++ b/container/mocks/FilterableContainer.go @@ -1,4 +1,3 @@ -// Code generated by mockery v1.0.0 package mocks import mock "github.com/stretchr/testify/mock" diff --git a/container/trust.go b/container/trust.go index 90ba335..e388302 100644 --- a/container/trust.go +++ b/container/trust.go @@ -5,20 +5,18 @@ import ( "os" "strings" - log "github.com/sirupsen/logrus" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/reference" "github.com/docker/docker/cli/command" "github.com/docker/docker/cliconfig" "github.com/docker/docker/cliconfig/configfile" "github.com/docker/docker/cliconfig/credentials" + log "github.com/sirupsen/logrus" ) -/** - * Return an encoded auth config for the given registry - * loaded from environment variables or docker config - * as available in that order - */ +// EncodedAuth returns an encoded auth config for the given registry +// loaded from environment variables or docker config +// as available in that order func EncodedAuth(ref string) (string, error) { auth, err := EncodedEnvAuth(ref) if err != nil { @@ -27,11 +25,9 @@ func EncodedAuth(ref string) (string, error) { return auth, err } -/* - * Return an encoded auth config for the given registry - * loaded from environment variables - * Returns an error if authentication environment variables have not been set - */ +// EncodedEnvAuth returns an encoded auth config for the given registry +// loaded from environment variables +// Returns an error if authentication environment variables have not been set func EncodedEnvAuth(ref string) (string, error) { username := os.Getenv("REPO_USER") password := os.Getenv("REPO_PASS") @@ -42,17 +38,14 @@ func EncodedEnvAuth(ref string) (string, error) { } log.Debugf("Loaded auth credentials %s for %s", auth, ref) return EncodeAuth(auth) - } else { - return "", errors.New("Registry auth environment variables (REPO_USER, REPO_PASS) not set") } + return "", errors.New("Registry auth environment variables (REPO_USER, REPO_PASS) not set") } -/* - * Return an encoded auth config for the given registry - * loaded from the docker config - * Returns an empty string if credentials cannot be found for the referenced server - * The docker config must be mounted on the container - */ +// EncodedConfigAuth returns an encoded auth config for the given registry +// loaded from the docker config +// Returns an empty string if credentials cannot be found for the referenced server +// The docker config must be mounted on the container func EncodedConfigAuth(ref string) (string, error) { server, err := ParseServerAddress(ref) configDir := os.Getenv("DOCKER_CONFIG") @@ -92,18 +85,14 @@ func CredentialsStore(configFile configfile.ConfigFile) credentials.Store { return credentials.NewFileStore(&configFile) } -/* - * Base64 encode an AuthConfig struct for transmission over HTTP - */ +// EncodeAuth Base64 encode an AuthConfig struct for transmission over HTTP func EncodeAuth(auth types.AuthConfig) (string, error) { return command.EncodeAuthToBase64(auth) } -/** - * This function will be invoked if an AuthConfig is rejected - * It could be used to return a new value for the "X-Registry-Auth" authentication header, - * but there's no point trying again with the same value as used in AuthConfig - */ +// DefaultAuthHandler will be invoked if an AuthConfig is rejected +// It could be used to return a new value for the "X-Registry-Auth" authentication header, +// but there's no point trying again with the same value as used in AuthConfig func DefaultAuthHandler() (string, error) { log.Debug("Authentication request was rejected. Trying again without authentication") return "", nil