bambou

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2018 License: BSD-3-Clause Imports: 14 Imported by: 12

Documentation

Overview

Package bambou provides the basic contructs used by ReST frameworks generated using Monolithe.

Bambou provides a set of objects that allow the manipulation of ReST entities very easily. It deals with all possible CRUD operations and defines all these low level operations in a single place.

Index

Constants

This section is empty.

Variables

View Source
var AllIdentity = Identity{
	Name:     "__all__",
	Category: "__all__",
}

AllIdentity represents all possible Identities.

Functions

func Logger

func Logger() *logging.Logger

Logger returns the defaut Bambou logger.

Types

type Error

type Error struct {
	Title       string `json:"title"`
	Description string `json:"description"`
}

func NewBambouError

func NewBambouError(title, description string) *Error

func NewError

func NewError(code int, description string) *Error

func (*Error) Error

func (be *Error) Error() string

Error returns the string representation of a Bambou Error (making it an "error") Valid JSON formatted

type Event

type Event struct {
	DataMap         []map[string]interface{} `json:"entities"`
	Data            []byte                   `json:"-"`
	EntityType      string                   `json:"entityType"`
	Type            string                   `json:"type"`
	UpdateMechanism string                   `json:"updateMechanism"`
}

Event represents one item of a Notification. It will contain data from the server regarding the object that has been created, deleted, or modified.

type EventHandler

type EventHandler func(*Event)

EventHandler is prototype of a Push Center Handler.

type EventsList

type EventsList []*Event

EventsList represents a list of *Event.

type FetchingInfo

type FetchingInfo struct {
	Filter     string
	FilterType string
	GroupBy    []string
	OrderBy    string
	Page       int
	PageSize   int
	TotalCount int
}

FetchingInfo is a structure that contains differents values about the fetching of children, either for the user to set, of for the server to fill. This structure will be used to pass and get back information during the fetching of some children.

func NewFetchingInfo

func NewFetchingInfo() *FetchingInfo

NewFetchingInfo returns a new *FetchingInfo

func (*FetchingInfo) String

func (f *FetchingInfo) String() string

String returns the string representation of the FetchingInfo.

type Identifiable

type Identifiable interface {

	// Identity returns the Identity of the of the receiver.
	Identity() Identity

	// Identifier returns the unique identifier of the of the receiver.
	Identifier() string

	// SetIdentifier sets the unique identifier of the of the receiver.
	SetIdentifier(string)
}

Identifiable is the interface that object which have Identity must implement.

type IdentifiablesList

type IdentifiablesList []Identifiable

IdentifiablesList is a list of objects implementing the Identifiable interface.

type Identity

type Identity struct {
	Name     string
	Category string
}

Identity is a structure that contains the necessary information about an Identifiable. The Name is usually the singular form of the Category. For instance, "enterprise" and "enterprises".

func (Identity) String

func (i Identity) String() string

String returns the string representation of the identity.

type Notification

type Notification struct {
	Events EventsList `json:"events"`
	UUID   string     `json:"uuid"`
}

Notification represents a collection of Event structures. It also contains a identifier for the Notification.

func NewNotification

func NewNotification() *Notification

NewNotification returns a new *Notification.

type NotificationsChannel

type NotificationsChannel chan *Notification

NotificationsChannel is used to received notification from the session

type PushCenter

type PushCenter struct {
	Channel NotificationsChannel
	// contains filtered or unexported fields
}

PushCenter is a structure that allows the user to deal with notifications. You can register multiple handlers for several Identity. When a notification is sent by the server and the Identity of its content matches one of the registered handler, this handler will be called.

func NewPushCenter

func NewPushCenter(session *Session) *PushCenter

NewPushCenter creates a new PushCenter.

func (*PushCenter) HasHandlerForIdentity

func (p *PushCenter) HasHandlerForIdentity(identity Identity) bool

HasHandlerForIdentity verifies if the given identity has a registered handler.

func (*PushCenter) RegisterHandlerForIdentity

func (p *PushCenter) RegisterHandlerForIdentity(handler EventHandler, identity Identity)

RegisterHandlerForIdentity registers the given EventHandler for the given Entity Identity. You can pass the bambou.AllIdentity as identity to register the handler for all events. If you pass a handler for an Identity that is already registered the previous handler will be silently overwriten.

func (*PushCenter) Start

func (p *PushCenter) Start() error

Start starts the Push Center.

func (*PushCenter) Stop

func (p *PushCenter) Stop() error

Stop stops a running PushCenter.

func (*PushCenter) UnregisterHandlerForIdentity

func (p *PushCenter) UnregisterHandlerForIdentity(identity Identity)

UnregisterHandlerForIdentity unegisters the given EventHandler for the given Entity Identity.

type Rootable

type Rootable interface {
	Identifiable

	// APIKey returns the token that will be used to authentify the communication
	// between a Storer and the backend.
	APIKey() string

	// SetAPIKey sets the token used by the Storer.
	SetAPIKey(string)
}

Rootable is the interface that must be implemented by the root object of the API. A Rootable also implements the Identifiable interface.

type Session

type Session struct {
	Certificate  *tls.Certificate
	Username     string
	Password     string
	Organization string
	URL          string
	// contains filtered or unexported fields
}

Session represents a user session. It provides the entire communication layer with the backend. It must implement the Operationable interface. A session can be authenticated via 1) TLS certificates or 2) user + password (different API endpoints)

func NewSession

func NewSession(username, password, organization, url string, root Rootable) *Session

NewSession returns a new *Session You need to provide a Rootable object that will be used to contain the results of the authentication process, like the api key for instance. Authentication using user + password

func NewX509Session

func NewX509Session(cert *tls.Certificate, url string, root Rootable) *Session

func (*Session) AssignChildren

func (s *Session) AssignChildren(parent Identifiable, children []Identifiable, identity Identity) *Error

AssignChildren assigns the list of given child Identifiables to the given Identifiable parent in the server.

func (*Session) CreateChild

func (s *Session) CreateChild(parent Identifiable, child Identifiable) *Error

CreateChild creates a new child Identifiable under the given parent Identifiable in the server.

func (*Session) DeleteEntity

func (s *Session) DeleteEntity(object Identifiable) *Error

DeleteEntity deletes the given Identifiable from the server.

func (*Session) FetchChildren

func (s *Session) FetchChildren(parent Identifiable, identity Identity, dest interface{}, info *FetchingInfo) *Error

FetchChildren fetches the children with of given parent identified by the given Identity.

func (*Session) FetchEntity

func (s *Session) FetchEntity(object Identifiable) *Error

FetchEntity fetchs the given Identifiable from the server.

func (*Session) NextEvent

func (s *Session) NextEvent(channel NotificationsChannel, lastEventID string) *Error

NextEvent will return the next notification from the backend as it occurs and will send it to the correct channel.

func (*Session) Reset

func (s *Session) Reset()

Reset resets the session.

func (*Session) Root

func (s *Session) Root() Rootable

Root returns the Root API object.

func (*Session) SaveEntity

func (s *Session) SaveEntity(object Identifiable) *Error

SaveEntity saves the given Identifiable into the server.

func (*Session) SetInsecureSkipVerify

func (s *Session) SetInsecureSkipVerify(skip bool) *Error

Dummy function avail for backwards compat. Logic moved to the new session methods

func (*Session) Start

func (s *Session) Start() *Error

Start starts the session. At that point the authentication will be done.

type Storer

type Storer interface {
	Start() *Error
	Reset()
	Root() Rootable

	FetchEntity(Identifiable) *Error
	SaveEntity(Identifiable) *Error
	DeleteEntity(Identifiable) *Error
	FetchChildren(Identifiable, Identity, interface{}, *FetchingInfo) *Error
	CreateChild(Identifiable, Identifiable) *Error
	AssignChildren(Identifiable, []Identifiable, Identity) *Error
	NextEvent(NotificationsChannel, string) *Error
}

Storer is the interface that must be implemented by object that can perform CRUD operations on RemoteObjects.

func CurrentSession

func CurrentSession() Storer

CurrentSession returns the current active and authenticated Session.

type VsdError

type VsdError struct {
	Property     string  `json:"property"`
	Descriptions []Error `json:"descriptions"` // XXX -- note
}

type VsdErrorList

type VsdErrorList struct {
	VsdErrors    []VsdError `json:"errors"`
	VsdErrorCode int        `json:"internalErrorCode"`
}

Jump to

Keyboard shortcuts

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