Categorygithub.com/creatorkit/go-deviceserver-client
modulepackage
0.0.0-20170212200753-c126cd1049b3
Repository: https://github.com/creatorkit/go-deviceserver-client.git
Documentation: pkg.go.dev

# 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

# Packages

No description provided by the author

# Functions

Create constructs a deviceserver client from a provided hateoas client.
No description provided by the author
ParseVerify performs signature validation and returns byte string.
TokenFromPSK generates an JWT with signed OrgClaim.

# Variables

ErrorInvalidKeyName can be sent in response to CreateAccessKey.

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
JwtSigner is the main object for simplified JWT operations.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Client is the main object for interacting with the deviceserver.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author