Skip to content
This repository has been archived by the owner on Feb 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #9 from ripienaar/8
Browse files Browse the repository at this point in the history
(#8) Allow clients to request full validation be disabled
  • Loading branch information
ripienaar authored Mar 23, 2018
2 parents a6dae85 + 910b5e8 commit 0afaad0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func IsSecure() bool {
return Secure == "true"
}

// ClientStrictValidation gives hints to the protocol implementations that
// a client does not wish to be fully validated, this is because validation
// can often be very slow so clients can elect to disable that.
//
// It's not mandatory for a specific version of implementation of the protocol
// to do anything with this, so it's merely a hint
var ClientStrictValidation = true

// Additional to these the package for a specific version must also provide these constructors
// with signature matching those in v1/constructors.go these are in use by mcollective/protocol.gos

Expand Down
6 changes: 6 additions & 0 deletions protocol/v1/reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strings"
"sync"
"time"

"github.com/choria-io/go-protocol/protocol"
)

type reply struct {
Expand Down Expand Up @@ -100,6 +102,10 @@ func (r *reply) Version() string {

// IsValidJSON validates the given JSON data against the schema
func (r *reply) IsValidJSON(data string) (err error) {
if !protocol.ClientStrictValidation {
return nil
}

_, errors, err := schemas.Validate(schemas.ReplyV1, data)
if err != nil {
err = fmt.Errorf("Could not validate Reply JSON data: %s", err)
Expand Down
4 changes: 4 additions & 0 deletions protocol/v1/security_reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func (r *secureReply) Version() string {

// IsValidJSON validates the given JSON data against the schema
func (r *secureReply) IsValidJSON(data string) (err error) {
if !protocol.ClientStrictValidation {
return nil
}

_, errors, err := schemas.Validate(schemas.SecureReplyV1, data)
if err != nil {
err = fmt.Errorf("Could not validate SecureReply JSON data: %s", err)
Expand Down
4 changes: 4 additions & 0 deletions protocol/v1/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ func (m *transportMessage) Version() string {

// IsValidJSON validates the given JSON data against the Transport schema
func (m *transportMessage) IsValidJSON(data string) (err error) {
if !protocol.ClientStrictValidation {
return nil
}

_, errors, err := schemas.Validate(schemas.TransportV1, data)
if err != nil {
err = fmt.Errorf("Could not validate Transport JSON data: %s", err)
Expand Down

0 comments on commit 0afaad0

Please sign in to comment.