iotservice

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2019 License: MIT Imports: 18 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// AckNone no feedback.
	AckNone = "none"

	// AckPositive receive a feedback message if the message was completed.
	AckPositive = "positive"

	// AckNegative receive a feedback message if the message expired
	// (or maximum delivery count was reached) without being completed by the device.
	AckNegative = "negative"

	// AckFull both positive and negative.
	AckFull = "full"
)
View Source
const (
	// AuthSAS uses symmetric keys to sign requests.
	AuthSAS = "sas"

	// AuthSelfSigned self signed certificate with a thumbprint.
	AuthSelfSigned = "selfSigned"

	// AuthCA certificate signed by a registered certificate authority.
	AuthCA = "certificateAuthority"
)

Variables

This section is empty.

Functions

func FromAMQPMessage

func FromAMQPMessage(msg *amqp.Message) *common.Message

FromAMQPMessage converts a amqp.Message into common.Message.

Exported to use with a custom stream when devices telemetry is routed for example to an EventhHub instance.

func NewSymmetricKey

func NewSymmetricKey() (string, error)

NewSymmetricKey generates a random symmetric key.

Types

type AuthType

type AuthType string

AuthType device authentication type.

type Authentication

type Authentication struct {
	SymmetricKey   *SymmetricKey   `json:"symmetricKey,omitempty"`
	X509Thumbprint *X509Thumbprint `json:"x509Thumbprint,omitempty"`
	Type           AuthType        `json:"type,omitempty"`
}

type CallOption

type CallOption func(c *call) error

CallOption is a direct-method invocation option.

func WithCallConnectTimeout

func WithCallConnectTimeout(seconds int) CallOption

ConnectTimeout is connection timeout in seconds.

func WithCallResponseTimeout

func WithCallResponseTimeout(seconds int) CallOption

ResponseTimeout is response timeout in seconds.

type Client

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

func New

func New(opts ...ClientOption) (*Client, error)

New creates new iothub service client.

func (*Client) Call

func (c *Client) Call(
	ctx context.Context,
	deviceID string,
	methodName string,
	payload map[string]interface{},
	opts ...CallOption,
) (*Result, error)

Call calls the named direct method on with the given parameters.

func (*Client) CancelJob

func (c *Client) CancelJob(ctx context.Context, jobID string) (map[string]interface{}, error)

func (*Client) Close

func (c *Client) Close() error

Close closes transport.

func (*Client) ConnectToAMQP

func (c *Client) ConnectToAMQP(ctx context.Context) error

ConnectToAMQP connects to the iothub AMQP broker, it's done automatically before publishing events or subscribing to the feedback topic.

func (*Client) CreateDevice

func (c *Client) CreateDevice(ctx context.Context, device *Device) (*Device, error)

CreateDevice creates a new device.

func (*Client) DeleteDevice

func (c *Client) DeleteDevice(ctx context.Context, deviceID string) error

DeleteDevice deletes the named device.

func (*Client) DeviceConnectionString

func (c *Client) DeviceConnectionString(device *Device, secondary bool) (string, error)

DeviceConnectionString builds up a connection string for the given device.

func (*Client) DeviceSAS

func (c *Client) DeviceSAS(device *Device, duration time.Duration, secondary bool) (string, error)

DeviceSAS generates a GenerateToken token for the named device.

func (*Client) ExportDevicesToBlob

func (c *Client) ExportDevicesToBlob(
	ctx context.Context,
	outputBlobURL string,
	excludeKeys bool,
) (map[string]interface{}, error)

func (*Client) GetDevice

func (c *Client) GetDevice(ctx context.Context, deviceID string) (*Device, error)

GetDevice retrieves the named device.

func (*Client) GetJob

func (c *Client) GetJob(ctx context.Context, jobID string) (map[string]interface{}, error)

func (*Client) GetTwin

func (c *Client) GetTwin(ctx context.Context, deviceID string) (*Twin, error)

GetTwin retrieves the named twin device from the registry.

func (*Client) HostName

func (c *Client) HostName() string

HostName returns service's hostname.

func (*Client) ImportDevicesFromBlob

func (c *Client) ImportDevicesFromBlob(
	ctx context.Context,
	inputBlobURL string,
	outputBlobURL string,
) (map[string]interface{}, error)

func (*Client) ListDevices

func (c *Client) ListDevices(ctx context.Context) ([]*Device, error)

ListDevices lists all registered devices.

func (*Client) ListJobs

func (c *Client) ListJobs(ctx context.Context) ([]map[string]interface{}, error)

func (*Client) SendEvent

func (c *Client) SendEvent(
	ctx context.Context,
	deviceID string,
	payload []byte,
	opts ...SendOption,
) error

SendEvent sends the given cloud-to-device message and returns its id. Panics when event is nil.

func (*Client) Stats

func (c *Client) Stats(ctx context.Context) (*Stats, error)

Stats retrieves the device registry statistic.

func (*Client) SubscribeEvents

func (c *Client) SubscribeEvents(ctx context.Context, fn MessageHandler) error

SubscribeEvents subscribes to device events. No need to call Connect first, because this method different connect method that dials an eventhub instance first opposed to SendEvent func.

func (*Client) SubscribeFeedback

func (c *Client) SubscribeFeedback(ctx context.Context, fn FeedbackHandler) error

SubscribeFeedback subscribes to feedback of messages that ack was requested.

func (*Client) UpdateDevice

func (c *Client) UpdateDevice(ctx context.Context, device *Device) (*Device, error)

UpdateDevice updates the named device.

func (*Client) UpdateTwin

func (c *Client) UpdateTwin(
	ctx context.Context,
	deviceID string,
	twin *Twin,
	etag string,
) (*Twin, error)

UpdateTwin updates the named twin desired properties.

type ClientOption

type ClientOption func(c *Client) error

ClientOption is a client connectivity option.

func WithConnectionString

func WithConnectionString(cs string) ClientOption

WithConnectionString parses the given connection string instead of using `WithCredentials`.

func WithCredentials

func WithCredentials(creds *sas.Credentials) ClientOption

WithCredentials uses the given credentials to generate GenerateToken tokens.

func WithHTTPClient

func WithHTTPClient(client *http.Client) ClientOption

WithHTTPClient changes default http rest client.

func WithLogger

func WithLogger(l common.Logger) ClientOption

WithLogger sets client logger.

type Device

type Device struct {
	DeviceID                   string                 `json:"deviceId,omitempty"`
	GenerationID               string                 `json:"generationId,omitempty"`
	ETag                       string                 `json:"etag,omitempty"`
	ConnectionState            string                 `json:"connectionState,omitempty"`
	Status                     string                 `json:"status,omitempty"`
	StatusReason               string                 `json:"statusReason,omitempty"`
	ConnectionStateUpdatedTime string                 `json:"connectionStateUpdatedTime,omitempty"`
	StatusUpdatedTime          string                 `json:"statusUpdatedTime,omitempty"`
	LastActivityTime           string                 `json:"lastActivityTime,omitempty"`
	CloudToDeviceMessageCount  int                    `json:"cloudToDeviceMessageCount,omitempty"`
	Authentication             *Authentication        `json:"authentication,omitempty"`
	Capabilities               map[string]interface{} `json:"capabilities,omitempty"`
}

type Feedback

type Feedback struct {
	OriginalMessageID  string    `json:"originalMessageId"`
	Description        string    `json:"description"`
	DeviceGenerationID string    `json:"deviceGenerationId"`
	DeviceID           string    `json:"deviceId"`
	EnqueuedTimeUTC    time.Time `json:"enqueuedTimeUtc"`
	StatusCode         string    `json:"statusCode"`
}

Feedback is message feedback.

type FeedbackHandler

type FeedbackHandler func(f *Feedback)

FeedbackHandler handles message feedback.

type MessageHandler

type MessageHandler func(e *common.Message)

MessageHandler handles incoming cloud-to-device events.

type Properties

type Properties struct {
	Desired  map[string]interface{} `json:"desired,omitempty"`
	Reported map[string]interface{} `json:"reported,omitempty"`
}

type Result

type Result struct {
	Status  int                    `json:"status,omitempty"`
	Payload map[string]interface{} `json:"payload,omitempty"`
}

Result is a direct-method call result.

type SendOption

type SendOption func(msg *common.Message) error

SendOption is a send option.

func WithSendAck

func WithSendAck(typ string) SendOption

WithSendAck sets message confirmation type.

func WithSendCorrelationID

func WithSendCorrelationID(cid string) SendOption

WithSendCorrelationID sets correlation id.

func WithSendMessageID

func WithSendMessageID(mid string) SendOption

WithSendMessageID sets message id.

func WithSendProperties

func WithSendProperties(m map[string]string) SendOption

WithSendProperties same as `WithSendProperty` but accepts map of keys and values.

func WithSendProperty

func WithSendProperty(k, v string) SendOption

WithSendProperty sets a message property.

func WithSendUserID

func WithSendUserID(uid string) SendOption

WithSendUserID sets user id.

func WithSentExpiryTime

func WithSentExpiryTime(t time.Time) SendOption

WithSentExpiryTime sets message expiration time.

type Stats

type Stats struct {
	DisabledDeviceCount int `json:"disabledDeviceCount,omitempty"`
	EnabledDeviceCount  int `json:"enabledDeviceCount,omitempty"`
	TotalDeviceCount    int `json:"totalDeviceCount,omitempty"`
}

type SymmetricKey

type SymmetricKey struct {
	PrimaryKey   string `json:"primaryKey,omitempty"`
	SecondaryKey string `json:"secondaryKey,omitempty"`
}

type Twin

type Twin struct {
	DeviceID                  string                 `json:"deviceId,omitempty"`
	ETag                      string                 `json:"etag,omitempty"`
	DeviceETag                string                 `json:"deviceEtag,omitempty"`
	Status                    string                 `json:"status,omitempty"`
	StatusReason              string                 `json:"statusReason,omitempty"`
	StatusUpdateTime          string                 `json:"statusUpdateTime,omitempty"`
	ConnectionState           string                 `json:"connectionState,omitempty"`
	LastActivityTime          string                 `json:"lastActivityTime,omitempty"`
	CloudToDeviceMessageCount int                    `json:"cloudToDeviceMessageCount,omitempty"`
	AuthenticationType        string                 `json:"authenticationType,omitempty"`
	X509Thumbprint            *X509Thumbprint        `json:"x509Thumbprint,omitempty"`
	Version                   int                    `json:"version,omitempty"`
	Tags                      map[string]interface{} `json:"tags,omitempty"`
	Properties                *Properties            `json:"properties,omitempty"`
	Capabilities              map[string]interface{} `json:"capabilities,omitempty"`
}

type X509Thumbprint

type X509Thumbprint struct {
	PrimaryThumbprint   string `json:"primaryThumbprint,omitempty"`
	SecondaryThumbprint string `json:"secondaryThumbprint,omitempty"`
}

Jump to

Keyboard shortcuts

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