Documentation ¶
Overview ¶
Package tools provides utilities for all the bus actors
Copyright 2015 Apcera Inc. All rights reserved. Copied from nats.go/encoders/protobuf and changed to use gogo/protobuf
Index ¶
- Constants
- Variables
- func CreateCSR(priv interface{}, hostDefs string, certSubject pkix.Name) (derBytes []byte, err error)
- func CreateCert(priv interface{}, ca bool, extKeyUsage x509.ExtKeyUsage, signerCertData []byte, ...) (certData []byte, err error)
- func CreateCertificateFromCSR(csr []byte, parent *x509.Certificate, priv interface{}, notAfter time.Time) ([]byte, error)
- func CreateClientCA(priv interface{}, notbefore, notafter time.Time, hostDefs string) (certData []byte, err error)
- func CreatePrivateKey() (privKeyData []byte, err error)
- func CreateServerRootCA(priv interface{}, notbefore, notafter time.Time, hostDefs string) (certData []byte, err error)
- func DumpEventValidator(ev EventValidator) (string, error)
- func GetCSRHash(csrDataStr string, decodePEM bool) string
- func PKeyToPEM(key *ecdsa.PrivateKey) ([]byte, error)
- func RandomString(n int) string
- func ReadPEM(blockType string, pemOrPath string) ([]byte, error)
- func ReadPEMCertificate(pemOrPath string) (*x509.Certificate, error)
- func ReadPEMPrivateKey(pemOrPath string) (*ecdsa.PrivateKey, error)
- func RequestWithInbox(nc *nats.Conn, subject, inbox string, data []byte, timeout time.Duration) (*nats.Msg, error)
- func ValidateAccountName(name string) bool
- func ValidateEventType(eventType string) bool
- type CustomInboxPrefixConn
- type EnvelopeFragmentSorter
- type EnvelopeValidator
- type EnvelopeValidatorWithQueue
- type EventValidator
- type ProtobufEncoder
- type WhoAmIConn
Constants ¶
const ( // Alpha contains the letters upper and lower cased Alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" // Num contains the 10 digits Num = "0123456789" // Dot is the dot char Dot = "." // Dash is the '-' char Dash = "-" // Underscore is the '_' char Underscore = "_" // EventTypeAllowerCharacters constains all the characters allowed in a event // type name EventTypeAllowerCharacters = Alpha + Num + Dash + Underscore + Dot // AccountNameCharacters contains characters allowed in a account name AccountNameCharacters = Alpha + Num + Dash + Underscore )
const (
PROTOBUF_ENCODER = "protobuf"
)
Additional index for registered Encoders.
Variables ¶
var ( ErrInvalidProtoMsgEncode = errors.New("nats: Invalid protobuf proto.Message object passed to encode") ErrInvalidProtoMsgDecode = errors.New("nats: Invalid protobuf proto.Message object passed to decode") )
var ( // ErrWrongEnvelope is returned by validator if an envelope with a wrong // ID is passed to it. ErrWrongEnvelope = errors.New("Wrong envelope") )
Functions ¶
func CreateCSR ¶
func CreateCSR( priv interface{}, hostDefs string, certSubject pkix.Name, ) (derBytes []byte, err error)
CreateCSR is used when creating CSRs. you need to provide a private Key
func CreateCert ¶
func CreateCert( priv interface{}, ca bool, extKeyUsage x509.ExtKeyUsage, signerCertData []byte, signerPrivKey []byte, notbefore, notafter time.Time, hostDefs string, organization []string, commonName string, ) (certData []byte, err error)
CreateCert creates either an X.509 certificate (self-signed or to be signed via the specified CA private key) or a PKCS #10 CSR. the result is a PEM encoded byte array
func CreateCertificateFromCSR ¶
func CreateCertificateFromCSR( csr []byte, parent *x509.Certificate, priv interface{}, notAfter time.Time, ) ([]byte, error)
CreateCertificateFromCSR creates a certificate using a csr as a template.
func CreateClientCA ¶
func CreateClientCA( priv interface{}, notbefore, notafter time.Time, hostDefs string, ) (certData []byte, err error)
CreateClientCA creates a self-signed X.509 CA for client connections.
func CreatePrivateKey ¶
CreatePrivateKey generates a private key and returns it, PEM-encoded.
func CreateServerRootCA ¶
func CreateServerRootCA( priv interface{}, notbefore, notafter time.Time, hostDefs string, ) (certData []byte, err error)
CreateServerRootCA creates a self-signed X.509 certificate used by the Xbus server. it returns a PEM encoded certificate in a byte array
func DumpEventValidator ¶
func DumpEventValidator(ev EventValidator) (string, error)
DumpEventValidator store a EventValidator in a string
func GetCSRHash ¶
GetCSRHash computes a SHA-1 hash of the specified certificate signing request; the output is prettyfied (2-char split). The hash is based on the DER data of the CSR. @param decodePEM: Whether the data is given as PEM-encoded data, in which case the DER data will be extracted from it.
func PKeyToPEM ¶
func PKeyToPEM(key *ecdsa.PrivateKey) ([]byte, error)
PKeyToPEM serialize a key to PEM encoding
func RandomString ¶
RandomString returns a random string of length 'n'
func ReadPEMCertificate ¶
func ReadPEMCertificate(pemOrPath string) (*x509.Certificate, error)
ReadPEMCertificate loads a x509.Certificate from a PEM file or content
func ReadPEMPrivateKey ¶
func ReadPEMPrivateKey(pemOrPath string) (*ecdsa.PrivateKey, error)
ReadPEMPrivateKey loads a x509.Certificate from a PEM file or content
func RequestWithInbox ¶
func RequestWithInbox(nc *nats.Conn, subject, inbox string, data []byte, timeout time.Duration) (*nats.Msg, error)
RequestWithInbox is a nats.Conn.Request that takes the reply instead of calculating it automatically
func ValidateAccountName ¶
ValidateAccountName returns true if the passed account name is valid
func ValidateEventType ¶
ValidateEventType returns true if the passed event type is valid
Types ¶
type CustomInboxPrefixConn ¶
type CustomInboxPrefixConn struct { *nats.Conn InboxPrefix string }
CustomInboxPrefixConn is a nats.Conn that uses a custom inbox prefix
func NewClientConn ¶
func NewClientConn(c *nats.Conn, ClientID string) *CustomInboxPrefixConn
NewClientConn returns a CustomInboxPrefixConn for a client
func NewServerToClientConn ¶
func NewServerToClientConn(c *nats.Conn, ClientID string) *CustomInboxPrefixConn
NewServerToClientConn returns a CustomInboxPrefixConn for a server talking to a given client
type EnvelopeFragmentSorter ¶
type EnvelopeFragmentSorter struct { EnvelopeValidator // contains filtered or unexported fields }
EnvelopeFragmentSorter sorts a stream of envelope fragments It is _not_ concurrency safe
func NewEnvelopeFragmentSorter ¶
func NewEnvelopeFragmentSorter() *EnvelopeFragmentSorter
NewEnvelopeFragmentSorter returns a new EnvelopeFragmentSorter
func (*EnvelopeFragmentSorter) Add ¶
func (s *EnvelopeFragmentSorter) Add(fragment *api.Envelope)
Add a fragment to the sorter queue
func (*EnvelopeFragmentSorter) Get ¶
func (s *EnvelopeFragmentSorter) Get() (*api.Envelope, error)
Get returns the current item
func (*EnvelopeFragmentSorter) Next ¶
func (s *EnvelopeFragmentSorter) Next() bool
Next switch to the next fragment if available
type EnvelopeValidator ¶
type EnvelopeValidator struct { EnvelopeID api.UUID ExpectedEvents []api.UUID EventTypesKnown bool Events map[api.UUID]EventValidator // Index if the last chunk of each event Complete bool Valid bool }
EnvelopeValidator handle a stream of chunks of envelope and calculate checksum on the fly. The event chunks in the stream must be ordered. Its state can be easily saved to later continuation
func NewEnvelopeValidator ¶
func NewEnvelopeValidator() EnvelopeValidator
NewEnvelopeValidator returns a new validator, and optionnaly feeds it some envelopes
func (*EnvelopeValidator) Add ¶
func (v *EnvelopeValidator) Add(envelope api.Envelope) error
Add adds an envelope
func (*EnvelopeValidator) Check ¶
func (v *EnvelopeValidator) Check() error
Check compare the current validation state with a final state
func (EnvelopeValidator) Clone ¶ added in v3.3.0
func (v EnvelopeValidator) Clone() EnvelopeValidator
Clone returns a copy of the validator
type EnvelopeValidatorWithQueue ¶
type EnvelopeValidatorWithQueue struct { EnvelopeValidator // contains filtered or unexported fields }
EnvelopeValidatorWithQueue queues fragments when they are not the next in line
func NewEnvelopeValidatorWithQueue ¶
func NewEnvelopeValidatorWithQueue() *EnvelopeValidatorWithQueue
NewEnvelopeValidatorWithQueue creates a new EnvelopeValidatorWithQueue
type EventValidator ¶
type EventValidator struct { EventID api.UUID Type string ItemCount uint64 Checksum api.Checksum CurrentIndex uint64 CurrentItemCount uint64 CurrentChecksum api.Checksum Complete bool Valid bool Error error `json:"-"` }
EventValidator handles a stream of event chunks of the same event
func LoadEventValidator ¶
func LoadEventValidator(s string) (ev EventValidator, err error)
LoadEventValidator loads a EventValidator from a string
func NewEventValidator ¶
func NewEventValidator(event api.Event) (EventValidator, error)
NewEventValidator initialize a EventValidator
func (EventValidator) MarshalJSON ¶
func (v EventValidator) MarshalJSON() ([]byte, error)
MarshalJSON serializes to json
func (*EventValidator) UnmarshalJSON ¶
func (v *EventValidator) UnmarshalJSON(data []byte) error
UnmarshalJSON deserialize a jsonified EventValidator
func (EventValidator) Update ¶
func (v EventValidator) Update(event api.Event) (EventValidator, error)
Update calculates a new intermediary state
type ProtobufEncoder ¶
type ProtobufEncoder struct { }
ProtobufEncoder is a protobuf implementation for EncodedConn This encoder will use the builtin protobuf lib to Marshal and Unmarshal structs.
type WhoAmIConn ¶
type WhoAmIConn struct {
*nats.Conn
}
WhoAmIConn is a conn with a very specific reply
func NewWhoAmIConn ¶
func NewWhoAmIConn(c *nats.Conn) WhoAmIConn
NewWhoAmIConn creates a new WhoAmIConn