Skip to content

Commit

Permalink
enable more linters
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
  • Loading branch information
mmorel-35 committed Apr 21, 2023
1 parent 2f04d2e commit 185fc9b
Show file tree
Hide file tree
Showing 41 changed files with 545 additions and 448 deletions.
1 change: 1 addition & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v3.4.0
with:
args: --verbose
version: v1.51.2
20 changes: 20 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
linters:
enable:
- gocritic
- gofumpt
- goimports
- gosimple
- misspell
- revive
- unconvert
- unused

linters-settings:
goimports:
local-prefixes: github.com/prometheus

output:
sort-results: true

run:
timeout: 5m
7 changes: 3 additions & 4 deletions config/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func SerialNumber() *big.Int {
serialNumber.Add(&serial, big.NewInt(1))

return &serial

}

func GenerateCertificateAuthority(commonName string, parentCert *x509.Certificate, parentKey *rsa.PrivateKey) (*x509.Certificate, *rsa.PrivateKey, error) {
Expand Down Expand Up @@ -170,7 +169,7 @@ func writeCertificateAndKey(path string, cert *x509.Certificate, key *rsa.Privat
return err
}

if err := os.WriteFile(fmt.Sprintf("%s.crt", path), b.Bytes(), 0644); err != nil {
if err := os.WriteFile(fmt.Sprintf("%s.crt", path), b.Bytes(), 0o644); err != nil {
return err
}

Expand All @@ -179,7 +178,7 @@ func writeCertificateAndKey(path string, cert *x509.Certificate, key *rsa.Privat
return err
}

if err := os.WriteFile(fmt.Sprintf("%s.key", path), b.Bytes(), 0644); err != nil {
if err := os.WriteFile(fmt.Sprintf("%s.key", path), b.Bytes(), 0o644); err != nil {
return err
}

Expand Down Expand Up @@ -239,7 +238,7 @@ func main() {
log.Fatal(err)
}

if err := os.WriteFile("testdata/tls-ca-chain.pem", b.Bytes(), 0644); err != nil {
if err := os.WriteFile("testdata/tls-ca-chain.pem", b.Bytes(), 0o644); err != nil {
log.Fatal(err)
}
}
29 changes: 15 additions & 14 deletions config/http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var TLSVersions = map[string]TLSVersion{

func (tv *TLSVersion) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
err := unmarshal((*string)(&s))
err := unmarshal(&s)
if err != nil {
return err
}
Expand Down Expand Up @@ -251,12 +251,12 @@ func (o *OAuth2) UnmarshalJSON(data []byte) error {
}

// SetDirectory joins any relative file paths with dir.
func (a *OAuth2) SetDirectory(dir string) {
if a == nil {
func (o *OAuth2) SetDirectory(dir string) {
if o == nil {
return
}
a.ClientSecretFile = JoinDir(dir, a.ClientSecretFile)
a.TLSConfig.SetDirectory(dir)
o.ClientSecretFile = JoinDir(dir, o.ClientSecretFile)
o.TLSConfig.SetDirectory(dir)
}

// LoadHTTPConfig parses the YAML input s into a HTTPClientConfig.
Expand Down Expand Up @@ -845,11 +845,12 @@ func NewTLSConfig(cfg *TLSConfig) (*tls.Config, error) {
tlsConfig.ServerName = cfg.ServerName
}
// If a client cert & key is provided then configure TLS config accordingly.
if len(cfg.CertFile) > 0 && len(cfg.KeyFile) == 0 {
switch {
case len(cfg.CertFile) > 0 && len(cfg.KeyFile) == 0:
return nil, fmt.Errorf("client cert file %q specified without client key file", cfg.CertFile)
} else if len(cfg.KeyFile) > 0 && len(cfg.CertFile) == 0 {
case len(cfg.KeyFile) > 0 && len(cfg.CertFile) == 0:
return nil, fmt.Errorf("client key file %q specified without client cert file", cfg.KeyFile)
} else if len(cfg.CertFile) > 0 && len(cfg.KeyFile) > 0 {
case len(cfg.CertFile) > 0 && len(cfg.KeyFile) > 0:
// Verify that client cert and key are valid.
if _, err := cfg.getClientCertificate(nil); err != nil {
return nil, err
Expand Down Expand Up @@ -1014,9 +1015,9 @@ func (t *tlsRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
}

t.mtx.RLock()
equal := bytes.Equal(caHash[:], t.hashCAFile) &&
bytes.Equal(certHash[:], t.hashCertFile) &&
bytes.Equal(keyHash[:], t.hashKeyFile)
equal := bytes.Equal(caHash, t.hashCAFile) &&
bytes.Equal(certHash, t.hashCertFile) &&
bytes.Equal(keyHash, t.hashKeyFile)
rt := t.rt
t.mtx.RUnlock()
if equal {
Expand All @@ -1039,9 +1040,9 @@ func (t *tlsRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {

t.mtx.Lock()
t.rt = rt
t.hashCAFile = caHash[:]
t.hashCertFile = certHash[:]
t.hashKeyFile = keyHash[:]
t.hashCAFile = caHash
t.hashCertFile = certHash
t.hashKeyFile = keyHash
t.mtx.Unlock()

return rt.RoundTrip(req)
Expand Down
Loading

0 comments on commit 185fc9b

Please sign in to comment.