service

package
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: Apache-2.0 Imports: 79 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	COAPStatusCodeKey = attribute.Key("coap.status_code")
	COAPMethodKey     = attribute.Key("coap.method")
	COAPPathKey       = attribute.Key("coap.path")
)

Functions

func CreateResourceContentToObserver added in v2.3.6

func CreateResourceContentToObserver(client *Client, resourceChanged *events.ResourceChanged, observe uint32, token coapMessage.Token) (*pool.Message, error)

func DefaultCodeToLevel added in v2.2.4

func DefaultCodeToLevel(code codes.Code, logger log.Logger) func(args ...interface{})

DefaultCodeToLevel is the default implementation of gRPC return codes and interceptor log level for server side.

func MakeGetConfigForClient

func MakeGetConfigForClient(tlsCfg *tls.Config) tls.Config

func NewExchangeCache

func NewExchangeCache() *exchangeCache

func NewRefreshCache

func NewRefreshCache() *refreshCache

func ParsePublishedResources

func ParsePublishedResources(data io.ReadSeeker, deviceID string) (wkRd, error)
func PublishResourceLinks(ctx context.Context, raClient raService.ResourceAggregateClient, links schema.ResourceLinks, deviceID string, ttl int32, connectionID string, sequence uint64) ([]*commands.Resource, error)

func ValidUntil

func ValidUntil(expiry time.Time) (validUntil int64, ok bool)

ValidUntil returns time until expiration. No expiration is denoted by expiry = 0 for which 0 is returned. When expired, ok is false.

func WantToLog added in v2.2.4

func WantToLog(code codes.Code, logger log.Logger) bool

Types

type APIsConfig

type APIsConfig struct {
	COAP COAPConfig `yaml:"coap" json:"coap"`
}

func (*APIsConfig) Validate

func (c *APIsConfig) Validate() error

type AuthorizationConfig

type AuthorizationConfig struct {
	DeviceIDClaim string            `yaml:"deviceIDClaim" json:"deviceIdClaim"`
	OwnerClaim    string            `yaml:"ownerClaim" json:"ownerClaim"`
	Providers     []ProvidersConfig `yaml:"providers" json:"providers"`
}

func (*AuthorizationConfig) Validate

func (c *AuthorizationConfig) Validate() error

type BlockwiseTransferConfig

type BlockwiseTransferConfig struct {
	Enabled bool   `yaml:"enabled" json:"enabled"`
	SZX     string `yaml:"blockSize" json:"blockSize"`
}

func (*BlockwiseTransferConfig) Validate

func (c *BlockwiseTransferConfig) Validate() error

type COAPConfig

type COAPConfig struct {
	Addr                   string                  `yaml:"address" json:"address"`
	ExternalAddress        string                  `yaml:"externalAddress" json:"externalAddress"`
	MaxMessageSize         uint32                  `yaml:"maxMessageSize" json:"maxMessageSize"`
	OwnerCacheExpiration   time.Duration           `yaml:"ownerCacheExpiration" json:"ownerCacheExpiration"`
	SubscriptionBufferSize int                     `yaml:"subscriptionBufferSize" json:"subscriptionBufferSize"`
	MessagePoolSize        int                     `yaml:"messagePoolSize" json:"messagePoolSize"`
	KeepAlive              KeepAlive               `yaml:"keepAlive" json:"keepAlive"`
	BlockwiseTransfer      BlockwiseTransferConfig `yaml:"blockwiseTransfer" json:"blockwiseTransfer"`
	TLS                    TLSConfig               `yaml:"tls" json:"tls"`
	Authorization          AuthorizationConfig     `yaml:"authorization" json:"authorization"`
}

func (*COAPConfig) Validate

func (c *COAPConfig) Validate() error

type Client

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

Client a setup of connection

func (*Client) CleanUp

func (c *Client) CleanUp(resetAuthContext bool) *authorizationContext

func (*Client) Close

func (c *Client) Close()

Close closes coap connection

func (*Client) Context

func (c *Client) Context() context.Context

func (*Client) CreateResource

func (c *Client) CreateResource(ctx context.Context, event *events.ResourceCreatePending) error

func (*Client) Debugf added in v2.2.4

func (c *Client) Debugf(fmt string, args ...interface{})

func (*Client) DeleteResource

func (c *Client) DeleteResource(ctx context.Context, event *events.ResourceDeletePending) error

func (*Client) Do added in v2.2.4

func (c *Client) Do(req *pool.Message, correlationID string) (*pool.Message, error)

func (*Client) Errorf added in v2.2.4

func (c *Client) Errorf(fmt string, args ...interface{})

func (*Client) Get added in v2.2.4

func (c *Client) Get(ctx context.Context, path string, opts ...message.Option) (*pool.Message, error)

func (*Client) GetAuthorizationContext

func (c *Client) GetAuthorizationContext() (*authorizationContext, error)

func (*Client) GetContext

func (c *Client) GetContext() context.Context

func (*Client) GetDevicesMetadata added in v2.2.4

func (*Client) Infof added in v2.2.4

func (c *Client) Infof(fmt string, args ...interface{})

func (*Client) Observe added in v2.2.4

func (c *Client) Observe(ctx context.Context, path string, observeFunc func(req *pool.Message), opts ...message.Option) (*tcp.Observation, error)

func (*Client) OnClose

func (c *Client) OnClose()

OnClose is invoked when the coap connection was closed.

func (*Client) OnDeviceSubscriberReconnectError

func (c *Client) OnDeviceSubscriberReconnectError(err error)

func (*Client) ReleaseMessage added in v2.2.4

func (c *Client) ReleaseMessage(m *pool.Message)

func (*Client) RemoteAddr added in v2.4.1

func (c *Client) RemoteAddr() net.Addr

func (*Client) ResolveDeviceID

func (c *Client) ResolveDeviceID(claim pkgJwt.Claims, paramDeviceID string) string

func (*Client) RetrieveResource

func (c *Client) RetrieveResource(ctx context.Context, event *events.ResourceRetrievePending) error

func (*Client) SetAuthorizationContext

func (c *Client) SetAuthorizationContext(authCtx *authorizationContext) (oldDeviceID *authorizationContext)

func (*Client) UpdateDeviceMetadata

func (c *Client) UpdateDeviceMetadata(ctx context.Context, event *events.DeviceMetadataUpdatePending) error

func (*Client) UpdateResource

func (c *Client) UpdateResource(ctx context.Context, event *events.ResourceUpdatePending) error

func (*Client) ValidateToken

func (c *Client) ValidateToken(ctx context.Context, token string) (pkgJwt.Claims, error)

func (*Client) WriteMessage added in v2.3.6

func (c *Client) WriteMessage(msg *pool.Message)

type ClientsConfig

type ClientsConfig struct {
	Eventbus               EventBusConfig          `yaml:"eventBus" json:"eventBus"`
	IdentityStore          IdentityStoreConfig     `yaml:"identityStore" json:"identityStore"`
	ResourceAggregate      ResourceAggregateConfig `yaml:"resourceAggregate" json:"resourceAggregate"`
	ResourceDirectory      GrpcServerConfig        `yaml:"resourceDirectory" json:"resourceDirectory"`
	OpenTelemetryCollector otelClient.Config       `yaml:"openTelemetryCollector" json:"openTelemetryCollector"`
}

func (*ClientsConfig) Validate

func (c *ClientsConfig) Validate() error

type CoapRefreshTokenReq

type CoapRefreshTokenReq struct {
	DeviceID     string `json:"di"`
	UserID       string `json:"uid"`
	RefreshToken string `json:"refreshtoken"`
}

type CoapRefreshTokenResp

type CoapRefreshTokenResp struct {
	ExpiresIn    int64  `json:"expiresin"`
	AccessToken  string `json:"accesstoken"`
	RefreshToken string `json:"refreshtoken"`
}

type CoapSignInReq

type CoapSignInReq struct {
	DeviceID    string `json:"di"`
	UserID      string `json:"uid"`
	AccessToken string `json:"accesstoken"`
	Login       bool   `json:"login"`
}

type CoapSignInResp

type CoapSignInResp struct {
	ExpiresIn int64 `json:"expiresin"`
}

type CoapSignUpRequest

type CoapSignUpRequest struct {
	DeviceID                string `json:"di"`
	AuthorizationCode       string `json:"accesstoken"`
	AuthorizationCodeLegacy string `json:"authcode"`
	AuthorizationProvider   string `json:"authprovider"`
}

type CoapSignUpResponse

type CoapSignUpResponse struct {
	AccessToken  string `json:"accesstoken"`
	UserID       string `json:"uid"`
	RefreshToken string `json:"refreshtoken"`
	ExpiresIn    int64  `json:"expiresin"`
	RedirectURI  string `json:"redirecturi"`
}

type Config

type Config struct {
	Log       LogConfig     `yaml:"log" json:"log"`
	APIs      APIsConfig    `yaml:"apis" json:"apis"`
	Clients   ClientsConfig `yaml:"clients" json:"clients"`
	TaskQueue queue.Config  `yaml:"taskQueue" json:"taskQueue"`
}

Config represent application configuration

func (Config) String

func (c Config) String() string

String return string representation of Config

func (*Config) Validate

func (c *Config) Validate() error

type DeviceStatusExpirationConfig

type DeviceStatusExpirationConfig struct {
	Enabled   bool          `yaml:"enabled" json:"enabled"`
	ExpiresIn time.Duration `yaml:"expiresIn" json:"expiresIn"`
}

func (*DeviceStatusExpirationConfig) Validate

func (c *DeviceStatusExpirationConfig) Validate() error

type EventBusConfig

type EventBusConfig struct {
	NATS natsClient.Config `yaml:"nats" json:"nats"`
}

func (*EventBusConfig) Validate

func (c *EventBusConfig) Validate() error

type GrpcServerConfig

type GrpcServerConfig struct {
	Connection client.Config `yaml:"grpc" json:"grpc"`
}

func (*GrpcServerConfig) Validate

func (c *GrpcServerConfig) Validate() error

type IdentityStoreConfig

type IdentityStoreConfig struct {
	Connection client.Config `yaml:"grpc" json:"grpc"`
}

func (*IdentityStoreConfig) Validate

func (c *IdentityStoreConfig) Validate() error

type Interceptor

type Interceptor = func(ctx context.Context, code codes.Code, path string) (context.Context, error)

type KeepAlive

type KeepAlive struct {
	Timeout time.Duration `yaml:"timeout" json:"timeout"`
}

func (*KeepAlive) Validate

func (c *KeepAlive) Validate() error

type LogConfig

type LogConfig struct {
	DumpBody   bool `yaml:"dumpBody" json:"dumpBody"`
	log.Config `yaml:",inline"`
}

Config represent application configuration

type ProvidersConfig

type ProvidersConfig struct {
	Name          string `yaml:"name" json:"name"`
	oauth2.Config `yaml:",inline"`
}

func (*ProvidersConfig) Validate

func (c *ProvidersConfig) Validate(firstAuthority string, providerNames map[string]bool) error

type ResourceAggregateConfig

type ResourceAggregateConfig struct {
	Connection             client.Config                `yaml:"grpc" json:"grpc"`
	DeviceStatusExpiration DeviceStatusExpirationConfig `yaml:"deviceStatusExpiration" json:"deviceStatusExpiration"`
}

func (*ResourceAggregateConfig) Validate

func (c *ResourceAggregateConfig) Validate() error

type Service

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

Service is a configuration of coap-gateway

func New

func New(ctx context.Context, config Config, logger log.Logger) (*Service, error)

New creates server.

func (*Service) Close

func (s *Service) Close() error

Close turns off the server.

func (*Service) Serve

func (s *Service) Serve() error

Serve starts a coapgateway on the configured address in *Service.

func (*Service) ValidateToken

func (s *Service) ValidateToken(ctx context.Context, token string) (pkgJwt.Claims, error)

func (*Service) VerifyDeviceID

func (s *Service) VerifyDeviceID(tlsDeviceID string, claim pkgJwt.Claims) error

type TLSConfig

type TLSConfig struct {
	Enabled                        bool                     `yaml:"enabled" json:"enabled"`
	DisconnectOnExpiredCertificate bool                     `yaml:"disconnectOnExpiredCertificate" json:"disconnectOnExpiredCertificate"`
	Embedded                       certManagerServer.Config `yaml:",inline" json:",inline"`
}

func (*TLSConfig) Validate

func (c *TLSConfig) Validate() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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