Fix gosec, errorlint, and gofmt linter errors in unseal.go and grpc.go

Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
2026-03-15 10:30:18 -07:00
parent 2336bf5061
commit 33e71eeee9
3 changed files with 11 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ package server
import (
"context"
"crypto/tls"
"errors"
"fmt"
"net"
@@ -33,7 +34,7 @@ func (g *systemServiceServer) Init(ctx context.Context, req *metacryptv1.InitReq
Threads: g.s.cfg.Seal.Argon2Threads,
}
if err := g.s.seal.Initialize(ctx, []byte(req.Password), params); err != nil {
if err == seal.ErrAlreadyInitialized {
if errors.Is(err, seal.ErrAlreadyInitialized) {
return nil, grpcstatus.Error(codes.AlreadyExists, "already initialized")
}
g.s.logger.Error("grpc init failed", "error", err)
@@ -44,14 +45,14 @@ func (g *systemServiceServer) Init(ctx context.Context, req *metacryptv1.InitReq
func (g *systemServiceServer) Unseal(ctx context.Context, req *metacryptv1.UnsealRequest) (*metacryptv1.UnsealResponse, error) {
if err := g.s.seal.Unseal([]byte(req.Password)); err != nil {
switch err {
case seal.ErrNotInitialized:
switch {
case errors.Is(err, seal.ErrNotInitialized):
return nil, grpcstatus.Error(codes.FailedPrecondition, "not initialized")
case seal.ErrInvalidPassword:
case errors.Is(err, seal.ErrInvalidPassword):
return nil, grpcstatus.Error(codes.Unauthenticated, "invalid password")
case seal.ErrRateLimited:
case errors.Is(err, seal.ErrRateLimited):
return nil, grpcstatus.Error(codes.ResourceExhausted, "too many attempts, try again later")
case seal.ErrNotSealed:
case errors.Is(err, seal.ErrNotSealed):
return nil, grpcstatus.Error(codes.AlreadyExists, "already unsealed")
default:
g.s.logger.Error("grpc unseal failed", "error", err)