Documentation ¶
Overview ¶
Package service implements a default service that can be used to quickly implement a connector. Together with connector.ConnectorHandler it implements the whole connector protocol. Developers can therefore focus on implementing technology specific details by implementing the Provider interface. It will listen to the provider.UpdateChannel() and update thing properties and action requests.
Index ¶
- Variables
- type ConnectorServiceOptions
- type DefaultConnectorService
- func (s *DefaultConnectorService) AddInstallation(ctx context.Context, request connector.InstallationRequest) (*connector.InstallationResponse, error)
- func (s *DefaultConnectorService) AddInstance(ctx context.Context, request connector.InstantiationRequest) (*connector.InstantiationResponse, error)
- func (s *DefaultConnectorService) CreateThing(ctx context.Context, instanceId string, thing connctd.Thing, externalId string) (*connctd.Thing, error)
- func (s *DefaultConnectorService) EventHandler(ctx context.Context)
- func (s *DefaultConnectorService) PerformAction(ctx context.Context, actionRequest connector.ActionRequest) (*connector.ActionResponse, error)
- func (s *DefaultConnectorService) RemoveInstallation(ctx context.Context, installationId string) error
- func (s *DefaultConnectorService) RemoveInstance(ctx context.Context, instanceId string) error
- func (s *DefaultConnectorService) UpdateActionStatus(ctx context.Context, instanceId string, actionRequestId string, ...) error
- func (s *DefaultConnectorService) UpdateProperty(ctx context.Context, ...) error
Constants ¶
This section is empty.
Variables ¶
var DefaultConnectorServiceOptions = ConnectorServiceOptions{ AsyncInstanceCreation: false, EnforceThingCreation: true, }
Functions ¶
This section is empty.
Types ¶
type ConnectorServiceOptions ¶ added in v0.4.4
type ConnectorServiceOptions struct { // if true connector will immediately respond to instance creation requests and asynchronously // creates thing descriptions. Useful if there is a high chance that an instance needs to create // multiple things AsyncInstanceCreation bool // if true instance creation will fail if at least one thing can not be created. You cannot // enforce thing creation if asyncInstanceCreation is enabled EnforceThingCreation bool }
type DefaultConnectorService ¶
type DefaultConnectorService struct {
// contains filtered or unexported fields
}
ConnectorService provides the callback functions used by the HTTP handler.
func NewConnectorService ¶
func NewConnectorService(dbClient connector.Database, connctdClient connector.Client, provider connector.Provider, thingTemplates connector.ThingTemplates, options ConnectorServiceOptions, logger logr.Logger) (*DefaultConnectorService, error)
NewConnectorService returns a new instance of the default connector.
func (*DefaultConnectorService) AddInstallation ¶
func (s *DefaultConnectorService) AddInstallation(ctx context.Context, request connector.InstallationRequest) (*connector.InstallationResponse, error)
AddInstallation is called by the HTTP handler when it receives an installation request. It will persist the new installation and its configuration and register the new installation with the provider.
func (*DefaultConnectorService) AddInstance ¶
func (s *DefaultConnectorService) AddInstance(ctx context.Context, request connector.InstantiationRequest) (*connector.InstantiationResponse, error)
AddInstantiation is called by the HTTP handler when it receives an instantiation request. It will persist the new instance, create new things for the instance and register the new instance with the provider.
func (*DefaultConnectorService) CreateThing ¶
func (s *DefaultConnectorService) CreateThing(ctx context.Context, instanceId string, thing connctd.Thing, externalId string) (*connctd.Thing, error)
CreateThing can be called by the connector to register a new thing for the given instance. It retrieves the instance token from the database and uses the token to create a new thing via the connctd API client. The new thing ID is then stored in the database referencing the instance id.
func (*DefaultConnectorService) EventHandler ¶
func (s *DefaultConnectorService) EventHandler(ctx context.Context)
EventHandler handles events coming from the provider.
func (*DefaultConnectorService) PerformAction ¶
func (s *DefaultConnectorService) PerformAction(ctx context.Context, actionRequest connector.ActionRequest) (*connector.ActionResponse, error)
PerformAction is called by the HTTP handler when it receives an action request.
func (*DefaultConnectorService) RemoveInstallation ¶
func (s *DefaultConnectorService) RemoveInstallation(ctx context.Context, installationId string) error
RemoveInstallation is called by the HTTP handler when it receives an installation removal request. It will remove the installation from the database (including the installation token) and from the provider. Note that we will not be able to communicate with the connctd platform about the removed installation after this, since the token is deleted.
func (*DefaultConnectorService) RemoveInstance ¶
func (s *DefaultConnectorService) RemoveInstance(ctx context.Context, instanceId string) error
RemoveInstance is called by the HTTP handler when it receives an instance removal request. It will remove the instance from the database (including the instance token) and from the provider. Note that we will not be able to communicate with the connctd platform about the removed instance after this, since the token is deleted.
func (*DefaultConnectorService) UpdateActionStatus ¶
func (s *DefaultConnectorService) UpdateActionStatus(ctx context.Context, instanceId string, actionRequestId string, actionResponse *connector.ActionResponse) error
UpdateActionStatus can be called by the connector to update the status of an action request.
func (*DefaultConnectorService) UpdateProperty ¶
func (s *DefaultConnectorService) UpdateProperty(ctx context.Context, instanceId, thingId, componentId, propertyId, value string) error
UpdateProperty can be called by the connector to update a component property of a thing belonging to an instance.