service

package
v0.0.0-...-0001d10 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindHandler

func BindHandler(services Services, binder rpc.HandlerBinder)

BindHandler binds the service handler to the provided HandlerBinder

Types

type AsyncResponse

type AsyncResponse struct {
	// ID to identify an asynchronous response. It uniquely identifies the
	// event and orders it in the sequence of events expected by the user
	ID uint64 `json:"id"`
}

AsyncResponse is the response returned by APIs that are asynchronous that return an ID that can be used by the user to receive and identify a response to the request when it is ready

type Client

type Client interface {
	// DeployServiceAsync triggers a deploy service operation and returns an ID with which
	// the response can be later retrieved with a PollService request
	DeployServiceAsync(context.Context, backend.DeployServiceRequest) (uint64, errors.Err)

	// ExecuteServiceAsync triggers an execute service operation and returns an ID with which
	// the response can be later retrieved with a PollService request
	ExecuteServiceAsync(context.Context, backend.ExecuteServiceRequest) (uint64, errors.Err)

	// PollService allows the client to poll for asynchronous responses
	PollService(context.Context, backend.PollServiceRequest) (backend.Events, errors.Err)

	// GetCode retrieves the code associated with a service.
	GetCode(context.Context, backend.GetCodeRequest) (backend.GetCodeResponse, errors.Err)

	// GetExpiry retrieves the expiration timestamp associated with a service.
	GetExpiry(context.Context, backend.GetExpiryRequest) (backend.GetExpiryResponse, errors.Err)

	// GetPublicKey retrieves the public key associated with a service
	// so that the client can encrypt and format the input data in a confidential
	// and privacy preserving manner.
	GetPublicKey(context.Context, backend.GetPublicKeyRequest) (backend.GetPublicKeyResponse, errors.Err)
}

Client interface for the underlying operations needed for the API implementation

type DeployServiceEvent

type DeployServiceEvent struct {
	// ID to identify an asynchronous response. It uniquely identifies the
	// event and orders it in the sequence of events expected by the user
	ID uint64 `json:"id"`

	// Address is the unique address that identifies the service,
	// is generated when a service is deployed and it can be used
	// for service execution
	Address string `json:"address"`
}

DeployServiceEvent is the event that can be polled by the user as a result to a ServiceExecutionRequest

func (DeployServiceEvent) EventID

func (e DeployServiceEvent) EventID() uint64

EventID is the implementation of rpc.Event for DeployServiceEvent

type DeployServiceRequest

type DeployServiceRequest struct {
	// Data is a blob of data that the user wants to pass as argument for
	// the deployment of a service
	Data string `json:"data"`
}

DeployServiceRequest is issued by the user to trigger a service execution. A client is always subscribed to a subscription with topic "service" from which the client can retrieve the asynchronous results to this request

func (DeployServiceRequest) Type

Type implementation of Request for DeployServiceRequest

type DeployServiceResponse

type DeployServiceResponse AsyncResponse

DeployServiceResponse is an asynchronous response that will be obtained using the polling mechanism

type ErrorEvent

type ErrorEvent struct {
	// ID to identify an asynchronous response. It uniquely identifies the
	// event and orders it in the sequence of events expected by the user
	ID uint64 `json:"id"`

	// Cause is the error that caused the event to failed
	Cause rpc.Error `json:"cause"`
}

ErrorEvent is the event that can be polled by the user as a result to a request that failed

func (ErrorEvent) EventID

func (e ErrorEvent) EventID() uint64

EventID is the implementation of rpc.Event for ErrorEvent

type Event

type Event interface {
	// EventID is the ID that uniquely identifies the event and it is found
	// inside a sequence of events
	EventID() uint64
}

Event is an interface for types that can be fetched by polling on a service

type ExecuteServiceEvent

type ExecuteServiceEvent struct {
	// ID to identify an asynchronous response. It uniquely identifies the
	// event and orders it in the sequence of events expected by the user
	ID uint64 `json:"id"`

	// Address is the unique address that identifies the service,
	// is generated when a service is deployed and it can be used
	// for service execution
	Address string `json:"address"`

	// Output generated by the service at the end of its execution
	Output string `json:"output"`
}

ExecuteServiceEvent is the event that can be polled by the user as a result to a ServiceExecutionRequest

func (ExecuteServiceEvent) EventID

func (e ExecuteServiceEvent) EventID() uint64

EventID is the implementation of rpc.Event for ExecuteServiceEvent

type ExecuteServiceRequest

type ExecuteServiceRequest struct {
	// Data is a blob of data that the user wants to pass to the service
	// as argument
	Data string `json:"data"`

	// Address where the service can be found
	Address string `json:"address"`
}

ExecuteServiceRequest is is used by the user to trigger a service execution. A client is always subscribed to a subscription with topic "service" from which the client can retrieve the asynchronous results to this request

func (ExecuteServiceRequest) Type

Type implementation of Request for ExecuteServiceRequest

type ExecuteServiceResponse

type ExecuteServiceResponse AsyncResponse

ExecuteServiceResponse is an asynchronous response that will be obtained using the polling mechanisms

type GetCodeRequest

type GetCodeRequest struct {
	// Address is the unique address that identifies the service,
	// is generated when a service is deployed and it can be used
	// for service execution
	Address string `json:"address"`
}

GetCodeRequest is a request to retrieve the code associated with a specific service

func (GetCodeRequest) Type

func (r GetCodeRequest) Type() RequestType

Type implementation of Request for GetCodeRequest

type GetCodeResponse

type GetCodeResponse struct {
	// Address is the unique address that identifies the service,
	// is generated when a service is deployed and it can be used
	// for service execution
	Address string `json:"address"`

	// Code associated with the service
	Code string `json:"code"`
}

GetCodeResponse is the response in which the code associated with the service is provided

type GetExpiryRequest

type GetExpiryRequest struct {
	// Address is the unique address that identifies the service,
	// is generated when a service is deployed and it can be used
	// for service execution
	Address string `json:"address"`
}

GetExpiryRequest is a request to retrieve the expiration timestamp associated with a specific service

func (GetExpiryRequest) Type

func (r GetExpiryRequest) Type() RequestType

Type implementation of Request for GetExpiryRequest

type GetExpiryResponse

type GetExpiryResponse struct {
	// Address is the unique address that identifies the service,
	// is generated when a service is deployed and it can be used
	// for service execution
	Address string `json:"address"`

	// Expiration timestamp associated with the service
	Expiry uint64 `json:"expiry"`
}

GetExpiryResponse is the response in which the expiration timestamp associated with the service is provided

type GetPublicKeyRequest

type GetPublicKeyRequest struct {
	// Address is the unique address that identifies the service,
	// is generated when a service is deployed and it can be used
	// for service execution
	Address string `json:"address"`
}

GetPublicKeyRequest is a request to retrieve the public key associated with a specific service

func (GetPublicKeyRequest) Type

Type implementation of Request for GetPublicKeyRequest

type GetPublicKeyResponse

type GetPublicKeyResponse struct {
	// Timestamp at which the public key expired
	Timestamp uint64 `json:"timestamp"`
	// Address is the unique address that identifies the service,
	// is generated when a service is deployed and it can be used
	// for service execution
	Address string `json:"address"`

	// PublicKey associated with the service
	PublicKey string `json:"publicKey"`

	// Signature generated by the key manager for authentication of the
	// public key
	Signature string `json:"signature"`
}

GetPublicKeyResponse is the response in which the public key associated with the service is provided

type PollServiceRequest

type PollServiceRequest struct {
	// Offset at which events need to be provided. Events are all ordered
	// with sequence numbers and it is up to the client to specify which
	// events it wants to receive from an offset in the sequence
	Offset uint64 `json:"offset"`

	// Count for the number of items the client would prefer to receive
	// at most from a single response
	Count uint `json:"count"`

	// DiscardPrevious allows the client to define whether the server should
	// discard all the events that have a sequence number lower than the offer
	DiscardPrevious bool `json:"discardPrevious"`
}

PollServiceRequest is a request that allows the user to poll for events either from asynchronous responses

func (PollServiceRequest) Type

Type implementation of Request for PollServiceRequest

type PollServiceResponse

type PollServiceResponse struct {
	// Offset is the base offset the requests were got from
	Offset uint64 `json:"offset"`

	// Events is the list of events that the server has starting from
	// the provided Offset
	Events []Event `json:"events"`
}

PollServiceResponse returns a list of asynchronous responses the client requested

type Request

type Request interface {
	// Type returns the type of the request
	Type() RequestType
}

Request is the type implemented by requests expected by the API handlers

type RequestType

type RequestType uint

RequestType defines the type of the request. May be useful for serialization and deserialization

const (
	Deploy       RequestType = 0
	Execute      RequestType = 1
	Poll         RequestType = 2
	GetCode      RequestType = 3
	GetExpiry    RequestType = 4
	GetPublicKey RequestType = 5
)

type ServiceHandler

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

ServiceHandler implements the handlers for service management

func NewServiceHandler

func NewServiceHandler(services Services) ServiceHandler

func (ServiceHandler) DeployService

func (h ServiceHandler) DeployService(ctx context.Context, v interface{}) (interface{}, error)

DeployService handles the deployment of new services

func (ServiceHandler) ExecuteService

func (h ServiceHandler) ExecuteService(ctx context.Context, v interface{}) (interface{}, error)

ExecuteService handles the execution of deployed services

func (ServiceHandler) GetCode

func (h ServiceHandler) GetCode(ctx context.Context, v interface{}) (interface{}, error)

GetCode retrieves the source code associated with a service.

func (ServiceHandler) GetExpiry

func (h ServiceHandler) GetExpiry(ctx context.Context, v interface{}) (interface{}, error)

GetExpiry retrieves the expiration timestamp associated with a service.

func (ServiceHandler) GetPublicKey

func (h ServiceHandler) GetPublicKey(ctx context.Context, v interface{}) (interface{}, error)

GetPublicKey retrieves the public key associated with a service to allow the client to encrypt the data that serves as argument for a service deployment or service execution.

func (ServiceHandler) PollService

func (h ServiceHandler) PollService(ctx context.Context, v interface{}) (interface{}, error)

PollService polls the service response queue to retrieve available responses

type Services

type Services struct {
	Logger   log.Logger
	Client   Client
	Verifier auth.Auth
}

Services required by the ServiceHandler execution

Jump to

Keyboard shortcuts

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