From bb737505d411b57864f577f3b1f3e13c30332d51 Mon Sep 17 00:00:00 2001 From: "mayur.popli" Date: Fri, 4 Apr 2025 16:34:43 +0530 Subject: [PATCH] fix: resolved comments --- core/module/module.go | 2 +- core/module/module_test.go | 2 +- pkg/plugin/implementation/schemavalidator/schemavalidator.go | 5 +---- pkg/plugin/implementation/signvalidator/signvalidator.go | 4 ++-- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/core/module/module.go b/core/module/module.go index 0cd7567..3b0fcef 100644 --- a/core/module/module.go +++ b/core/module/module.go @@ -51,7 +51,7 @@ func Register(ctx context.Context, mCfgs []Config, mux *http.ServeMux, mgr handl } // addMiddleware applies middleware plugins to the provided handler in reverse order. -// It retrieves middleware instances from the plugin manager and chains them to the handler.. +// It retrieves middleware instances from the plugin manager and chains them to the handler. func addMiddleware(ctx context.Context, mgr handler.PluginManager, handler http.Handler, hCfg *handler.Config) (http.Handler, error) { mws := hCfg.Plugins.Middleware log.Debugf(ctx, "Applying %d middleware(s) to the handler", len(mws)) diff --git a/core/module/module_test.go b/core/module/module_test.go index 8737968..8f9016c 100644 --- a/core/module/module_test.go +++ b/core/module/module_test.go @@ -99,7 +99,7 @@ func TestRegisterSuccess(t *testing.T) { } } -// TestRegisterFailure tests scenarios where the handler registration should fail.. +// TestRegisterFailure tests scenarios where the handler registration should fail. func TestRegisterFailure(t *testing.T) { tests := []struct { name string diff --git a/pkg/plugin/implementation/schemavalidator/schemavalidator.go b/pkg/plugin/implementation/schemavalidator/schemavalidator.go index 9456c07..bab2dba 100644 --- a/pkg/plugin/implementation/schemavalidator/schemavalidator.go +++ b/pkg/plugin/implementation/schemavalidator/schemavalidator.go @@ -105,16 +105,13 @@ func (v *schemaValidator) Validate(ctx context.Context, url *url.URL, data []byt // Return the array of schema validation errors return &model.SchemaValidationErr{Errors: schemaErrors} } - return model.NewBadReqErr(fmt.Errorf("validation failed: %v", err)) + return fmt.Errorf("validation failed: %v", err) } // Return nil if validation succeeds return nil } -// ValidatorProvider provides instances of Validator. -type ValidatorProvider struct{} - // Initialise initialises the validator provider by compiling all the JSON schema files // from the specified directory and storing them in a cache indexed by their schema filenames. func (v *schemaValidator) initialise() error { diff --git a/pkg/plugin/implementation/signvalidator/signvalidator.go b/pkg/plugin/implementation/signvalidator/signvalidator.go index 07893fd..612d857 100644 --- a/pkg/plugin/implementation/signvalidator/signvalidator.go +++ b/pkg/plugin/implementation/signvalidator/signvalidator.go @@ -33,7 +33,7 @@ func New(ctx context.Context, config *Config) (*validator, func() error, error) func (v *validator) Validate(ctx context.Context, body []byte, header string, publicKeyBase64 string) error { createdTimestamp, expiredTimestamp, signature, err := parseAuthHeader(header) if err != nil { - return model.NewBadReqErr(fmt.Errorf("error parsing header: %w", err)) + return model.NewSignValidationErr(fmt.Errorf("error parsing header: %w", err)) } signatureBytes, err := base64.StdEncoding.DecodeString(signature) @@ -53,7 +53,7 @@ func (v *validator) Validate(ctx context.Context, body []byte, header string, pu decodedPublicKey, err := base64.StdEncoding.DecodeString(publicKeyBase64) if err != nil { - return model.NewBadReqErr(fmt.Errorf("error decoding public key: %w", err)) + return model.NewSignValidationErr(fmt.Errorf("error decoding public key: %w", err)) } if !ed25519.Verify(ed25519.PublicKey(decodedPublicKey), []byte(signingString), signatureBytes) {