raptor

package module
v5.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

README

Golang Raptor SDK

SDK for Raptor IoT platform (v5)

Usage

See ./*_test.go files for usage examples

Install dependencies

dep ensure

Documentation

Index

Constants

View Source
const (
	//SubjectTypeDevice device type subject
	SubjectTypeDevice SubjectType = "device"
	//SubjectTypeToken token type subject
	SubjectTypeToken = "token"
	//SubjectTypeTreeNode tree node type subject
	SubjectTypeTreeNode = "tree"
)
View Source
const (
	STREAM_LIST        string = "/stream/%s/%s"
	STREAM_PUSH               = STREAM_LIST
	STREAM_LAST_UPDATE        = STREAM_PUSH + "/lastUpdate"
	STREAM_PULL               = STREAM_PUSH
	STREAM_SEARCH             = STREAM_PUSH

	ACTION_INVOKE = "/action/%s/%s"
	ACTION_STATUS = ACTION_INVOKE

	PERMISSION_CHECK = "/auth/check"
	LOGIN            = "/auth/login"
	LOGOUT           = LOGIN
	REFRESH_TOKEN    = "/auth/refresh"

	USER_CREATE      = "/auth/user"
	USER_LIST        = USER_CREATE
	USER_GET         = USER_CREATE + "/%s"
	USER_IMPERSONATE = USER_GET + "/impersonate"
	USER_UPDATE      = USER_GET
	USER_DELETE      = USER_GET
	USER_GET_ME      = "/auth/me"
	USER_UPDATE_ME   = USER_GET_ME

	TOKEN_CREATE = "/auth/token"
	TOKEN_UPDATE = TOKEN_CREATE + "/%s"
	TOKEN_DELETE = TOKEN_UPDATE
	TOKEN_GET    = TOKEN_UPDATE
	TOKEN_LIST   = TOKEN_CREATE + "?uuid=%s"

	ROLE_CREATE = "/auth/role"
	ROLE_UPDATE = TOKEN_CREATE + "/%s"
	ROLE_DELETE = TOKEN_UPDATE
	ROLE_LIST   = TOKEN_CREATE

	PROFILE_GET_ALL    = "/profile/%s"
	PROFILE_GET        = PROFILE_GET_ALL + "/%s"
	PROFILE_SET        = PROFILE_GET
	PREFERENCES_DELETE = PROFILE_GET

	PERMISSION_GET     = "/auth/permission/%s/%s"
	PERMISSION_BY_USER = PERMISSION_GET + "/%s"
	PERMISSION_SET     = PERMISSION_GET

	TOKEN_PERMISSION_GET     = "/auth/permission/token/%s"
	TOKEN_PERMISSION_BY_USER = TOKEN_PERMISSION_GET + "/%s"
	TOKEN_PERMISSION_SET     = TOKEN_PERMISSION_GET

	INVENTORY_LIST   = "/inventory/"
	INVENTORY_SEARCH = INVENTORY_LIST + "search"
	INVENTORY_CREATE = INVENTORY_LIST
	INVENTORY_UPDATE = INVENTORY_LIST + "%s"
	INVENTORY_LOAD   = INVENTORY_UPDATE
	INVENTORY_DELETE = INVENTORY_UPDATE

	TREE_LIST        = "/tree/"
	TREE_CREATE      = TREE_LIST
	TREE_GET         = TREE_LIST + "%s"
	TREE_CHILDREN    = TREE_GET + "/children"
	TREE_ADD         = TREE_GET
	TREE_REMOVE      = TREE_GET
	TREE_REMOVE_TREE = TREE_GET + "tree"

	APP_LIST   = "/app/"
	APP_CREATE = APP_LIST
	APP_SEARCH = APP_LIST + "/search"
	APP_GET    = APP_LIST + "%s"
	APP_UPDATE = APP_GET
	APP_DELETE = APP_GET
)

Variables

This section is empty.

Functions

func DefaultClientOptions

func DefaultClientOptions() *models.ClientOptions

DefaultClientOptions create default client options

func FromJSON

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

FromJSON convert a raw value to a model

func LoadModelFromFile

func LoadModelFromFile(src string, m interface{}) error

LoadModelFromFile load a model from a JSON file

func LoadModelFromString

func LoadModelFromString(json string, m interface{}) error

LoadModelFromString load a config from a JSON string

func ToJSON

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

ToJSON convert the model to JSON string

Types

type Action

type Action struct {
	Raptor *Raptor
}

Action API client

func CreateAction

func CreateAction(r *Raptor) *Action

CreateAction instantiate a new API client

func (*Action) GetClient

func (a *Action) GetClient() models.Client

GetClient return a client instance

func (*Action) GetConfig

func (a *Action) GetConfig() models.Config

GetConfig return the configuration

func (*Action) GetStatus

func (a *Action) GetStatus(action *models.Action) (*models.ActionStatus, error)

GetStatus fetch the action status

func (*Action) Invoke

func (a *Action) Invoke(action *models.Action, body string) error

Invoke trigger an action

func (*Action) SetStatus

func (a *Action) SetStatus(status *models.ActionStatus) error

SetStatus set the action status

type Admin

type Admin struct {
	Raptor *Raptor
	// contains filtered or unexported fields
}

Admin API client

func CreateAdmin

func CreateAdmin(r *Raptor) *Admin

CreateAdmin instantiate a new API client

func (*Admin) Token

func (a *Admin) Token() *Token

Token handles Stream API

func (*Admin) User

func (a *Admin) User() *User

User handles Stream API

type App

type App struct {
	Raptor *Raptor
}

App API client

func CreateApp

func CreateApp(r *Raptor) *App

CreateApp instantiate a new API client

func (*App) Create

func (i *App) Create(app *models.App) error

Create a app

func (*App) Delete

func (i *App) Delete(app *models.App) error

Delete a app

func (*App) DeleteByID

func (i *App) DeleteByID(id string) error

DeleteByID a app by ID

func (*App) GetClient

func (i *App) GetClient() models.Client

GetClient return a client instance

func (*App) GetConfig

func (i *App) GetConfig() models.Config

GetConfig return the configuration

func (*App) List

func (i *App) List() (*models.AppPager, error)

List apps accessible by an user

func (*App) Load

func (i *App) Load(ID string) (*models.App, error)

Load a app by ID

func (*App) NewApp

func (i *App) NewApp() *models.App

NewApp return a new App instance

func (*App) NewAppQuery

func (i *App) NewAppQuery() *models.AppQuery

NewAppQuery return a new AppQuery instance

func (*App) Search

func (i *App) Search(q *models.AppQuery) (*models.AppPager, error)

Search for apps

func (*App) Update

func (i *App) Update(app *models.App) error

Update a app

type Auth

type Auth struct {
	Raptor *Raptor
	// contains filtered or unexported fields
}

Auth API client

func CreateAuth

func CreateAuth(r *Raptor) *Auth

CreateAuth instantiate a new API client

func (*Auth) GetClient

func (a *Auth) GetClient() models.Client

GetClient return a client instance

func (*Auth) GetConfig

func (a *Auth) GetConfig() models.Config

GetConfig return the configuration

func (*Auth) GetToken

func (a *Auth) GetToken() string

GetToken return the authentication token

func (*Auth) GetUser

func (a *Auth) GetUser() *models.User

GetUser return the authenticated user

func (*Auth) Login

func (a *Auth) Login() (*models.LoginState, error)

Login login a user with the provided credentials

func (*Auth) Logout

func (a *Auth) Logout() error

Logout logout an user

func (*Auth) Refresh

func (a *Auth) Refresh() (*models.LoginState, error)

Refresh a user token

type BrokerConnection

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

BrokerConnection track connection status to the broker

type Config

type Config struct {
	URL      string `json:"url"`
	Username string `json:"username"`
	Password string `json:"password"`
	Token    string `json:"token"`
}

Config a client configuration

func NewConfigFromFile

func NewConfigFromFile(src string) (*Config, error)

NewConfigFromFile load a config from a JSON file

func NewConfigFromString

func NewConfigFromString(json string) (*Config, error)

NewConfigFromString load a config from a JSON string

func (*Config) GetPassword

func (c *Config) GetPassword() string

GetPassword return password

func (*Config) GetToken

func (c *Config) GetToken() string

GetToken return token

func (*Config) GetURL

func (c *Config) GetURL() string

GetURL return URL

func (*Config) GetUsername

func (c *Config) GetUsername() string

GetUsername return username

type DefaultClient

type DefaultClient struct {
	Raptor *Raptor
	// contains filtered or unexported fields
}

DefaultClient IClient default implementation

func NewDefaultClient

func NewDefaultClient(c *Raptor) *DefaultClient

NewDefaultClient initialize a default client

func (*DefaultClient) Delete

func (c *DefaultClient) Delete(url string, opts *models.ClientOptions) error

Delete request

func (*DefaultClient) FromJSON

func (c *DefaultClient) FromJSON(raw []byte, i interface{}) error

FromJSON convert a raw value to a model

func (*DefaultClient) Get

func (c *DefaultClient) Get(url string, opts *models.ClientOptions) ([]byte, error)

Get request

func (*DefaultClient) GetBrokerClient

func (c *DefaultClient) GetBrokerClient() (mqtt.Client, error)

GetBrokerClient return a MQTT client

func (*DefaultClient) GetClient

func (c *DefaultClient) GetClient() models.Client

GetClient return a client instance

func (*DefaultClient) GetConfig

func (c *DefaultClient) GetConfig() *Config

GetConfig return the configuration

func (*DefaultClient) Post

func (c *DefaultClient) Post(url string, json interface{}, opts *models.ClientOptions) ([]byte, error)

Post request

func (*DefaultClient) Put

func (c *DefaultClient) Put(url string, json interface{}, opts *models.ClientOptions) ([]byte, error)

Put request

func (*DefaultClient) Subscribe

func (c *DefaultClient) Subscribe(topic string, cb func(event models.Payload)) error

Subscribe to topic

func (*DefaultClient) ToJSON

func (c *DefaultClient) ToJSON(i interface{}) ([]byte, error)

ToJSON convert the model to JSON string

func (*DefaultClient) Unsubscribe

func (c *DefaultClient) Unsubscribe(topic string, cb func(event models.Payload)) error

Unsubscribe from topic

type GenericPermission

type GenericPermission struct {
	Raptor *Raptor
	// contains filtered or unexported fields
}

GenericPermission API client abstract per subject ACL permission management

func (*GenericPermission) Get

func (s *GenericPermission) Get(subjectID int) ([]string, error)

Get the available device permissions

func (*GenericPermission) GetClient

func (s *GenericPermission) GetClient() models.Client

GetClient return a client instance

func (*GenericPermission) GetConfig

func (s *GenericPermission) GetConfig() models.Config

GetConfig return the configuration

func (*GenericPermission) Set

func (s *GenericPermission) Set(subjectID int, userID string, permissions []string) ([]string, error)

Set the token permissions

type Inventory

type Inventory struct {
	Raptor *Raptor
	// contains filtered or unexported fields
}

Inventory API client

func CreateInventory

func CreateInventory(r *Raptor) *Inventory

CreateInventory instantiate a new API client

func (*Inventory) Create

func (i *Inventory) Create(dev *models.Device) error

Create a device

func (*Inventory) Delete

func (i *Inventory) Delete(dev *models.Device) error

Delete a device

func (*Inventory) DeleteByID

func (i *Inventory) DeleteByID(id string) error

DeleteByID a device by ID

func (*Inventory) GetClient

func (i *Inventory) GetClient() models.Client

GetClient return a client instance

func (*Inventory) GetConfig

func (i *Inventory) GetConfig() models.Config

GetConfig return the configuration

func (*Inventory) List

func (i *Inventory) List() (*models.DevicePager, error)

List devices accessible by an user

func (*Inventory) Load

func (i *Inventory) Load(ID string) (*models.Device, error)

Load a device by ID

func (*Inventory) NewDevice

func (i *Inventory) NewDevice() *models.Device

NewDevice return a new Device instance

func (*Inventory) NewDeviceFromFile

func (i *Inventory) NewDeviceFromFile(src string) (*models.Device, error)

NewDeviceFromFile load a Device definition from a file

func (*Inventory) NewDeviceQuery

func (i *Inventory) NewDeviceQuery() *models.DeviceQuery

NewDeviceQuery return a new DeviceQuery instance

func (*Inventory) Permission

func (i *Inventory) Permission() Permission

Permission return the Permission API

func (*Inventory) Search

func (i *Inventory) Search(q *models.DeviceQuery) (*models.DevicePager, error)

Search for devices

func (*Inventory) Update

func (i *Inventory) Update(dev *models.Device) error

Update a device

type Permission

type Permission interface {
	GetConfig() models.Config
	GetClient() models.Client
	Get(subjectID int) ([]string, error)
	Set(subjectID int, userID string, permissions []string) ([]string, error)
}

Permission API client interface

func CreateDevicePermission

func CreateDevicePermission(r *Raptor) Permission

CreateDevicePermission instantiate a new API client

func CreatePermission

func CreatePermission(r *Raptor, subjectType SubjectType) Permission

CreatePermission instantiate a new API client specifying a subject

func CreateTokenPermission

func CreateTokenPermission(r *Raptor) Permission

CreateTokenPermission instantiate a new API client

func CreateTreeNodePermission

func CreateTreeNodePermission(r *Raptor) Permission

CreateTreeNodePermission instantiate a new API client

type Profile

type Profile struct {
	Raptor *Raptor
}

Profile API client

func CreateProfile

func CreateProfile(r *Raptor) *Profile

CreateProfile instantiate a new API client

func (*Profile) Get

func (s *Profile) Get(key string) ([]byte, error)

Get a stored value by key

func (*Profile) GetAll

func (s *Profile) GetAll() ([]byte, error)

GetAll retrieve all stored value for an user

func (*Profile) GetClient

func (s *Profile) GetClient() models.Client

GetClient return a client instance

func (*Profile) GetConfig

func (s *Profile) GetConfig() models.Config

GetConfig return the configuration

func (*Profile) Set

func (s *Profile) Set(key string, val []byte) ([]byte, error)

Set store a value by key

type Raptor

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

Raptor the SDK API wrapper

func New

func New(url string) (*Raptor, error)

New create a new SDK instance

func NewFromConfig

func NewFromConfig(config *Config) (*Raptor, error)

NewFromConfig create a new Raptor instance from a provided Config

func NewFromCredentials

func NewFromCredentials(url string, username string, password string) (*Raptor, error)

NewFromCredentials create a new Raptor instance using username & password authentication

func NewFromToken

func NewFromToken(url string, token string) (*Raptor, error)

NewFromToken create a new Raptor instance using token authentication

func (*Raptor) Action

func (r *Raptor) Action() *Action

Action handles Stream API

func (*Raptor) Admin

func (r *Raptor) Admin() *Admin

Admin handles authentication API

func (*Raptor) App

func (r *Raptor) App() *App

App handles App API

func (*Raptor) Auth

func (r *Raptor) Auth() *Auth

Auth handles authentication API

func (*Raptor) GetClient

func (r *Raptor) GetClient() models.Client

GetClient return a client instance

func (*Raptor) GetConfig

func (r *Raptor) GetConfig() *Config

GetConfig return the configuration

func (*Raptor) Inventory

func (r *Raptor) Inventory() *Inventory

Inventory handles Inventory API

func (*Raptor) LoadModelFromFile

func (r *Raptor) LoadModelFromFile(src string, m interface{}) error

LoadModelFromFile load a model from a JSON file

func (*Raptor) LoadModelFromString

func (r *Raptor) LoadModelFromString(src string, m interface{}) error

LoadModelFromString load a config from a JSON string

func (*Raptor) Profile

func (r *Raptor) Profile() *Profile

Profile handles user storage API

func (*Raptor) SetConfig

func (r *Raptor) SetConfig(config *Config) error

SetConfig update the configuration merging with previously set

func (*Raptor) SetCredentials

func (r *Raptor) SetCredentials(username string, password string) error

SetCredentials set username and password

func (*Raptor) SetToken

func (r *Raptor) SetToken(token string) error

SetToken set token

func (*Raptor) Stream

func (r *Raptor) Stream() *Stream

Stream handles Stream API

func (*Raptor) Tree

func (r *Raptor) Tree() *Tree

Tree handles Tree API

type Stream

type Stream struct {
	Raptor *Raptor
}

Stream API client

func CreateStream

func CreateStream(r *Raptor) *Stream

CreateStream instantiate a new API client

func (*Stream) Delete

func (s *Stream) Delete(stream *models.Stream) error

Delete drop the data of a stream

func (*Stream) GetClient

func (s *Stream) GetClient() models.Client

GetClient return a client instance

func (*Stream) GetConfig

func (s *Stream) GetConfig() models.Config

GetConfig return the configuration

func (*Stream) LastUpdate

func (s *Stream) LastUpdate(stream *models.Stream) (*models.Record, error)

LastUpdate fetch the last record stored

func (*Stream) Pull

func (s *Stream) Pull(stream *models.Stream, offset int, size int) ([]models.Record, error)

Pull stored data for a stream

func (*Stream) Push

func (s *Stream) Push(r *models.Record) error

Push data to the backend

func (*Stream) Search

func (s *Stream) Search(stream *models.Stream, q *models.DataQuery) ([]models.Record, error)

Search stored data for a stream

type SubjectType

type SubjectType string

SubjectType a subject for ACL enforcement

type Token

type Token struct {
	Raptor *Raptor
	// contains filtered or unexported fields
}

Token API client

func CreateToken

func CreateToken(r *Raptor) *Token

CreateToken instantiate a new API client

func (*Token) Create

func (s *Token) Create(token *models.Token) error

Create a token

func (*Token) Delete

func (s *Token) Delete(token *models.Token) error

Delete an user

func (*Token) GetClient

func (s *Token) GetClient() models.Client

GetClient return a client instance

func (*Token) GetConfig

func (s *Token) GetConfig() models.Config

GetConfig return the configuration

func (*Token) List

func (s *Token) List() ([]models.Token, error)

List the available token for the current user

func (*Token) ListByID

func (s *Token) ListByID(uuid string) ([]models.Token, error)

ListByID the available token for a user

func (*Token) Permission

func (s *Token) Permission() Permission

Permission return the Permission API

func (*Token) Read

func (s *Token) Read(id int) (*models.Token, error)

Read a token

func (*Token) Update

func (s *Token) Update(token *models.Token) error

Update a token

type Tree

type Tree struct {
	Raptor *Raptor
	// contains filtered or unexported fields
}

Tree API client

func CreateTree

func CreateTree(r *Raptor) *Tree

CreateTree instantiate a new API client

func (*Tree) Add

func (s *Tree) Add(node *models.TreeNode, childs []models.TreeNode) error

Add a leaf nodes to a branch node

func (*Tree) Children

func (s *Tree) Children(node *models.TreeNode) (*models.TreeNode, error)

Children return the children for a node

func (*Tree) Create

func (s *Tree) Create(node *models.TreeNode) (*models.TreeNode, error)

Create a new root node

func (*Tree) Delete

func (s *Tree) Delete(node *models.TreeNode) error

Delete a node

func (*Tree) GetClient

func (s *Tree) GetClient() models.Client

GetClient return a client instance

func (*Tree) GetConfig

func (s *Tree) GetConfig() models.Config

GetConfig return the configuration

func (*Tree) List

func (s *Tree) List() ([]models.TreeNode, error)

List the available trees

func (*Tree) Permission

func (s *Tree) Permission() Permission

Permission return the Permission API

func (*Tree) Tree

func (s *Tree) Tree(node *models.TreeNode) (*models.TreeNode, error)

Tree return the structure for a node

type User

type User struct {
	Raptor *Raptor
}

User API client

func CreateUser

func CreateUser(r *Raptor) *User

CreateUser instantiate a new API client

func (*User) Create

func (s *User) Create(user *models.User) error

Create an user

func (*User) Delete

func (s *User) Delete(user *models.User) error

Delete an user

func (*User) GetClient

func (s *User) GetClient() models.Client

GetClient return a client instance

func (*User) GetConfig

func (s *User) GetConfig() models.Config

GetConfig return the configuration

func (*User) List

func (s *User) List() ([]models.User, error)

List the available users

func (*User) Me

func (s *User) Me() (*models.User, error)

Me Read the user identified by the token

func (*User) Read

func (s *User) Read(id string) (*models.User, error)

Read an user

func (*User) Update

func (s *User) Update(user *models.User) error

Update an user

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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