object

package
v0.11.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2020 License: MIT Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ErrInvalidSigner    = errors.Error("signer is does not match owner")
	ErrMissingSignature = errors.Error("missing signature")
	ErrCouldNotVerify   = errors.Error("could not verify signature")
)
View Source
const (
	// AlgorithmObjectHash for creating ObjectHash+ES256 based signatures
	AlgorithmObjectHash = "OH_ES256"
)
View Source
const (
	ErrNoSignature = errors.Error("object has no signature")
)
View Source
const (
	ErrReaderDone = errors.Error("reader done")
)

Variables

View Source
var (
	// ErrInvalidObjectType is returned when the signature being verified
	// is not an encoded object of type "signature".
	ErrInvalidObjectType = errors.New("invalid object type")
	// ErrAlgorithNotImplemented is returned when the algorithm specified
	// has not been implemented
	ErrAlgorithNotImplemented = errors.New("algorithm not implemented")
)
View Source
var (
	ErrTimeout = errors.New("timeout")
)

Functions

func Dump

func Dump(o Object, skipKeys ...string) string

Dump returns the object as pretty-printed json

func Normalize added in v0.5.0

func Normalize(i interface{}) (map[string]interface{}, error)

Normalize maps to get them ready to be used as objects. This is supposed to convert a map's values into something more usable by using the type hints from the key as guide. A lot of what this does is due to the types go's JSON unmarshaller uses when unmarshalling into an `interface{}`. More info about this here: https://golang.org/pkg/encoding/json/#Unmarshal

For example: * `"some-data:d": []float64{1, 2}` becomes `"some-data:d": []byte{1, 2}` * `"some-data:d": "AQI="` becomes `"some-data:d": []byte{1, 2}` * `"some-int:i": float64(7)` becomes `"some-int:i": uint64(7)` * `"some-int:i": "7"` becomes `"some-int:i": uint64(7)`

NOTE: This should work for the most part but needs additional testing.

func NormalizeData added in v0.5.0

func NormalizeData(i interface{}) ([]byte, error)

func SortHashSlice added in v0.11.0

func SortHashSlice(h []Hash)

func Traverse added in v0.10.0

func Traverse(v Value, f func(string, Value) bool)

func UnloadReferences added in v0.11.0

func UnloadReferences(
	ctx context.Context,
	obj Object,
) (
	result *Object,
	unloaded []Object,
	err error,
)

func Verify added in v0.5.0

func Verify(o Object) error

Verify object TODO should this verify nested objects as well?

Types

type Bool added in v0.10.0

type Bool bool

func (Bool) Hash added in v0.10.0

func (v Bool) Hash() Hash

func (Bool) IsBool added in v0.10.0

func (v Bool) IsBool() bool

func (Bool) IsBytes added in v0.10.0

func (v Bool) IsBytes() bool

func (Bool) IsFloat added in v0.10.0

func (v Bool) IsFloat() bool

func (Bool) IsInt added in v0.10.0

func (v Bool) IsInt() bool

func (Bool) IsList added in v0.10.0

func (v Bool) IsList() bool

func (Bool) IsMap added in v0.10.0

func (v Bool) IsMap() bool

func (Bool) IsRef added in v0.10.0

func (v Bool) IsRef() bool

func (Bool) IsString added in v0.10.0

func (v Bool) IsString() bool

func (Bool) PrimitiveHinted added in v0.10.0

func (v Bool) PrimitiveHinted() interface{}

type Bytes added in v0.10.0

type Bytes []byte

func (Bytes) Hash added in v0.10.0

func (v Bytes) Hash() Hash

func (Bytes) IsBool added in v0.10.0

func (v Bytes) IsBool() bool

func (Bytes) IsBytes added in v0.10.0

func (v Bytes) IsBytes() bool

func (Bytes) IsFloat added in v0.10.0

func (v Bytes) IsFloat() bool

func (Bytes) IsInt added in v0.10.0

func (v Bytes) IsInt() bool

func (Bytes) IsList added in v0.10.0

func (v Bytes) IsList() bool

func (Bytes) IsMap added in v0.10.0

func (v Bytes) IsMap() bool

func (Bytes) IsRef added in v0.10.0

func (v Bytes) IsRef() bool

func (Bytes) IsString added in v0.10.0

func (v Bytes) IsString() bool

func (Bytes) PrimitiveHinted added in v0.10.0

func (v Bytes) PrimitiveHinted() interface{}

type Certificate added in v0.5.0

type Certificate struct {
	Metadata Metadata
	Nonce    string
	Created  string
	Expires  string
	// contains filtered or unexported fields
}

func NewCertificate added in v0.5.0

func NewCertificate(
	subject crypto.PublicKey,
	issuer crypto.PrivateKey,
) (*Certificate, error)

func NewCertificateSelfSigned added in v0.11.0

func NewCertificateSelfSigned(k crypto.PrivateKey) (*Certificate, error)

func (*Certificate) FromObject added in v0.5.0

func (e *Certificate) FromObject(o Object) error

func (Certificate) GetSchema added in v0.5.0

func (e Certificate) GetSchema() *SchemaObject

func (Certificate) GetType added in v0.5.0

func (e Certificate) GetType() string

func (Certificate) IsStreamRoot added in v0.11.0

func (e Certificate) IsStreamRoot() bool

func (Certificate) ToObject added in v0.5.0

func (e Certificate) ToObject() Object

type CertificateRequest added in v0.11.0

type CertificateRequest struct {
	Metadata               Metadata
	ApplicationName        string
	ApplicationDescription string
	ApplicationURL         string
	Subject                string
	Resources              []string
	Actions                []string
	Nonce                  string
	// contains filtered or unexported fields
}

func (*CertificateRequest) FromObject added in v0.11.0

func (e *CertificateRequest) FromObject(o Object) error

func (CertificateRequest) GetSchema added in v0.11.0

func (e CertificateRequest) GetSchema() *SchemaObject

func (CertificateRequest) GetType added in v0.11.0

func (e CertificateRequest) GetType() string

func (CertificateRequest) IsStreamRoot added in v0.11.0

func (e CertificateRequest) IsStreamRoot() bool

func (CertificateRequest) ToObject added in v0.11.0

func (e CertificateRequest) ToObject() Object

type Float added in v0.10.0

type Float float64

func (Float) Hash added in v0.10.0

func (v Float) Hash() Hash

func (Float) IsBool added in v0.10.0

func (v Float) IsBool() bool

func (Float) IsBytes added in v0.10.0

func (v Float) IsBytes() bool

func (Float) IsFloat added in v0.10.0

func (v Float) IsFloat() bool

func (Float) IsInt added in v0.10.0

func (v Float) IsInt() bool

func (Float) IsList added in v0.10.0

func (v Float) IsList() bool

func (Float) IsMap added in v0.10.0

func (v Float) IsMap() bool

func (Float) IsRef added in v0.10.0

func (v Float) IsRef() bool

func (Float) IsString added in v0.10.0

func (v Float) IsString() bool

func (Float) PrimitiveHinted added in v0.10.0

func (v Float) PrimitiveHinted() interface{}

type Getter added in v0.11.0

type Getter interface {
	Get(
		context.Context,
		Hash,
	) (*Object, error)
}

type GetterFunc added in v0.11.0

type GetterFunc func(
	context.Context,
	Hash,
) (*Object, error)

GetterFunc is an adapter to allow the use of ordinary functions as object.Getter

type Hash

type Hash string

func GetReferences added in v0.11.0

func GetReferences(o Object) []Hash

func (Hash) IsEmpty added in v0.5.0

func (h Hash) IsEmpty() bool

func (Hash) IsEqual added in v0.5.0

func (h Hash) IsEqual(c Hash) bool

func (Hash) String added in v0.5.0

func (h Hash) String() string

type Int added in v0.10.0

type Int int64

func (Int) Hash added in v0.10.0

func (v Int) Hash() Hash

func (Int) IsBool added in v0.10.0

func (v Int) IsBool() bool

func (Int) IsBytes added in v0.10.0

func (v Int) IsBytes() bool

func (Int) IsFloat added in v0.10.0

func (v Int) IsFloat() bool

func (Int) IsInt added in v0.10.0

func (v Int) IsInt() bool

func (Int) IsList added in v0.10.0

func (v Int) IsList() bool

func (Int) IsMap added in v0.10.0

func (v Int) IsMap() bool

func (Int) IsRef added in v0.10.0

func (v Int) IsRef() bool

func (Int) IsString added in v0.10.0

func (v Int) IsString() bool

func (Int) PrimitiveHinted added in v0.10.0

func (v Int) PrimitiveHinted() interface{}

type List added in v0.10.0

type List struct {
	// contains filtered or unexported fields
}

func (List) Append added in v0.10.0

func (l List) Append(v Value) List

func (List) Get added in v0.11.0

func (l List) Get(index int) Value

func (List) Hash added in v0.10.0

func (v List) Hash() Hash

func (List) IsBool added in v0.10.0

func (v List) IsBool() bool

func (List) IsBytes added in v0.10.0

func (v List) IsBytes() bool

func (List) IsFloat added in v0.10.0

func (v List) IsFloat() bool

func (List) IsInt added in v0.10.0

func (v List) IsInt() bool

func (List) IsList added in v0.10.0

func (v List) IsList() bool

func (List) IsMap added in v0.10.0

func (v List) IsMap() bool

func (List) IsRef added in v0.10.0

func (v List) IsRef() bool

func (List) IsString added in v0.10.0

func (v List) IsString() bool

func (List) Iterate added in v0.10.0

func (l List) Iterate(f func(int, Value) bool)

func (List) Length added in v0.10.0

func (l List) Length() (n int)

func (List) PrimitiveHinted added in v0.10.0

func (l List) PrimitiveHinted() interface{}

func (List) Set added in v0.11.0

func (l List) Set(path string, v Value) List

type Map added in v0.10.0

type Map struct {
	// contains filtered or unexported fields
}

func (Map) Hash added in v0.10.0

func (v Map) Hash() Hash

func (Map) IsBool added in v0.10.0

func (v Map) IsBool() bool

func (Map) IsBytes added in v0.10.0

func (v Map) IsBytes() bool

func (Map) IsEmpty added in v0.10.0

func (m Map) IsEmpty() bool

func (Map) IsFloat added in v0.10.0

func (v Map) IsFloat() bool

func (Map) IsInt added in v0.10.0

func (v Map) IsInt() bool

func (Map) IsList added in v0.10.0

func (v Map) IsList() bool

func (Map) IsMap added in v0.10.0

func (v Map) IsMap() bool

func (Map) IsRef added in v0.10.0

func (v Map) IsRef() bool

func (Map) IsString added in v0.10.0

func (v Map) IsString() bool

func (Map) Iterate added in v0.10.0

func (m Map) Iterate(f func(k string, v Value) bool)

func (Map) PrimitiveHinted added in v0.10.0

func (m Map) PrimitiveHinted() interface{}

func (Map) Set added in v0.10.0

func (m Map) Set(path string, v Value) Map

func (Map) Value added in v0.10.0

func (m Map) Value(path string) Value

type Metadata added in v0.11.0

type Metadata struct {
	Owner     crypto.PublicKey `json:"owner"`
	Parents   []Hash           `json:"parents"`
	Policy    Policy           `json:"policy"`
	Signature Signature        `json:"_signature"`
	Stream    Hash             `json:"stream"`
}

Metadata for object

type Object

type Object Map

Object for everything f12n

func Collapse added in v0.11.0

func Collapse(o Object) Object

Collapse the object's immutable values into a single layer in order to reduce its complexity. Most usually used for tests.

func FromMap

func FromMap(m map[string]interface{}) Object

FromMap returns an object from a map

func LoadReferences added in v0.11.0

func LoadReferences(
	ctx context.Context,
	objectHash Hash,
	getter GetterFunc,
) (*Object, error)

LoadReferences will look for references in the given object, request the referred objects using the getter, and will replace the references with the actual object before returning the complete

func ReadAll added in v0.11.0

func ReadAll(r Reader) ([]*Object, error)

ReadAll is a helper method that

func (Object) Get added in v0.4.0

func (o Object) Get(k string) interface{}

Get -

func (Object) GetOwner added in v0.11.0

func (o Object) GetOwner() crypto.PublicKey

func (Object) GetParents

func (o Object) GetParents() []Hash

func (Object) GetPolicy

func (o Object) GetPolicy() Policy

func (Object) GetSignature

func (o Object) GetSignature() Signature

func (Object) GetStream added in v0.5.0

func (o Object) GetStream() Hash

func (Object) GetType

func (o Object) GetType() string

func (Object) Hash

func (o Object) Hash() Hash

func (Object) IsEmpty added in v0.5.0

func (o Object) IsEmpty() bool

IsEmpty returns whether the object is empty

func (Object) Raw added in v0.5.0

func (o Object) Raw() Map

func (Object) Set added in v0.4.0

func (o Object) Set(k string, v interface{}) Object

Set -

func (Object) SetOwner added in v0.11.0

func (o Object) SetOwner(owner crypto.PublicKey) Object

func (Object) SetParents

func (o Object) SetParents(hashes []Hash) Object

func (Object) SetPolicy

func (o Object) SetPolicy(policy Policy) Object

func (Object) SetSignature

func (o Object) SetSignature(signature Signature) Object

func (Object) SetStream added in v0.5.0

func (o Object) SetStream(v Hash) Object

func (Object) SetType

func (o Object) SetType(v string) Object

func (Object) ToMap

func (o Object) ToMap() map[string]interface{}

ToMap returns the object as a map

func (Object) ToObject

func (o Object) ToObject() Object

ToObject returns the same object, this is a helper method for codegen

type ParsedType added in v0.11.0

type ParsedType struct {
	PrimaryType string
	Namespace   string
	Object      string
}

func ParseType added in v0.11.0

func ParseType(objectType string) ParsedType

type Policy

type Policy struct {
	Subjects  []string `json:"subjects:as,omitempty" mapstructure:"subjects:as,omitempty"`
	Resources []string `json:"resources:as,omitempty" mapstructure:"resources:as,omitempty"`
	Actions   []string `json:"actions:as,omitempty" mapstructure:"actions:as,omitempty"`
	Effect    string   `json:"effect:s,omitempty" mapstructure:"effect:s,omitempty"`
}

Policy for object metadata

func (Policy) IsEmpty added in v0.5.0

func (v Policy) IsEmpty() bool

type ReadCloser added in v0.11.0

type ReadCloser interface {
	Read() (*Object, error)
	Close()
}

func FetchWithReferences added in v0.11.0

func FetchWithReferences(
	ctx context.Context,
	getter GetterFunc,
	objectHash Hash,
) (ReadCloser, error)

FetchWithReferences will look for references in the given object, request the primary object and all referred objects using the getter, and will return them in a lazy loaded result.

func NewReadCloser added in v0.11.0

func NewReadCloser(
	ctx context.Context,
	objects <-chan *Object,
	errs <-chan error,
	closer chan<- struct{},
) ReadCloser

func NewReadCloserFromObjects added in v0.11.0

func NewReadCloserFromObjects(objects []Object) ReadCloser

NewReadCloserFromObjects is mainly used for testing and mocks that return a Reader, or ReadCloser.

type Reader added in v0.11.0

type Reader interface {
	Read() (*Object, error)
}

type Ref added in v0.10.0

type Ref Hash

func (Ref) Hash added in v0.10.0

func (v Ref) Hash() Hash

refs don't get re-hashed

func (Ref) IsBool added in v0.10.0

func (v Ref) IsBool() bool

func (Ref) IsBytes added in v0.10.0

func (v Ref) IsBytes() bool

func (Ref) IsFloat added in v0.10.0

func (v Ref) IsFloat() bool

func (Ref) IsInt added in v0.10.0

func (v Ref) IsInt() bool

func (Ref) IsList added in v0.10.0

func (v Ref) IsList() bool

func (Ref) IsMap added in v0.10.0

func (v Ref) IsMap() bool

func (Ref) IsRef added in v0.10.0

func (v Ref) IsRef() bool

func (Ref) IsString added in v0.10.0

func (v Ref) IsString() bool

func (Ref) PrimitiveHinted added in v0.10.0

func (v Ref) PrimitiveHinted() interface{}

type Request added in v0.11.0

type Request struct {
	Metadata              Metadata
	ObjectHash            Hash
	ExcludedNestedObjects bool
	// contains filtered or unexported fields
}

func (*Request) FromObject added in v0.11.0

func (e *Request) FromObject(o Object) error

func (Request) GetSchema added in v0.11.0

func (e Request) GetSchema() *SchemaObject

func (Request) GetType added in v0.11.0

func (e Request) GetType() string

func (Request) IsStreamRoot added in v0.11.0

func (e Request) IsStreamRoot() bool

func (Request) ToObject added in v0.11.0

func (e Request) ToObject() Object

type Response added in v0.11.0

type Response struct {
	Metadata   Metadata
	ObjectHash *Object
	// contains filtered or unexported fields
}

func (*Response) FromObject added in v0.11.0

func (e *Response) FromObject(o Object) error

func (Response) GetSchema added in v0.11.0

func (e Response) GetSchema() *SchemaObject

func (Response) GetType added in v0.11.0

func (e Response) GetType() string

func (Response) IsStreamRoot added in v0.11.0

func (e Response) IsStreamRoot() bool

func (Response) ToObject added in v0.11.0

func (e Response) ToObject() Object

type SchemaObject added in v0.5.0

type SchemaObject struct {
	Metadata   Metadata
	Properties []*SchemaProperty
	// contains filtered or unexported fields
}

func (*SchemaObject) FromObject added in v0.5.0

func (e *SchemaObject) FromObject(o Object) error

func (SchemaObject) GetType added in v0.5.0

func (e SchemaObject) GetType() string

func (SchemaObject) IsStreamRoot added in v0.11.0

func (e SchemaObject) IsStreamRoot() bool

func (SchemaObject) ToObject added in v0.5.0

func (e SchemaObject) ToObject() Object

type SchemaProperty added in v0.5.0

type SchemaProperty struct {
	Metadata   Metadata
	Name       string
	Type       string
	Hint       string
	IsRepeated bool
	IsOptional bool
	Properties []*SchemaProperty
	// contains filtered or unexported fields
}

func (*SchemaProperty) FromObject added in v0.5.0

func (e *SchemaProperty) FromObject(o Object) error

func (SchemaProperty) GetType added in v0.5.0

func (e SchemaProperty) GetType() string

func (SchemaProperty) IsStreamRoot added in v0.11.0

func (e SchemaProperty) IsStreamRoot() bool

func (SchemaProperty) ToObject added in v0.5.0

func (e SchemaProperty) ToObject() Object

type Signature added in v0.5.0

type Signature struct {
	Signer      crypto.PublicKey `json:"signer:s,omitempty" mapstructure:"signer:s,omitempty"`
	Alg         string           `json:"alg:s,omitempty" mapstructure:"alg:s,omitempty"`
	X           []byte           `json:"x:d,omitempty" mapstructure:"x:d,omitempty"`
	Certificate *Certificate     `json:"certificate:m,omitempty" mapstructure:"certificate:m,omitempty"`
}

func NewSignature added in v0.5.0

func NewSignature(
	k crypto.PrivateKey,
	o Object,
) (Signature, error)

NewSignature returns a signature given some bytes and a private key

func (Signature) IsEmpty added in v0.5.0

func (v Signature) IsEmpty() bool

func (Signature) ToMap added in v0.5.0

func (s Signature) ToMap() map[string]interface{}

type String added in v0.10.0

type String string

func (String) Hash added in v0.10.0

func (v String) Hash() Hash

func (String) IsBool added in v0.10.0

func (v String) IsBool() bool

func (String) IsBytes added in v0.10.0

func (v String) IsBytes() bool

func (String) IsFloat added in v0.10.0

func (v String) IsFloat() bool

func (String) IsInt added in v0.10.0

func (v String) IsInt() bool

func (String) IsList added in v0.10.0

func (v String) IsList() bool

func (String) IsMap added in v0.10.0

func (v String) IsMap() bool

func (String) IsRef added in v0.10.0

func (v String) IsRef() bool

func (String) IsString added in v0.10.0

func (v String) IsString() bool

func (String) PrimitiveHinted added in v0.10.0

func (v String) PrimitiveHinted() interface{}

type TypeHint

type TypeHint string

TypeHint are the hints of a member's type

const (
	HintUndefined TypeHint = ""
	HintMap       TypeHint = "m"
	HintArray     TypeHint = "a"
	HintBool      TypeHint = "b"
	HintData      TypeHint = "d"
	HintFloat     TypeHint = "f"
	HintInt       TypeHint = "i"
	HintNil       TypeHint = "n"
	HintString    TypeHint = "s"
	HintRef       TypeHint = "r"
	HintUint      TypeHint = "u"
)

func DeduceTypeHint

func DeduceTypeHint(o interface{}) TypeHint

DeduceTypeHint returns a TypeHint from a given value

func (TypeHint) String

func (t TypeHint) String() string

String implements the Stringer interface

type Value added in v0.10.0

type Value interface {
	PrimitiveHinted() interface{}
	Hash() Hash

	IsList() bool
	IsMap() bool
	IsBool() bool
	IsString() bool
	IsRef() bool
	IsInt() bool
	IsFloat() bool
	IsBytes() bool
	// contains filtered or unexported methods
}

func AnyToValue added in v0.10.0

func AnyToValue(k string, a interface{}) Value

nolint: gocritic

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL