Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Dec 11, 2023
1 parent 12d66b0 commit eaeaf10
Show file tree
Hide file tree
Showing 60 changed files with 244 additions and 225 deletions.
11 changes: 1 addition & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,13 @@ linters:
- dupl
- exhaustivestruct
- exhaustruct
- forbidigo
- forcetypeassert
- funlen
- gci
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- goerr113
- gofumpt
- goheader
- golint
- gomnd
- ifshort
Expand All @@ -153,15 +149,10 @@ linters:
- nilnil
- nlreturn
- nosnakecase
- promlinter
- rowserrcheck
- perfsprint
- scopelint
- sqlclosecheck
- structcheck
- thelper
- varcheck
- varnamelen
- wastedassign
- whitespace
- wrapcheck
- wsl
23 changes: 12 additions & 11 deletions cmd/showcertificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"os"
"time"

"github.com/pkg/errors"
Expand All @@ -32,21 +33,21 @@ func ShowCertificates(ctx context.Context, majordomo majordomo.Service) error {
if err != nil {
return errors.Wrap(err, "failed to obtain server certificate")
}
fmt.Printf("Server certificate obtained from %s\n", viper.GetString("certificates.server-cert"))
fmt.Fprintf(os.Stdout, "Server certificate obtained from %s\n", viper.GetString("certificates.server-cert"))
keyPEMBlock, err := majordomo.Fetch(ctx, viper.GetString("certificates.server-key"))
if err != nil {
return errors.Wrap(err, "failed to obtain server key")
}
fmt.Printf("Server key obtained from %s\n", viper.GetString("certificates.server-key"))
fmt.Fprintf(os.Stdout, "Server key obtained from %s\n", viper.GetString("certificates.server-key"))
var caPEMBlock []byte
if viper.GetString("certificates.ca-cert") != "" {
caPEMBlock, err = majordomo.Fetch(ctx, viper.GetString("certificates.ca-cert"))
if err != nil {
return errors.Wrap(err, "failed to obtain client CA certificate")
}
fmt.Printf("CA certificate obtained from %s\n", viper.GetString("certificates.ca-cert"))
fmt.Fprintf(os.Stdout, "CA certificate obtained from %s\n", viper.GetString("certificates.ca-cert"))
}
fmt.Println()
fmt.Fprintln(os.Stdout)

serverCert, err := tls.X509KeyPair(certPEMBlock, keyPEMBlock)
if err != nil {
Expand All @@ -59,13 +60,13 @@ func ShowCertificates(ctx context.Context, majordomo majordomo.Service) error {
if err != nil {
return errors.Wrap(err, "could not read certificate")
}
fmt.Printf("Server certificate issued by: %s\n", cert.Issuer.CommonName)
fmt.Fprintf(os.Stdout, "Server certificate issued by: %s\n", cert.Issuer.CommonName)
if cert.NotAfter.Before(time.Now()) {
fmt.Printf("WARNING: server certificate expired at: %v\n", cert.NotAfter)
fmt.Fprintf(os.Stdout, "WARNING: server certificate expired at: %v\n", cert.NotAfter)
} else {
fmt.Printf("Server certificate expires: %v\n", cert.NotAfter)
fmt.Fprintf(os.Stdout, "Server certificate expires: %v\n", cert.NotAfter)
}
fmt.Printf("Server certificate issued to: %s\n", cert.Subject.CommonName)
fmt.Fprintf(os.Stdout, "Server certificate issued to: %s\n", cert.Subject.CommonName)

for len(caPEMBlock) > 0 {
var block *pem.Block
Expand All @@ -80,11 +81,11 @@ func ShowCertificates(ctx context.Context, majordomo majordomo.Service) error {
if err != nil {
continue
}
fmt.Printf("\nCertificate authority certificate is: %s\n", cert.Subject.CommonName)
fmt.Fprintf(os.Stdout, "\nCertificate authority certificate is: %s\n", cert.Subject.CommonName)
if cert.NotAfter.Before(time.Now()) {
fmt.Printf("WARNING: certificate authority certificate expired at: %v\n", cert.NotAfter)
fmt.Fprintf(os.Stdout, "WARNING: certificate authority certificate expired at: %v\n", cert.NotAfter)
} else {
fmt.Printf("Certificate authority certificate expires: %v\n", cert.NotAfter)
fmt.Fprintf(os.Stdout, "Certificate authority certificate expires: %v\n", cert.NotAfter)
}
}

Expand Down
2 changes: 1 addition & 1 deletion logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func initLogging() error {

// Change the output file.
if viper.GetString("log-file") != "" {
f, err := os.OpenFile(util.ResolvePath(viper.GetString("log-file")), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
f, err := os.OpenFile(util.ResolvePath(viper.GetString("log-file")), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o600)
if err != nil {
return errors.Wrap(err, "failed to open log file")
}
Expand Down
14 changes: 6 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func initProfiling() {

func runCommands(ctx context.Context, majordomo majordomo.Service) (bool, int) {
if viper.GetBool("version") {
fmt.Printf("%s\n", ReleaseVersion)
fmt.Fprintf(os.Stdout, "%s\n", ReleaseVersion)
return true, 0
}

Expand Down Expand Up @@ -500,13 +500,11 @@ func logModules() {
if ok {
log.Trace().Str("path", buildInfo.Path).Msg("Main package")
for _, dep := range buildInfo.Deps {
log := log.Trace()
if dep.Replace == nil {
log = log.Str("path", dep.Path).Str("version", dep.Version)
} else {
log = log.Str("path", dep.Replace.Path).Str("version", dep.Replace.Version)
path := dep.Path
if dep.Replace != nil {
path = dep.Replace.Path
}
log.Msg("Dependency")
log.Trace().Str("path", path).Str("version", dep.Version).Msg("Dependency")
}
}
}
Expand All @@ -522,7 +520,7 @@ func initRules(ctx context.Context) (rules.Service, error) {

func initStores(ctx context.Context, majordomo majordomo.Service) ([]e2wtypes.Store, error) {
storesCfg := &core.Stores{}
if err := viper.Unmarshal(&storesCfg); err != nil {
if err := viper.Unmarshal(storesCfg); err != nil {
return nil, errors.Wrap(err, "failed to obtain stores configuration")
}
stores, err := core.InitStores(ctx, majordomo, storesCfg.Stores)
Expand Down
6 changes: 4 additions & 2 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (

var metricsNamespace = "dirk"

var releaseMetric *prometheus.GaugeVec
var readyMetric prometheus.Gauge
var (
releaseMetric *prometheus.GaugeVec
readyMetric prometheus.Gauge
)

func registerMetrics(ctx context.Context, monitor metrics.Service) error {
if releaseMetric != nil {
Expand Down
2 changes: 1 addition & 1 deletion rules/standard/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type parameters struct {

// Parameter is the interface for service parameters.
type Parameter interface {
apply(*parameters)
apply(p *parameters)
}

type parameterFunc func(*parameters)
Expand Down
7 changes: 3 additions & 4 deletions rules/standard/signbeaconattestations.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,9 @@ func (s *Service) storeSignBeaconAttestationStates(ctx context.Context, pubKeys
return err
}

if e := log.Trace(); e.Enabled() {
for _, state := range states {
log.Trace().Int64("source_epoch", state.SourceEpoch).Int64("target_epoch", state.TargetEpoch).Msg("Stored attestation state to store")
}
for _, state := range states {
log.Trace().Int64("source_epoch", state.SourceEpoch).Int64("target_epoch", state.TargetEpoch).Msg("Stored attestation state to store")
}

return nil
}
1 change: 0 additions & 1 deletion rules/standard/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ func TestBatchStore(t *testing.T) {
require.NotNil(t, err)
require.EqualError(t, err, test.err)
}

})
}
}
Expand Down
2 changes: 1 addition & 1 deletion services/accountmanager/standard/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type parameters struct {

// Parameter is the interface for service parameters.
type Parameter interface {
apply(*parameters)
apply(p *parameters)
}

type parameterFunc func(*parameters)
Expand Down
8 changes: 7 additions & 1 deletion services/api/grpc/handlers/accountmanager/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ func (h *Handler) Generate(ctx context.Context, req *pb.GenerateRequest) (*pb.Ge
log.Trace().Str("account", req.GetAccount()).Msg("Generate account received")
res := &pb.GenerateResponse{}

pubKey, participants, err := h.process.OnGenerate(ctx, handlers.GenerateCredentials(ctx), req.Account, req.Passphrase, req.SigningThreshold, req.Participants)
pubKey, participants, err := h.process.OnGenerate(ctx,
handlers.GenerateCredentials(ctx),
req.GetAccount(),
req.GetPassphrase(),
req.GetSigningThreshold(),
req.GetParticipants(),
)
if err != nil {
log.Error().Err(err).Msg("Generate attempt resulted in error")
res.State = pb.ResponseState_FAILED
Expand Down
2 changes: 1 addition & 1 deletion services/api/grpc/handlers/accountmanager/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (h *Handler) Lock(ctx context.Context, req *pb.LockAccountRequest) (*pb.Loc
log.Trace().Str("account", req.GetAccount()).Msg("Lock account received")
res := &pb.LockAccountResponse{}

result, err := h.accountManager.Lock(ctx, handlers.GenerateCredentials(ctx), req.Account)
result, err := h.accountManager.Lock(ctx, handlers.GenerateCredentials(ctx), req.GetAccount())
if err != nil {
log.Error().Err(err).Msg("Lock attempt resulted in error")
res.State = pb.ResponseState_FAILED
Expand Down
2 changes: 1 addition & 1 deletion services/api/grpc/handlers/accountmanager/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type parameters struct {

// Parameter is the interface for service parameters.
type Parameter interface {
apply(*parameters)
apply(p *parameters)
}

type parameterFunc func(*parameters)
Expand Down
2 changes: 1 addition & 1 deletion services/api/grpc/handlers/accountmanager/unlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (h *Handler) Unlock(ctx context.Context, req *pb.UnlockAccountRequest) (*pb
log.Trace().Str("account", req.GetAccount()).Msg("Unlock account received")
res := &pb.UnlockAccountResponse{}

result, err := h.accountManager.Unlock(ctx, handlers.GenerateCredentials(ctx), req.Account, req.Passphrase)
result, err := h.accountManager.Unlock(ctx, handlers.GenerateCredentials(ctx), req.GetAccount(), req.GetPassphrase())
if err != nil {
log.Error().Err(err).Msg("Unlock attempt resulted in error")
res.State = pb.ResponseState_FAILED
Expand Down
10 changes: 5 additions & 5 deletions services/api/grpc/handlers/lister/listaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (h *Handler) ListAccounts(ctx context.Context, req *pb.ListAccountsRequest)
res.Accounts = make([]*pb.Account, 0)
res.DistributedAccounts = make([]*pb.DistributedAccount, 0)

result, accounts := h.lister.ListAccounts(ctx, handlers.GenerateCredentials(ctx), req.Paths)
result, accounts := h.lister.ListAccounts(ctx, handlers.GenerateCredentials(ctx), req.GetPaths())
switch result {
case core.ResultDenied:
res.State = pb.ResponseState_DENIED
Expand Down Expand Up @@ -85,25 +85,25 @@ func (h *Handler) ListAccounts(ctx context.Context, req *pb.ListAccountsRequest)
log.Warn().Str("participant", v).Err(err).Msg("Invalid port for participant")
continue
}
pbAccount.Participants = append(pbAccount.Participants, &pb.Endpoint{
pbAccount.Participants = append(pbAccount.GetParticipants(), &pb.Endpoint{
Id: k,
Name: parts[0],
Port: uint32(port),
})
}
res.DistributedAccounts = append(res.DistributedAccounts, pbAccount)
res.DistributedAccounts = append(res.GetDistributedAccounts(), pbAccount)
} else {
pbAccount := &pb.Account{
Uuid: uuid,
Name: name,
PublicKey: pubKeyProvider.PublicKey().Marshal(),
}
res.Accounts = append(res.Accounts, pbAccount)
res.Accounts = append(res.GetAccounts(), pbAccount)
}
}
}

res.State = pb.ResponseState_SUCCEEDED
log.Trace().Int("accounts", len(res.Accounts)).Int("distributedAccounts", len(res.DistributedAccounts)).Msg("Success")
log.Trace().Int("accounts", len(res.GetAccounts())).Int("distributedAccounts", len(res.GetDistributedAccounts())).Msg("Success")
return res, nil
}
2 changes: 1 addition & 1 deletion services/api/grpc/handlers/lister/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type parameters struct {

// Parameter is the interface for service parameters.
type Parameter interface {
apply(*parameters)
apply(p *parameters)
}

type parameterFunc func(*parameters)
Expand Down
2 changes: 1 addition & 1 deletion services/api/grpc/handlers/receiver/abort.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (h *Handler) Abort(ctx context.Context, req *pb.AbortRequest) (*empty.Empty
}
log.Debug().Uint64("sender_id", senderID).Msg("Aborting as per request from sender")

if err := h.process.OnAbort(ctx, senderID, req.Account); err != nil {
if err := h.process.OnAbort(ctx, senderID, req.GetAccount()); err != nil {
log.Error().Err(err).Msg("Failed to abort distributed key generation")
return nil, errors.New("Failed")
}
Expand Down
2 changes: 1 addition & 1 deletion services/api/grpc/handlers/receiver/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (h *Handler) Commit(ctx context.Context, req *pb.CommitRequest) (*pb.Commit
}
log.Trace().Uint64("sender_id", senderID).Msg("Committing as per request from sender")

pubKey, confirmationSig, err := h.process.OnCommit(ctx, senderID, req.Account, req.ConfirmationData)
pubKey, confirmationSig, err := h.process.OnCommit(ctx, senderID, req.GetAccount(), req.GetConfirmationData())
if err != nil {
log.Error().Err(err).Msg("Failed to commit distributed key generation")
return nil, errors.Wrap(err, "failed to commit created key")
Expand Down
10 changes: 5 additions & 5 deletions services/api/grpc/handlers/receiver/contribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ func (h *Handler) Contribute(ctx context.Context, req *pb.ContributeRequest) (*p
return nil, errors.New("Unknown sender")
}

log := log.With().Str("account", req.Account).Uint64("peer", senderID).Logger()
log := log.With().Str("account", req.GetAccount()).Uint64("peer", senderID).Logger()

secret := bls.SecretKey{}
if err := secret.Deserialize(req.Secret); err != nil {
if err := secret.Deserialize(req.GetSecret()); err != nil {
log.Warn().Err(err).Msg("Received secret key is invalid")
return nil, errors.New("Invalid secret key")
}
vVec := make([]bls.PublicKey, len(req.VerificationVector))
for i, key := range req.VerificationVector {
vVec := make([]bls.PublicKey, len(req.GetVerificationVector()))
for i, key := range req.GetVerificationVector() {
vVec[i] = bls.PublicKey{}
if err := vVec[i].Deserialize(key); err != nil {
log.Warn().Err(err).Msg("Received verification vector is invalid")
Expand All @@ -47,7 +47,7 @@ func (h *Handler) Contribute(ctx context.Context, req *pb.ContributeRequest) (*p
}
log.Trace().Msg("Received valid contribution")

retSecret, retVVec, err := h.process.OnContribute(ctx, senderID, req.Account, secret, vVec)
retSecret, retVVec, err := h.process.OnContribute(ctx, senderID, req.GetAccount(), secret, vVec)
if err != nil {
log.Error().Err(err).Msg("Handle/generate contribution failed")
return nil, errors.Wrap(err, "Failed to handle contribution")
Expand Down
2 changes: 1 addition & 1 deletion services/api/grpc/handlers/receiver/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (h *Handler) Execute(ctx context.Context, req *pb.ExecuteRequest) (*empty.E
}
log.Trace().Uint64("sender_id", senderID).Msg("Executing as per request from sender")

err := h.process.OnExecute(ctx, senderID, req.Account)
err := h.process.OnExecute(ctx, senderID, req.GetAccount())
if err != nil {
log.Error().Err(err).Msg("Failed to execute distributed key generation")
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion services/api/grpc/handlers/receiver/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type parameters struct {

// Parameter is the interface for handler parameters.
type Parameter interface {
apply(*parameters)
apply(p *parameters)
}

type parameterFunc func(*parameters)
Expand Down
12 changes: 6 additions & 6 deletions services/api/grpc/handlers/receiver/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ func (h *Handler) Prepare(ctx context.Context, req *pb.PrepareRequest) (*empty.E
}
log.Trace().Uint64("sender_id", senderID).Msg("Preparing as per request from sender")

participants := make([]*core.Endpoint, len(req.Participants))
for i, participant := range req.Participants {
participants := make([]*core.Endpoint, len(req.GetParticipants()))
for i, participant := range req.GetParticipants() {
participants[i] = &core.Endpoint{
ID: participant.Id,
Name: participant.Name,
Port: participant.Port,
ID: participant.GetId(),
Name: participant.GetName(),
Port: participant.GetPort(),
}
}
err := h.process.OnPrepare(ctx, senderID, req.Account, req.Passphrase, req.Threshold, participants)
err := h.process.OnPrepare(ctx, senderID, req.GetAccount(), req.GetPassphrase(), req.GetThreshold(), participants)
if err != nil {
log.Error().Err(err).Msg("Failed to prepare for distributed key generation")
return nil, errors.New("Failed to prepare")
Expand Down
Loading

0 comments on commit eaeaf10

Please sign in to comment.