[#1651] apemanager: Wrap some errors with InvalidArgument
status
Some checks failed
Tests and linters / Run gofumpt (pull_request) Successful in 46s
DCO action / DCO (pull_request) Successful in 1m1s
Vulncheck / Vulncheck (pull_request) Failing after 1m22s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m14s
Build / Build Components (pull_request) Successful in 2m18s
Tests and linters / Staticcheck (pull_request) Successful in 2m43s
Tests and linters / Tests (pull_request) Successful in 2m59s
Tests and linters / gopls check (pull_request) Successful in 3m25s
Tests and linters / Lint (pull_request) Successful in 3m43s
Tests and linters / Tests with -race (pull_request) Successful in 4m0s
Some checks failed
Tests and linters / Run gofumpt (pull_request) Successful in 46s
DCO action / DCO (pull_request) Successful in 1m1s
Vulncheck / Vulncheck (pull_request) Failing after 1m22s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m14s
Build / Build Components (pull_request) Successful in 2m18s
Tests and linters / Staticcheck (pull_request) Successful in 2m43s
Tests and linters / Tests (pull_request) Successful in 2m59s
Tests and linters / gopls check (pull_request) Successful in 3m25s
Tests and linters / Lint (pull_request) Successful in 3m43s
Tests and linters / Tests with -race (pull_request) Successful in 4m0s
Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
9b113c3156
commit
1884ba4ce8
2 changed files with 18 additions and 7 deletions
|
@ -9,3 +9,9 @@ func ErrAPEManagerAccessDenied(reason string) error {
|
|||
err.WriteReason(reason)
|
||||
return err
|
||||
}
|
||||
|
||||
func ErrAPEManagerInvalidArgument(msg string) error {
|
||||
err := new(apistatus.InvalidArgument)
|
||||
err.SetMessage(msg)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -81,7 +81,8 @@ var _ Server = (*Service)(nil)
|
|||
func (s *Service) validateContainerTargetRequest(ctx context.Context, cid string, pubKey *keys.PublicKey) error {
|
||||
var cidSDK cidSDK.ID
|
||||
if err := cidSDK.DecodeString(cid); err != nil {
|
||||
return fmt.Errorf("invalid CID format: %w", err)
|
||||
err = fmt.Errorf("invalid CID format: %w", err)
|
||||
return apemanager_errors.ErrAPEManagerInvalidArgument(err.Error())
|
||||
}
|
||||
isOwner, err := s.isActorContainerOwner(ctx, cidSDK, pubKey)
|
||||
if err != nil {
|
||||
|
@ -101,7 +102,7 @@ func (s *Service) AddChain(ctx context.Context, req *apemanagerV2.AddChainReques
|
|||
|
||||
chain, err := decodeAndValidateChain(req.GetBody().GetChain().GetKind().(*apeV2.ChainRaw).GetRaw())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, apemanager_errors.ErrAPEManagerInvalidArgument(err.Error())
|
||||
}
|
||||
if len(chain.ID) == 0 {
|
||||
const randomIDLength = 10
|
||||
|
@ -122,7 +123,8 @@ func (s *Service) AddChain(ctx context.Context, req *apemanagerV2.AddChainReques
|
|||
}
|
||||
target = policy_engine.ContainerTarget(reqCID)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported target type: %s", targetType)
|
||||
err = fmt.Errorf("unsupported target type: %s", targetType)
|
||||
return nil, apemanager_errors.ErrAPEManagerInvalidArgument(err.Error())
|
||||
}
|
||||
|
||||
txHash, vub, err := s.contractStorage.AddMorphRuleChain(apechain.Ingress, target, &chain)
|
||||
|
@ -158,7 +160,8 @@ func (s *Service) RemoveChain(ctx context.Context, req *apemanagerV2.RemoveChain
|
|||
}
|
||||
target = policy_engine.ContainerTarget(reqCID)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported target type: %s", targetType)
|
||||
err = fmt.Errorf("unsupported target type: %s", targetType)
|
||||
return nil, apemanager_errors.ErrAPEManagerInvalidArgument(err.Error())
|
||||
}
|
||||
|
||||
txHash, vub, err := s.contractStorage.RemoveMorphRuleChain(apechain.Ingress, target, req.GetBody().GetChainID())
|
||||
|
@ -193,7 +196,8 @@ func (s *Service) ListChains(ctx context.Context, req *apemanagerV2.ListChainsRe
|
|||
}
|
||||
target = policy_engine.ContainerTarget(reqCID)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported target type: %s", targetType)
|
||||
err = fmt.Errorf("unsupported target type: %s", targetType)
|
||||
return nil, apemanager_errors.ErrAPEManagerInvalidArgument(err.Error())
|
||||
}
|
||||
|
||||
chs, err := s.contractStorage.ListMorphRuleChains(apechain.Ingress, target)
|
||||
|
@ -227,11 +231,12 @@ func getSignaturePublicKey(vh *session.RequestVerificationHeader) (*keys.PublicK
|
|||
}
|
||||
sig := vh.GetBodySignature()
|
||||
if sig == nil {
|
||||
return nil, errEmptyBodySignature
|
||||
return nil, apemanager_errors.ErrAPEManagerInvalidArgument(errEmptyBodySignature.Error())
|
||||
}
|
||||
key, err := keys.NewPublicKeyFromBytes(sig.GetKey(), elliptic.P256())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid signature key: %w", err)
|
||||
err = fmt.Errorf("invalid signature key: %w", err)
|
||||
return nil, apemanager_errors.ErrAPEManagerInvalidArgument(err.Error())
|
||||
}
|
||||
|
||||
return key, nil
|
||||
|
|
Loading…
Add table
Reference in a new issue