diff --git a/boshupdate/bosh.go b/boshupdate/bosh.go index a1bd5202..988985f2 100644 --- a/boshupdate/bosh.go +++ b/boshupdate/bosh.go @@ -5,7 +5,6 @@ import ( "github.com/cloudfoundry/bosh-cli/director" "github.com/cloudfoundry/bosh-cli/uaa" "github.com/cloudfoundry/bosh-utils/logger" - "io/ioutil" "os" "regexp" ) @@ -40,7 +39,7 @@ func (c *BoshConfig) validate() error { if len(c.CaCert) == 0 { c.CaCert = os.Getenv("BOSH_CA_CERT") } else { - val, err := ioutil.ReadFile(c.CaCert) + val, err := os.ReadFile(c.CaCert) if err != nil { return fmt.Errorf("unable to read file at path %s", c.CaCert) } @@ -74,8 +73,7 @@ func buildLogger(config BoshConfig) (logger.Logger, error) { if err != nil { return nil, err } - logger := logger.NewLogger(level) - return logger, nil + return logger.NewLogger(level), nil } func buildUAA(url string, config BoshConfig, logger logger.Logger) (uaa.UAA, error) { @@ -111,12 +109,12 @@ func NewDirector(config BoshConfig) (director.Director, error) { os.Setenv("BOSH_ALL_PROXY", config.Proxy) } - logger, err := buildLogger(config) + log, err := buildLogger(config) if err != nil { return nil, err } - infos, err := getDirectorInfo(config, logger) + infos, err := getDirectorInfo(config, log) if err != nil { return nil, err } @@ -132,13 +130,13 @@ func NewDirector(config BoshConfig) (director.Director, error) { if !ok { return nil, fmt.Errorf("Expected UAA URL '%s' to be a string", uaaURL) } - uaaCli, err := buildUAA(uaaURLStr, config, logger) + uaaCli, err := buildUAA(uaaURLStr, config, log) if err != nil { return nil, err } directorConfig.TokenFunc = uaa.NewClientTokenSession(uaaCli).TokenFunc } - factory := director.NewFactory(logger) + factory := director.NewFactory(log) return factory.New(directorConfig, director.NewNoopTaskReporter(), director.NewNoopFileReporter()) } diff --git a/boshupdate/config.go b/boshupdate/config.go index fe19e31d..cc192503 100644 --- a/boshupdate/config.go +++ b/boshupdate/config.go @@ -6,7 +6,6 @@ import ( log "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" "io" - "io/ioutil" "os" "regexp" "strings" @@ -162,7 +161,7 @@ func (c *Config) Validate() error { // NewConfig - Creates and validates config from given reader func NewConfig(file io.Reader) *Config { - content, err := ioutil.ReadAll(file) + content, err := io.ReadAll(file) if err != nil { log.Fatalf("unable to read configuration file : %s", err) os.Exit(1) diff --git a/boshupdate/manager.go b/boshupdate/manager.go index 4e2e3b6b..c6ebe3b4 100644 --- a/boshupdate/manager.go +++ b/boshupdate/manager.go @@ -12,7 +12,7 @@ import ( log "github.com/sirupsen/logrus" "golang.org/x/oauth2" "gopkg.in/yaml.v2" - "io/ioutil" + "io" "regexp" "sort" ) @@ -32,7 +32,7 @@ func NewManager(config Config) (*Manager, error) { &oauth2.Token{AccessToken: config.Github.Token}, ) tc := oauth2.NewClient(ctx, ts) - director, err := NewDirector(config.Bosh) + newDirector, err := NewDirector(config.Bosh) if err != nil { return nil, errors.Wrapf(err, "unable to create director client") } @@ -41,7 +41,7 @@ func NewManager(config Config) (*Manager, error) { config: config, client: github.NewClient(tc), ctx: ctx, - director: director, + director: newDirector, }, nil } @@ -122,8 +122,8 @@ func (a *Manager) GetGenericReleases() []GenericReleaseData { results := []GenericReleaseData{} for name, item := range a.config.Github.GenericReleases { entry := log.WithFields(log.Fields{ - "name": name, - "repo": item.Repo, + "name": name, + "repo": item.Repo, "owner": item.Owner, }) entry.Debugf("processing github release") @@ -162,8 +162,8 @@ func (a *Manager) GetManifestReleases() []ManifestReleaseData { entry := log.WithFields(log.Fields{ "deployment": name, - "repo": item.Repo, - "owner": item.Owner, + "repo": item.Repo, + "owner": item.Owner, }) entry.Debugf("processing bosh deployment") @@ -186,9 +186,9 @@ func (a *Manager) GetManifestReleases() []ManifestReleaseData { entry = log.WithFields(log.Fields{ "deployment": name, - "repo": item.Repo, - "owner": item.Owner, - "version": target.LatestVersion.Version, + "repo": item.Repo, + "owner": item.Owner, + "version": target.LatestVersion.Version, }) if len(item.Manifest) == 0 { @@ -242,8 +242,8 @@ func (a *Manager) listReleases(item GenericReleaseConfig) ([]*github.RepositoryR } } -// 1. For some reason, we get empty date when reading tag object -// We fetch information for corresponding sha to get tag date +// 1. For some reason, we get empty date when reading tag object +// We fetch information for corresponding sha to get tag date func (a *Manager) getRefs(item GenericReleaseConfig) ([]GithubRef, error) { res := []GithubRef{} release := item.HasType("release") @@ -312,7 +312,7 @@ func (a *Manager) getContent(ref string, item ManifestReleaseConfig, path string } defer stream.Close() - content, err := ioutil.ReadAll(stream) + content, err := io.ReadAll(stream) if err != nil { return []byte{}, errors.Wrapf(err, "could read remote stream") } @@ -335,8 +335,8 @@ func (a *Manager) createVersions(refs []GithubRef, last GithubRef, item GenericR // RenderManifest - func (a *Manager) RenderManifest(manifest []byte, item ManifestReleaseData) ([]byte, error) { entry := log.WithFields(log.Fields{ - "name": item.Name, - "repo": item.Repo, + "name": item.Name, + "repo": item.Repo, "owner": item.Owner, }) entry.Debugf("rendering final manifest") diff --git a/cli/main.go b/cli/main.go index 6bc31241..19179859 100644 --- a/cli/main.go +++ b/cli/main.go @@ -2,17 +2,17 @@ package main import ( "fmt" + "github.com/alecthomas/kingpin/v2" "github.com/orange-cloudfoundry/boshupdate_exporter/boshupdate" - log "github.com/sirupsen/logrus" "github.com/prometheus/common/version" - "github.com/alecthomas/kingpin/v2" + log "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" "os" ) var ( configFile = kingpin.Flag("config", "Configuration file path").Required().File() - logLevel = kingpin.Flag( + logLevel = kingpin.Flag( "log.level", "Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]", ).Default("info").String() logStream = kingpin.Flag( diff --git a/exporter/main.go b/exporter/main.go index 0a38bed4..329548b5 100644 --- a/exporter/main.go +++ b/exporter/main.go @@ -1,11 +1,11 @@ package main import ( + "github.com/alecthomas/kingpin/v2" "github.com/orange-cloudfoundry/boshupdate_exporter/boshupdate" "github.com/prometheus/client_golang/prometheus/promhttp" - log "github.com/sirupsen/logrus" "github.com/prometheus/common/version" - "github.com/alecthomas/kingpin/v2" + log "github.com/sirupsen/logrus" "net/http" "os" "time"