Skip to content

Commit

Permalink
lint: use staticcheck + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
primalmotion committed Apr 5, 2019
1 parent 3a02e3d commit 3f9fe1c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
11 changes: 4 additions & 7 deletions Makefile
Expand Up @@ -17,15 +17,15 @@ ci: init lint test codecov build_linux build_darwin build_windows package
if [[ -d build/ ]] ; then cp -r build/ artifacts/build/ ; fi

init:
echo running dep ensure...
go get -u github.com/aporeto-inc/go-bindata/...
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
dep ensure
dep status || true
go generate ./...

lint:
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
# --enable=unparam
golangci-lint run \
--deadline=3m \
--disable-all \
--exclude-use-default=false \
--enable=errcheck \
Expand All @@ -34,16 +34,13 @@ lint:
--enable=golint \
--enable=unused \
--enable=structcheck \
--enable=staticcheck \
--enable=varcheck \
--enable=deadcode \
--enable=unconvert \
--enable=misspell \
--enable=prealloc \
--enable=nakedret \
--enable=gosimple \
--enable=govet \
--enable=staticcheck \
--enable=typecheck \
./...

test:
Expand Down
2 changes: 1 addition & 1 deletion tglib/cert.go
Expand Up @@ -226,7 +226,7 @@ func ReadCertificates(certPemBytes []byte, keyPemBytes []byte, password string)
return nil, nil, fmt.Errorf("failed to unmarshal private key: %s", err)
}
default:
return nil, nil, fmt.Errorf("Unsuported private key type: %s", keyBlock.Type)
return nil, nil, fmt.Errorf("unsuported private key type: %s", keyBlock.Type)
}

return x509certs, key, nil
Expand Down
2 changes: 1 addition & 1 deletion tglib/privatekey.go
Expand Up @@ -44,7 +44,7 @@ func KeyToPEM(key interface{}) (*pem.Block, error) {
t = rsaPrivateKeyHeader

default:
return nil, fmt.Errorf("Given key is not compatible: %T", k)
return nil, fmt.Errorf("given key is not compatible: %T", k)
}

return &pem.Block{
Expand Down
34 changes: 17 additions & 17 deletions tgnoob/helpers.go
Expand Up @@ -207,11 +207,11 @@ func GenerateCSR(
}

if cert != "" && certKey == "" {
return fmt.Errorf("If you specify --cert you must specify --cert-key")
return fmt.Errorf("if you specify --cert you must specify --cert-key")
}

if cert == "" && certKey != "" {
return fmt.Errorf("If you specify --cert-key you must specify --cert")
return fmt.Errorf("if you specify --cert-key you must specify --cert")
}

if cert != "" && (org != nil ||
Expand All @@ -224,7 +224,7 @@ func GenerateCSR(
address != nil ||
dns != nil ||
ips != nil) {
return fmt.Errorf("If you pass cert, you cannot pass any other information")
return fmt.Errorf("if you pass cert, you cannot pass any other information")
}

if cert == "" && commonName == "" {
Expand Down Expand Up @@ -261,11 +261,11 @@ func GenerateCSR(

privateKey, err := keygen()
if err != nil {
return fmt.Errorf("Unable to generate private key: %s", err.Error())
return fmt.Errorf("unable to generate private key: %s", err.Error())
}
keyBlock, err := tglib.KeyToPEM(privateKey)
if err != nil {
return fmt.Errorf("Unable to convert private key pem block: %s", err.Error())
return fmt.Errorf("unable to convert private key pem block: %s", err.Error())
}

var netips []net.IP
Expand All @@ -292,7 +292,7 @@ func GenerateCSR(

csrBytes, err = tglib.GenerateCSR(csr, privateKey)
if err != nil {
return fmt.Errorf("Unable to create csr: %s", err.Error())
return fmt.Errorf("unable to create csr: %s", err.Error())
}

if err = ioutil.WriteFile(
Expand All @@ -307,23 +307,23 @@ func GenerateCSR(

certData, err := ioutil.ReadFile(cert)
if err != nil {
return fmt.Errorf("Unable to load cert %s: %s", certKey, err.Error())
return fmt.Errorf("unable to load cert %s: %s", certKey, err.Error())
}
certKeyData, err := ioutil.ReadFile(certKey)
if err != nil {
return fmt.Errorf("Unable to load cert key %s: %s", certKey, err.Error())
return fmt.Errorf("unable to load cert key %s: %s", certKey, err.Error())
}

cert, key, err := tglib.ReadCertificate(certData, certKeyData, certKeyPass)
if err != nil {
return fmt.Errorf("Unable to read signing cert: %s", err.Error())
return fmt.Errorf("unable to read signing cert: %s", err.Error())
}

csr := tglib.CSRFromCertificate(cert)

csrBytes, err = tglib.GenerateCSR(csr, key)
if err != nil {
return fmt.Errorf("Unable to create csr: %s", err.Error())
return fmt.Errorf("unable to create csr: %s", err.Error())
}
}

Expand Down Expand Up @@ -384,16 +384,16 @@ func SignCSR(

signingCertData, err := ioutil.ReadFile(signingCertPath)
if err != nil {
return fmt.Errorf("Unable to load signing cert %s", signingCertPath)
return fmt.Errorf("unable to load signing cert %s", signingCertPath)
}
signingCertKeyData, err := ioutil.ReadFile(signingCertKeyPath)
if err != nil {
return fmt.Errorf("Unable to load signing cert key %s", signingCertKeyPath)
return fmt.Errorf("unable to load signing cert key %s", signingCertKeyPath)
}

signingCert, signingKey, err := tglib.ReadCertificate(signingCertData, signingCertKeyData, signingCertKeyPass)
if err != nil {
return fmt.Errorf("Unable to read signing cert: %s", err.Error())
return fmt.Errorf("unable to read signing cert: %s", err.Error())
}

var signalg x509.SignatureAlgorithm
Expand Down Expand Up @@ -436,11 +436,11 @@ func SignCSR(

csrData, err := ioutil.ReadFile(path)
if err != nil {
return fmt.Errorf("Unable to load csr %s", path)
return fmt.Errorf("unable to load csr %s", path)
}
csrs, err := tglib.LoadCSRs(csrData)
if err != nil {
return fmt.Errorf("Unable to parse csr %s", path)
return fmt.Errorf("unable to parse csr %s", path)
}

for _, csr := range csrs {
Expand All @@ -458,7 +458,7 @@ func SignCSR(
asnIdentifiers,
)
if err != nil {
return fmt.Errorf("Unable to sign certificate: %s", err.Error())
return fmt.Errorf("unable to sign certificate: %s", err.Error())
}

if err = ioutil.WriteFile(
Expand Down Expand Up @@ -600,7 +600,7 @@ func makePolicies(originalPolicies []string) ([]asn1.ObjectIdentifier, error) {
for _, part := range parts {
n, e := strconv.Atoi(part)
if e != nil {
return nil, fmt.Errorf("Given policy OID %s is invalid", kv)
return nil, fmt.Errorf("given policy OID %s is invalid", kv)
}
oid = append(oid, n)
}
Expand Down

0 comments on commit 3f9fe1c

Please sign in to comment.