forked from TrueCloudLab/certificates
Merge pull request #106 from smallstep/lint
Added a staticcheck and unused linters and trying to clear up new errors
This commit is contained in:
commit
9f0d8545a3
14 changed files with 14 additions and 53 deletions
|
@ -49,6 +49,8 @@ linters:
|
||||||
- misspell
|
- misspell
|
||||||
- ineffassign
|
- ineffassign
|
||||||
- deadcode
|
- deadcode
|
||||||
|
- staticcheck
|
||||||
|
- unused
|
||||||
|
|
||||||
run:
|
run:
|
||||||
skip-dirs:
|
skip-dirs:
|
||||||
|
@ -60,10 +62,9 @@ issues:
|
||||||
- declaration of "err" shadows declaration at line
|
- declaration of "err" shadows declaration at line
|
||||||
- should have a package comment, unless it's in another file for this package
|
- should have a package comment, unless it's in another file for this package
|
||||||
- error strings should not be capitalized or end with punctuation or a newline
|
- error strings should not be capitalized or end with punctuation or a newline
|
||||||
- declaration of "authz" shadows declaration at line
|
|
||||||
# golangci.com configuration
|
# golangci.com configuration
|
||||||
# https://github.com/golangci/golangci/wiki/Configuration
|
# https://github.com/golangci/golangci/wiki/Configuration
|
||||||
service:
|
service:
|
||||||
golangci-lint-version: 1.17.x # use the fixed version to not introduce new linters unexpectedly
|
golangci-lint-version: 1.18.x # use the fixed version to not introduce new linters unexpectedly
|
||||||
prepare:
|
prepare:
|
||||||
- echo "here I can run custom commands, but no preparation needed for this repo"
|
- echo "here I can run custom commands, but no preparation needed for this repo"
|
||||||
|
|
|
@ -214,18 +214,18 @@ func (a *Authority) FinalizeOrder(p provisioner.Interface, accID, orderID string
|
||||||
// GetAuthz retrieves and attempts to update the status on an ACME authz
|
// GetAuthz retrieves and attempts to update the status on an ACME authz
|
||||||
// before returning.
|
// before returning.
|
||||||
func (a *Authority) GetAuthz(p provisioner.Interface, accID, authzID string) (*Authz, error) {
|
func (a *Authority) GetAuthz(p provisioner.Interface, accID, authzID string) (*Authz, error) {
|
||||||
authz, err := getAuthz(a.db, authzID)
|
az, err := getAuthz(a.db, authzID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if accID != authz.getAccountID() {
|
if accID != az.getAccountID() {
|
||||||
return nil, UnauthorizedErr(errors.New("account does not own authz"))
|
return nil, UnauthorizedErr(errors.New("account does not own authz"))
|
||||||
}
|
}
|
||||||
authz, err = authz.updateStatus(a.db)
|
az, err = az.updateStatus(a.db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, Wrap(err, "error updating authz status")
|
return nil, Wrap(err, "error updating authz status")
|
||||||
}
|
}
|
||||||
return authz.toACME(a.db, a.dir, p)
|
return az.toACME(a.db, a.dir, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateChallenge attempts to validate the challenge.
|
// ValidateChallenge attempts to validate the challenge.
|
||||||
|
|
|
@ -195,13 +195,6 @@ func (ba *baseAuthz) clone() *baseAuthz {
|
||||||
return &u
|
return &u
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ba *baseAuthz) storeAndReturnError(db nosql.DB, err *Error) error {
|
|
||||||
clone := ba.clone()
|
|
||||||
clone.Error = err
|
|
||||||
clone.save(db, ba)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ba *baseAuthz) parent() authz {
|
func (ba *baseAuthz) parent() authz {
|
||||||
return &dnsAuthz{ba}
|
return &dnsAuthz{ba}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,6 @@ func TestDirectoryGetLink(t *testing.T) {
|
||||||
prov := newProv()
|
prov := newProv()
|
||||||
provID := URLSafeProvisionerName(prov)
|
provID := URLSafeProvisionerName(prov)
|
||||||
|
|
||||||
type newTest struct {
|
|
||||||
actual, expected string
|
|
||||||
}
|
|
||||||
assert.Equals(t, dir.getLink(NewNonceLink, provID, true), fmt.Sprintf("https://ca.smallstep.com/acme/%s/new-nonce", provID))
|
assert.Equals(t, dir.getLink(NewNonceLink, provID, true), fmt.Sprintf("https://ca.smallstep.com/acme/%s/new-nonce", provID))
|
||||||
assert.Equals(t, dir.getLink(NewNonceLink, provID, false), fmt.Sprintf("/%s/new-nonce", provID))
|
assert.Equals(t, dir.getLink(NewNonceLink, provID, false), fmt.Sprintf("/%s/new-nonce", provID))
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,6 @@ func Test_caHandler_Revoke(t *testing.T) {
|
||||||
input string
|
input string
|
||||||
auth Authority
|
auth Authority
|
||||||
tls *tls.ConnectionState
|
tls *tls.ConnectionState
|
||||||
err error
|
|
||||||
statusCode int
|
statusCode int
|
||||||
expected []byte
|
expected []byte
|
||||||
}
|
}
|
||||||
|
|
|
@ -260,13 +260,6 @@ func Test_caHandler_SignSSH(t *testing.T) {
|
||||||
})
|
})
|
||||||
assert.FatalError(t, err)
|
assert.FatalError(t, err)
|
||||||
|
|
||||||
type fields struct {
|
|
||||||
Authority Authority
|
|
||||||
}
|
|
||||||
type args struct {
|
|
||||||
w http.ResponseWriter
|
|
||||||
r *http.Request
|
|
||||||
}
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
req []byte
|
req []byte
|
||||||
|
|
|
@ -26,7 +26,6 @@ type Authority struct {
|
||||||
intermediateIdentity *x509util.Identity
|
intermediateIdentity *x509util.Identity
|
||||||
sshCAUserCertSignKey crypto.Signer
|
sshCAUserCertSignKey crypto.Signer
|
||||||
sshCAHostCertSignKey crypto.Signer
|
sshCAHostCertSignKey crypto.Signer
|
||||||
validateOnce bool
|
|
||||||
certificates *sync.Map
|
certificates *sync.Map
|
||||||
startTime time.Time
|
startTime time.Time
|
||||||
provisioners *provisioner.Collection
|
provisioners *provisioner.Collection
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
type MockAuthDB struct {
|
type MockAuthDB struct {
|
||||||
err error
|
err error
|
||||||
ret1, ret2 interface{}
|
ret1 interface{}
|
||||||
init func(*db.Config) (db.AuthDB, error)
|
init func(*db.Config) (db.AuthDB, error)
|
||||||
isRevoked func(string) (bool, error)
|
isRevoked func(string) (bool, error)
|
||||||
revoke func(rci *db.RevokedCertificateInfo) error
|
revoke func(rci *db.RevokedCertificateInfo) error
|
||||||
|
|
|
@ -248,10 +248,6 @@ func TestTimeDuration_Unix(t *testing.T) {
|
||||||
func TestTimeDuration_String(t *testing.T) {
|
func TestTimeDuration_String(t *testing.T) {
|
||||||
tm, fn := mockNow()
|
tm, fn := mockNow()
|
||||||
defer fn()
|
defer fn()
|
||||||
type fields struct {
|
|
||||||
t time.Time
|
|
||||||
d time.Duration
|
|
||||||
}
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
timeDuration *TimeDuration
|
timeDuration *TimeDuration
|
||||||
|
|
|
@ -212,7 +212,6 @@ type RevokeOptions struct {
|
||||||
MTLS bool
|
MTLS bool
|
||||||
Crt *x509.Certificate
|
Crt *x509.Certificate
|
||||||
OTT string
|
OTT string
|
||||||
errCtxt map[string]interface{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Revoke revokes a certificate.
|
// Revoke revokes a certificate.
|
||||||
|
|
|
@ -22,7 +22,6 @@ import (
|
||||||
|
|
||||||
func TestNewACMEClient(t *testing.T) {
|
func TestNewACMEClient(t *testing.T) {
|
||||||
type test struct {
|
type test struct {
|
||||||
endpoint string
|
|
||||||
ops []ClientOption
|
ops []ClientOption
|
||||||
r1, r2 interface{}
|
r1, r2 interface{}
|
||||||
rc1, rc2 int
|
rc1, rc2 int
|
||||||
|
@ -357,8 +356,6 @@ func TestACMEClient_post(t *testing.T) {
|
||||||
|
|
||||||
func TestACMEClient_NewOrder(t *testing.T) {
|
func TestACMEClient_NewOrder(t *testing.T) {
|
||||||
type test struct {
|
type test struct {
|
||||||
payload []byte
|
|
||||||
jwk *jose.JSONWebKey
|
|
||||||
ops []withHeaderOption
|
ops []withHeaderOption
|
||||||
r1, r2 interface{}
|
r1, r2 interface{}
|
||||||
rc1, rc2 int
|
rc1, rc2 int
|
||||||
|
|
|
@ -570,8 +570,8 @@ func TestBootstrapListener(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
wg.Add(1)
|
|
||||||
http.Serve(lis, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
http.Serve(lis, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write([]byte("ok"))
|
w.Write([]byte("ok"))
|
||||||
}))
|
}))
|
||||||
|
|
11
ca/ca.go
11
ca/ca.go
|
@ -63,12 +63,11 @@ func WithDatabase(db db.AuthDB) Option {
|
||||||
// CA is the type used to build the complete certificate authority. It builds
|
// CA is the type used to build the complete certificate authority. It builds
|
||||||
// the HTTP server, set ups the middlewares and the HTTP handlers.
|
// the HTTP server, set ups the middlewares and the HTTP handlers.
|
||||||
type CA struct {
|
type CA struct {
|
||||||
auth *authority.Authority
|
auth *authority.Authority
|
||||||
acmeAuth *acme.Authority
|
config *authority.Config
|
||||||
config *authority.Config
|
srv *server.Server
|
||||||
srv *server.Server
|
opts *options
|
||||||
opts *options
|
renewer *TLSRenewer
|
||||||
renewer *TLSRenewer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates and initializes the CA with the given configuration and options.
|
// New creates and initializes the CA with the given configuration and options.
|
||||||
|
|
|
@ -30,9 +30,6 @@ func NewResponseLogger(w http.ResponseWriter) ResponseLogger {
|
||||||
|
|
||||||
func wrapLogger(w http.ResponseWriter) (rw ResponseLogger) {
|
func wrapLogger(w http.ResponseWriter) (rw ResponseLogger) {
|
||||||
rw = &rwDefault{w, 200, 0, nil}
|
rw = &rwDefault{w, 200, 0, nil}
|
||||||
if c, ok := w.(http.CloseNotifier); ok {
|
|
||||||
rw = &rwCloseNotifier{rw, c}
|
|
||||||
}
|
|
||||||
if f, ok := w.(http.Flusher); ok {
|
if f, ok := w.(http.Flusher); ok {
|
||||||
rw = &rwFlusher{rw, f}
|
rw = &rwFlusher{rw, f}
|
||||||
}
|
}
|
||||||
|
@ -88,15 +85,6 @@ func (r *rwDefault) WithFields(fields map[string]interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type rwCloseNotifier struct {
|
|
||||||
ResponseLogger
|
|
||||||
c http.CloseNotifier
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *rwCloseNotifier) CloseNotify() <-chan bool {
|
|
||||||
return r.CloseNotify()
|
|
||||||
}
|
|
||||||
|
|
||||||
type rwFlusher struct {
|
type rwFlusher struct {
|
||||||
ResponseLogger
|
ResponseLogger
|
||||||
f http.Flusher
|
f http.Flusher
|
||||||
|
|
Loading…
Add table
Reference in a new issue