Documentation ¶
Index ¶
- Variables
- func AgentReboot(ctx *Context, devID, appID int64, force bool) error
- func AppDelete(ctx *Context, id int64) (bool, error)
- func AppGetAPIKey(ctx *Context, name string) ([]byte, error)
- func Authenticate(ctx *Context, typ AuthType, authToken ...string) (string, error)
- func DevBlink(ctx *Context, uuid string) error
- func DevDelete(ctx *Context, id int64) error
- func DevDisableURL(ctx *Context, uuid string) error
- func DevEnableURL(ctx *Context, uuid string) error
- func DevIsOnline(ctx *Context, uuid string) (bool, error)
- func DevMove(ctx *Context, id int64, appID int64) error
- func DevNote(ctx *Context, id int64, note string) error
- func DevRename(ctx *Context, uuid, newName string) error
- func Encode(q url.Values) string
- func EnvAppDelete(ctx *Context, id int64) error
- func EnvAppUpdate(ctx *Context, id int64, value string) error
- func EnvDevDelete(ctx *Context, id int64) error
- func EnvDevUpdate(ctx *Context, id int64, value string) error
- func GenerateUUID() (string, error)
- func KeyRemove(ctx *Context, id int64) error
- func Login(ctx *Context, authTyp AuthType, authToken ...string) error
- func ValidToken(tok string) bool
- type APIVersion
- type AppEnv
- type Application
- func AppCreate(ctx *Context, name string, typ DeviceType) (*Application, error)
- func AppGetAll(ctx *Context) ([]*Application, error)
- func AppGetByID(ctx *Context, id int64) (*Application, error)
- func AppGetByName(ctx *Context, name string) (*Application, error)
- func DevGetApp(ctx *Context, uuid string) (*Application, error)
- type AuthType
- type Config
- type Context
- type Device
- func DevGetAll(ctx *Context) ([]*Device, error)
- func DevGetAllByApp(ctx *Context, appID int64) ([]*Device, error)
- func DevGetByName(ctx *Context, name string) (*Device, error)
- func DevGetByUUID(ctx *Context, uuid string) (*Device, error)
- func DevRegister(ctx *Context, appName, uuid string) (*Device, error)
- type DeviceType
- type Env
- type HTTPClient
- type Key
- type Logs
- type Repository
- type ResinConfig
- type TokenClain
- type User
Constants ¶
This section is empty.
Variables ¶
var ErrBadToken = errors.New("resingo: bad session token")
ErrBadToken error returned when the resin session token is bad.
var ErrDeviceNotFound = errors.New("resingo: device not found")
ErrDeviceNotFound is returned when there is no device returned from an API call for devices.
We assume that, a valid API call will alwayss return with valid results, so lack of any matching devices means we didn't find anything.
NOTE: This should have been handled by resin api. Probably with status codes and the response body indicating nothing was dound.
var ErrMissingCredentials = errors.New("resingo: missing credentials( username or password)")
ErrMissingCredentials error returned when either username or password is missing
var ErrUnkownAuthType = errors.New("resingo: unknown authentication type")
ErrUnkownAuthType error returned when the type of authentication is not supported.
Functions ¶
func AgentReboot ¶
AgentReboot reboots the device
func AppGetAPIKey ¶
AppGetAPIKey returns the application with the given api key
func Authenticate ¶
Authenticate authenticates the client and returns the Auth token. See Login if you want to save the token in the client. This function does not save the authentication token and user detals.
func DevDisableURL ¶
DevDisableURL diables the deice url, making it not accessible via the web.
func DevEnableURL ¶
DevEnableURL enables the device url. This allows the device to be accessed anywhere using the url which uses resin vpn.
NOTE: It is awskward to retrurn OK rather than the url which was enabled.
func DevIsOnline ¶
DevIsOnline return true if the device with uuid is online and false otherwise. Any errors encountered is returned too.
func Encode ¶
Encode encode properly the request params for use with resin API.
Encode tartegts the filter param, which for some reasom(based on OData) is supposed to be $filter and not filter. The value specified by the eq param key is combined with the value from the fileter key to produce the $filter value string.
Any other url params are encoded by the default encoder from url.Values.Encoder. TODO: check a better way to encode OData url params.
func EnvAppDelete ¶
EnvAppDelete deletes application environment variable
func EnvAppUpdate ¶
EnvAppUpdate updates an existing application environmant variable
func EnvDevDelete ¶
EnvDevDelete deketes device environment variable
func EnvDevUpdate ¶
EnvDevUpdate updates environment variable for device. The id is for the environmant variable.
func GenerateUUID ¶
GenerateUUID generates uuid suitable for resin devices
Types ¶
type APIVersion ¶
type APIVersion int
APIVersion is the version of resin API
const ( VersionOne APIVersion = iota VersionTwo VersionThree )
supported resin API versions
func (APIVersion) String ¶
func (v APIVersion) String() string
type AppEnv ¶
type AppEnv struct { ID int64 `json:"id"` Name string `json:"name"` Value string `json:"value"` Application struct { ID int64 `json:"__id"` Deferred struct { URI string `json:"uri"` } `json:"__deferred"` } `json:"application"` Metadata struct { URI string `json:"uri"` Type string `json:"type"` } `json:"__metadata"` }
AppEnv application environment variable
func EnvAppCreate ¶
EnvAppCreate creates a newapplication environment variable
type Application ¶
type Application struct { ID int64 `json:"id"` Name string `json:"app_name"` Repository string `json:"git_repository"` Metadata struct { URI string `json:"uri"` Type string `json:"type"` } `json:"__metadata"` DeviceType string `json:"device_type"` User User `json:"user"` Commit string `json:"commit"` }
Application holds information about the application that is running on resin.
func AppCreate ¶
func AppCreate(ctx *Context, name string, typ DeviceType) (*Application, error)
AppCreate creates a new application with the given name
func AppGetAll ¶
func AppGetAll(ctx *Context) ([]*Application, error)
AppGetAll retrieves all applications that belog to the user in the given context.
For this to work, the context should be authorized, probably using the Login function.
func AppGetByID ¶
func AppGetByID(ctx *Context, id int64) (*Application, error)
AppGetByID returns application with the given id
func AppGetByName ¶
func AppGetByName(ctx *Context, name string) (*Application, error)
AppGetByName returns the application with the giveb name.
func DevGetApp ¶
func DevGetApp(ctx *Context, uuid string) (*Application, error)
DevGetApp returns the application in which the device belongs to. This function is convenient only when you are interested on other information about the application.
If your intention is only to retrieve the applicayion id, then just use this instead.
dev,err:=DevGetByUUID(ctx,<uuid goes here>) if err!=nil{ //handle error error } // you can now access the application id like this fmt.Println(dev.Application.ID
type AuthType ¶
type AuthType int
AuthType is the authentication type that is used to authenticate with a resin.io api.
type Config ¶
type Config struct { AuthToken string Username string Password string APIKey string ResinEndpoint string ResinVersion APIVersion // contains filtered or unexported fields }
Config is the configuration object for the Client
func (*Config) APIEndpoint ¶
APIEndpoint returns a url that points to the given endpoint. This adds the resin.io api host and version.
func (*Config) IsValidToken ¶
IsValidToken return true if the token tok is a valid resin session token.
This method ecodes the token. A token that can't be doced is bad token. Any token that has expired is also a bad token.
type Context ¶
type Context struct { Client HTTPClient Config *Config }
Context holds information necessary to make a call to the resin API
type Device ¶
type Device struct { ID int64 `json:"id"` Name string `json:"name"` WebAccessible bool `json:"is_web_accessible"` Type string `json:"device_type"` Application struct { ID int64 `json:"__id"` Metadata struct { URI string `json:"uri"` } `json:"__deferred"` } `json:"application"` UUID string `json:"uuid"` User User `json:"user"` Actor int64 `json:"actor"` IsOnline bool `json:"is_online"` Commit string `json:"commit"` Status string `json:"status"` LastConnectivityEvent null.Time `json:"last_connectivity_event"` IP string `json:"ip_address"` VPNAddr string `json:"vpn_address"` PublicAddr string `json:"public_address"` SuprevisorVersion string `json:"supervisor_version"` Note string `json:"note"` OsVersion string `json:"os_version"` Location string `json:"location"` Longitude string `json:"longitude"` Latitude string `json:"latitude"` LogsChannel string `json:"logs_channel"` }
Device represent the information about a resin device
func DevGetAll ¶
DevGetAll returns all devices that belong to the user who authorized the context ctx.
func DevGetAllByApp ¶
DevGetAllByApp returns all devices that are registered to the application with the given appID
func DevGetByName ¶
DevGetByName returns the device with the given name
func DevGetByUUID ¶
DevGetByUUID returns the device with the given uuid.
type DeviceType ¶
type DeviceType int
DeviceType is the identity of the the device that is supported by resin.
const ( Artik10 DeviceType = iota Artik5 BeagleboneBlack HumingBoard IntelAdison IntelNuc Nitrogen6x OdroidC1 OdroidXu4 Parallella RaspberryPi RaspberryPi2 RaspberryPi3 Ts4900 Ts700 ViaVabx820Quad ZyncXz702 )
supported devices
func (DeviceType) String ¶
func (d DeviceType) String() string
type Env ¶
type Env struct { ID int64 `json:"id"` Name string `json:"env_var_name"` Value string `json:"value"` Device struct { ID int64 `json:"__id"` Deferred struct { URI string `json:"uri"` } `json:"__deferred"` } `json:"device"` Metadata struct { URI string `json:"uri"` Type string `json:"type"` } `json:"__metadata"` }
Env contains the response for device environment variable
func EnvDevCreate ¶
EnvDevCreate creates environment variable for the device
type HTTPClient ¶
type HTTPClient interface { Do(*http.Request) (*http.Response, error) Post(url string, bodyTyp string, body io.Reader) (*http.Response, error) }
HTTPClient is an interface for a http clinet that is used to communicate with the resin API
type Key ¶
type Key struct { ID int64 `json:"id"` Title string `json:"title"` PublicKey string `json:"public_key"` User struct { ID int64 `json:"__id"` Deferred struct { URI string `json:"uri"` } `json:"__deferred"` } `json:"user"` Metadata struct { URI string `json:"uri"` Type string `json:"type"` } `json:"__metadata"` CreatedAt time.Time `json:"created_at"` }
Key is a user public key on resin
type Logs ¶
type Logs struct {
// contains filtered or unexported fields
}
Logs streams resin device logs
Resin uses pubnub service for logs. Unfortunate the API for pubnub sucks big time. This Limits the API for this struct too.
func NewLogs ¶
NewLogs returns a new Logs instace which is initialized to support streaming logs from pubnub.
func (*Logs) GetChannel ¶
GetChannel returns the device logs channel for the device with given uuid.. The value is not cached, so this is stateless. This allows to use the same Lofs instance to syvscribe to multiple devices in different goroutines without race conditions.
type Repository ¶
Repository is a resin remote repository
type ResinConfig ¶
type ResinConfig struct { SocialProviders []string `json:"supportedSocialProviders"` SignupCodeRequired bool `json:"signupCodeRequired"` MixPanelToken string `json:"mixpanelToken"` KeenProjectID string `json:"keenProjectId"` KeenReadKey string `json:"keenReadKey"` DeviceURLBase string `json:"deviceUrlsBase"` GitServerURL string `json:"gitServerUrl"` ImageMakerURL string `json:"imgMakerUrl"` AdminURL string `json:"adminUrl"` DebugEnabled bool `json:"debugEnabled"` PubNub struct { PubKey string `json:"publish_key"` SubKey string `json:"subscribe_key"` } `json:"pubnub"` GoogleAnalytics struct { ID string `kson:"id"` Site string `json:"site"` } `json:"ga"` DeviceTypes []struct { Slug string `json:"slug"` Version int `json:"version"` Aliases []string `json:"aliases"` Name string `json:"name"` Arch string `json:"arch"` State string `json:"state"` StateInstructions struct { PostProvisioning []string `json:"postProvisioning"` } `json:"stateInstructions"` //Instructions []string `json:"instructions"` SupportsBlink bool `json:"supportsBlink"` Yocto struct { Machine string `json:"machine"` Image string `json:"image"` FSType string `json:"fstype"` Version string `json:"version"` DeployArtfact string `json:"deployArtfact"` Compressed bool `json:"compressed"` } `json:"yocto"` Options []struct { IsGroup bool `json:"isGroup"` Name string `json:"name"` Message string `json:"message"` Options []struct { Name string `json:"name"` Message string `json:"message"` Type string `json:"type"` CHoices []string `json:"choices"` } `json:"options"` } `json:"options"` Configuration struct { Config struct { Partition struct { Primary int `json:"primary"` } `json:"partition"` } `json:"config"` } `json:"configuration"` Initialization struct { Options []struct { Name string `json:"name"` Message string `json:"message"` Type string `json:"type"` } `json:"options"` Operations []struct { Command string `json:"command"` } `json:"operations"` } `json:"initialization"` BuildID string `json:"buildId"` } `json:"deviceTypes"` }
ResinConfig resin configuration
func ConfigGetAll ¶
func ConfigGetAll(ctx *Context) (*ResinConfig, error)
ConfigGetAll return resin congiguration
type TokenClain ¶
type TokenClain struct { Username string `json:"username"` UserID int64 `json:"id"` Email string `json:"email"` jwt.StandardClaims }
TokenClain are the values that are encoded into a session token from resin.io.
It embeds jst.StandardClaims, so as to help with Verification of expired data. Resin doens't do claim verification :(.
func ParseToken ¶
func ParseToken(tok string) (*TokenClain, error)
ParseToken parses the given token and extracts the claims emcode into it. This function uses JWT method to parse the token, with verification of claims turned off.