deviceserver

package module
v0.0.0-...-c126cd1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2017 License: BSD-3-Clause Imports: 9 Imported by: 2

README

deviceserver

import "github.com/CreatorKit/go-deviceserver-client"

Overview

Golang client for the creatordev.io deviceserver REST API.

Index

Package files

deviceserver.go jwt.go struct.go

Variables

var (
    // ErrorInvalidKeyName can be sent in response to CreateAccessKey
    ErrorInvalidKeyName = errors.New("Invalid key name")
)

func ParseVerify

func ParseVerify(serialized []byte, signingKey interface{}) ([]byte, error)

ParseVerify performs signature validation and returns byte string

func TokenFromPSK

func TokenFromPSK(psk string, orgID int) (token string, err error)

TokenFromPSK generates an JWT with signed OrgClaim

type AccessKey

type AccessKey struct {
    Links  hateoas.Links `json:"Links"`
    Name   string        `json:"Name,omitempty"`
    Key    string        `json:"Key,omitempty"`
    Secret string        `json:"Secret,omitempty"`
}

type AccessKeys

type AccessKeys struct {
    PageInfo PageInfo      `json:"PageInfo"`
    Items    []AccessKey   `json:"Items"`
    Links    hateoas.Links `json:"Links"`
}

type Client

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

Client is the main object for interacting with the deviceserver

func Create
func Create(hclient *h.Client) (*Client, error)

Create constructs a deviceserver client from a provided hateoas client. If you want logging/caching etc, you should set those options during hateoas client initialisation

func (*Client) Authenticate
func (d *Client) Authenticate(credentials *AccessKey) error

Authenticate uses the provided key/secret to obtain an access_token/refresh_token

func (*Client) Close
func (d *Client) Close()

Close will clean things up as required

func (*Client) CreateAccessKey
func (d *Client) CreateAccessKey(name string) (*AccessKey, error)

CreateAccessKey does what it says on the tin. The client should already be authenticated somehow, by calling either Authenticate/RefreshAuth/SetBearerToken

func (*Client) Delete
func (d *Client) Delete(endpoint string) error

Delete performs DELETE on the specified resource

func (*Client) DeleteAccessKey
func (d *Client) DeleteAccessKey(key *AccessKey) error

DeleteAccessKey does what it says on the tin

func (*Client) DeleteSelf
func (d *Client) DeleteSelf(links *h.Links) error

DeleteSelf will find the "self" link and DELETE that

func (*Client) GetAccessKeys
func (d *Client) GetAccessKeys(previous *AccessKeys) (*AccessKeys, error)

GetAccessKeys returns the list of accesskeys in this organisation

func (*Client) HATEOAS
func (d *Client) HATEOAS() *h.Client

HATEOAS exposes the underlying hateoas client so that you can use that where necessary. Shouldn't be needed often.

func (*Client) RefreshAuth
func (d *Client) RefreshAuth(refreshToken string) error

RefreshAuth uses the provided refresh_token obtain an access_token/refresh_token

func (*Client) SetBearerToken
func (d *Client) SetBearerToken(token string)

SetBearerToken sets the Authorization header on the underlying hateoas client

func (*Client) Subscribe
func (d *Client) Subscribe(endpoint string, req *SubscriptionRequest, resp *SubscriptionResponse) error

Subscribe sets up webhook subscriptions, i.e. COAP observations. The endpoint can be

  • "" (=entrypoint) to subscribe to ClientConnected/ClientDisconnected events
  • a specific resource "self" URL to subscribe to observations on that resource
func (*Client) Unsubscribe
func (d *Client) Unsubscribe(subscription *SubscriptionResponse) error

type EntryPoint

type EntryPoint struct {
    Links hateoas.Links `json:"Links"`
}

type Error

type Error struct {
    ErrorCode    string `json:"ErrorCode"`
    ErrorMessage string `json:"ErrorMessage"`
    ErrorDetails string `json:"ErrorDetails"`
}

type JwtSigner

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

JwtSigner is the main object for simplified JWT operations

func (*JwtSigner) Init
func (s *JwtSigner) Init(alg jose.SignatureAlgorithm, signingKey interface{}) error

Init creates JOSE signer

func (*JwtSigner) MarshallSignSerialize
func (s *JwtSigner) MarshallSignSerialize(in interface{}) (string, error)

MarshallSignSerialize returns a compacted serialised JWT from a claims structure

type OAuthToken

type OAuthToken struct {
    AccessToken  string `json:"access_token"`
    TokenType    string `json:"token_type"`
    ExpiresIn    int    `json:"expires_in"`
    RefreshToken string `json:"refresh_token"`
}

type OrgClaim

type OrgClaim struct {
    OrgID int   `json:"OrgID"`
    Exp   int74 `json:"exp"`
}

type PageInfo

type PageInfo struct {
    TotalCount int           `json:"TotalCount"`
    ItemsCount int           `json:"ItemsCount"`
    StartIndex int           `json:"StartIndex"`
    Links      hateoas.Links `json:"Links,omitempty"`
}

type SubscriptionRequest

type SubscriptionRequest struct {
    SubscriptionType string `json:"SubscriptionType"`
    URL              string `json:"Url"`

    AcceptContentType string `json:"AcceptContentType,omitempty"`
    Property          string `json:"Property,omitempty"`
    Attributes        *struct {
        Pmin        string `json:"Pmin,omitempty"`
        Pmax        string `json:"Pmax,omitempty"`
        Step        string `json:"Step,omitempty"`
        LessThan    string `json:"LessThan,omitempty"`
        GreaterThan string `json:"GreaterThan,omitempty"`
    } `json:"Attributes,omitempty"`
}

type SubscriptionResponse

type SubscriptionResponse struct {
    ID    string        `json:"ID"`
    Links hateoas.Links `json:"Links"`
}

Generated by godoc12md

Documentation

Overview

Golang client for the creatordev.io deviceserver REST API.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorInvalidKeyName can be sent in response to CreateAccessKey
	ErrorInvalidKeyName = "Invalid key name"
)

Functions

func ParseVerify

func ParseVerify(serialized []byte, signingKey interface{}) ([]byte, error)

ParseVerify performs signature validation and returns byte string

func TokenFromPSK

func TokenFromPSK(psk string, orgID int) (token string, err error)

TokenFromPSK generates an JWT with signed OrgClaim

Types

type AccessKey

type AccessKey struct {
	Links  hateoas.Links `json:"Links"`
	Name   string        `json:"Name,omitempty"`
	Key    string        `json:"Key,omitempty"`
	Secret string        `json:"Secret,omitempty"`
}

type AccessKeys

type AccessKeys struct {
	PageInfo PageInfo      `json:"PageInfo"`
	Items    []AccessKey   `json:"Items"`
	Links    hateoas.Links `json:"Links"`
}

type Client

type Client struct {
	Name  string
	Links hateoas.Links `json:"Links"`
}

type Clients

type Clients struct {
	PageInfo PageInfo      `json:"PageInfo"`
	Items    []Client      `json:"Items"`
	Links    hateoas.Links `json:"Links"`
}

type EntryPoint

type EntryPoint struct {
	Links hateoas.Links `json:"Links"`
}

type Error

type Error struct {
	ErrorCode    string `json:"ErrorCode"`
	ErrorMessage string `json:"ErrorMessage"`
	ErrorDetails string `json:"ErrorDetails"`
}

type JwtSigner

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

JwtSigner is the main object for simplified JWT operations

func (*JwtSigner) Init

func (s *JwtSigner) Init(alg jose.SignatureAlgorithm, signingKey interface{}) error

Init creates JOSE signer

func (*JwtSigner) MarshallSignSerialize

func (s *JwtSigner) MarshallSignSerialize(in interface{}) (string, error)

MarshallSignSerialize returns a compacted serialised JWT from a claims structure

type OAuthToken

type OAuthToken struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
}

type ObjectDefinition

type ObjectDefinition struct {
	ObjectDefinitionID string                     `json:"ObjectDefinitionID"`
	ObjectID           string                     `json:"ObjectID"`
	Name               string                     `json:"Name"`
	MIMEType           string                     `json:"MIMEType"`
	Description        string                     `json:"Description"`
	SerialisationName  string                     `json:"SerialisationName"`
	Singleton          bool                       `json:"Singleton"`
	Properties         ObjectDefinitionProperties `json:"Properties"`
	Links              hateoas.Links              `json:"Links"`
}

type ObjectDefinitionProperties

type ObjectDefinitionProperties []ObjectDefinitionProperty

func (ObjectDefinitionProperties) Get

func (ObjectDefinitionProperties) String

type ObjectDefinitionProperty

type ObjectDefinitionProperty struct {
	PropertyDefinitionID string `json:"PropertyDefinitionID"`
	PropertyID           string `json:"PropertyID"`
	Name                 string `json:"Name"`
	Description          string `json:"Description"`
	DataType             string `json:"DataType"`
	Units                string `json:"Units"`
	IsCollection         bool   `json:"IsCollection"`
	IsMandatory          bool   `json:"IsMandatory"`
	Access               string `json:"Access"`
	SerialisationName    string `json:"SerialisationName"`
}

type ObjectDefinitionRegistry

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

func CreateObjectDefinitionRegistry

func CreateObjectDefinitionRegistry() *ObjectDefinitionRegistry

func (*ObjectDefinitionRegistry) GetByHref

func (r *ObjectDefinitionRegistry) GetByHref(href string) *ObjectDefinition

func (*ObjectDefinitionRegistry) GetByID

func (*ObjectDefinitionRegistry) Set

type ObjectInstance

type ObjectInstance map[string]interface{}

func (ObjectInstance) InstanceID

func (i ObjectInstance) InstanceID() int
func (i ObjectInstance) Links() *hateoas.Links

type ObjectInstances

type ObjectInstances struct {
	// see https://github.com/CreatorDev/DeviceServer/issues/25
	// PageInfo PageInfo         `json:"PageInfo"`
	Items []ObjectInstance `json:"Items"`
	Links hateoas.Links    `json:"Links"`
}

type ObjectType

type ObjectType struct {
	ObjectTypeID string        `json:"ObjectTypeID"`
	Links        hateoas.Links `json:"Links"`
}

type ObjectTypes

type ObjectTypes struct {
	PageInfo PageInfo     `json:"PageInfo"`
	Items    []ObjectType `json:"Items"`
}

type OrgClaim

type OrgClaim struct {
	OrgID int   `json:"OrgID"`
	Exp   int64 `json:"exp"`
}

type PageInfo

type PageInfo struct {
	TotalCount int           `json:"TotalCount"`
	ItemsCount int           `json:"ItemsCount"`
	StartIndex int           `json:"StartIndex"`
	Links      hateoas.Links `json:"Links,omitempty"`
}

type RESTClient

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

Client is the main object for interacting with the deviceserver

func Create

func Create(hclient *h.Client) (*RESTClient, error)

Create constructs a deviceserver client from a provided hateoas client. If you want logging/caching etc, you should set those options during hateoas client initialisation

func (*RESTClient) Authenticate

func (d *RESTClient) Authenticate(credentials *AccessKey) error

Authenticate uses the provided key/secret to obtain an access_token/refresh_token

func (*RESTClient) Close

func (d *RESTClient) Close()

Close will clean things up as required

func (*RESTClient) CreateAccessKey

func (d *RESTClient) CreateAccessKey(name string) (*AccessKey, error)

CreateAccessKey does what it says on the tin. The client should already be authenticated somehow, by calling either Authenticate/RefreshAuth/SetBearerToken

func (*RESTClient) Delete

func (d *RESTClient) Delete(endpoint string) error

Delete performs DELETE on the specified resource

func (*RESTClient) DeleteAccessKey

func (d *RESTClient) DeleteAccessKey(key *AccessKey) error

DeleteAccessKey does what it says on the tin

func (*RESTClient) DeleteSelf

func (d *RESTClient) DeleteSelf(links *h.Links) error

DeleteSelf will find the "self" link and DELETE that

func (*RESTClient) GetAccessKeys

func (d *RESTClient) GetAccessKeys(previous *AccessKeys) (*AccessKeys, error)

GetAccessKeys returns the list of accesskeys in this organisation

func (*RESTClient) GetClients

func (d *RESTClient) GetClients(previous *Clients) (*Clients, error)

func (*RESTClient) GetObjectInstances

func (d *RESTClient) GetObjectInstances(o *ObjectType) (*ObjectInstances, error)

func (*RESTClient) GetObjectTypes

func (d *RESTClient) GetObjectTypes(c *Client) (*ObjectTypes, error)

func (*RESTClient) GetSubscriptions

func (d *RESTClient) GetSubscriptions(endpoint string, previous *Subscriptions) (*Subscriptions, error)

func (*RESTClient) HATEOAS

func (d *RESTClient) HATEOAS() *h.Client

HATEOAS exposes the underlying hateoas client so that you can use that where necessary. Shouldn't be needed often.

func (*RESTClient) RefreshAuth

func (d *RESTClient) RefreshAuth(refreshToken string) error

RefreshAuth uses the provided refresh_token obtain an access_token/refresh_token

func (*RESTClient) SetBearerToken

func (d *RESTClient) SetBearerToken(token string)

SetBearerToken sets the Authorization header on the underlying hateoas client

func (*RESTClient) Subscribe

func (d *RESTClient) Subscribe(endpoint string, req *SubscriptionRequest, resp *SubscriptionResponse) error

Subscribe sets up webhook subscriptions, i.e. COAP observations. The `endpoint` can be - "" (=entrypoint) to subscribe to ClientConnected/ClientDisconnected events - a specific resource "self" URL to subscribe to observations on that resource

func (*RESTClient) Unsubscribe

func (d *RESTClient) Unsubscribe(subscription *SubscriptionResponse) error

type SubscriptionAttributes

type SubscriptionAttributes struct {
	Pmin        string `json:"Pmin,omitempty"`
	Pmax        string `json:"Pmax,omitempty"`
	Step        string `json:"Step,omitempty"`
	LessThan    string `json:"LessThan,omitempty"`
	GreaterThan string `json:"GreaterThan,omitempty"`
}

type SubscriptionRequest

type SubscriptionRequest struct {
	SubscriptionType string `json:"SubscriptionType"`
	URL              string `json:"Url"`

	AcceptContentType string                  `json:"AcceptContentType,omitempty"`
	Property          string                  `json:"Property,omitempty"`
	Attributes        *SubscriptionAttributes `json:"Attributes,omitempty"`
	Links             hateoas.Links           `json:"Links"`
}

type SubscriptionResponse

type SubscriptionResponse struct {
	ID    string        `json:"ID"`
	Links hateoas.Links `json:"Links"`
}

type Subscriptions

type Subscriptions struct {
	PageInfo PageInfo              `json:"PageInfo"`
	Items    []SubscriptionRequest `json:"Items"`
	Links    hateoas.Links         `json:"Links"`
}

type Webhook

type Webhook struct {
	Items []WebhookItem `json:"Items"`
}

type WebhookItem

type WebhookItem struct {
	SubscriptionType string                 `json:"SubscriptionType"`
	TimeTriggered    string                 `json:"TimeTriggered"`
	Value            map[string]interface{} `json:"Value"`
	Links            hateoas.Links          `json:"Links"`
}

Directories

Path Synopsis
cmd
Generic-ish HATEOAS client for golang
Generic-ish HATEOAS client for golang

Jump to

Keyboard shortcuts

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