component

package
v2.10.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2019 License: MIT Imports: 50 Imported by: 0

Documentation

Overview

Package component contains code that is shared by all components (discovery, router, broker, networkserver, handler)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnInitialize

func OnInitialize(fun initFunc)

OnInitialize registers a function that is called when any Component is initialized

Types

type Component

type Component struct {
	Config      Config
	Pool        *pool.Pool
	Identity    *pb_discovery.Announcement
	Discovery   discoveryclient.Client
	Monitor     *monitorclient.MonitorClient
	Ctx         ttnlog.Interface
	Context     context.Context
	AccessToken string

	TokenKeyProvider tokenkey.Provider
	// contains filtered or unexported fields
}

Component contains the common attributes for all TTN components

func New

func New(ctx ttnlog.Interface, serviceName string, announcedAddress string) (*Component, error)

New creates a new Component

func (*Component) Announce

func (c *Component) Announce() error

Announce the component to TTN discovery

func (*Component) BuildJWT

func (c *Component) BuildJWT() (string, error)

BuildJWT builds a short-lived JSON Web Token for this component

func (*Component) Discover

func (c *Component) Discover(serviceName, id string) (*pb_discovery.Announcement, error)

Discover is used to discover another component

func (*Component) ExchangeAppKeyForToken

func (c *Component) ExchangeAppKeyForToken(appID, key string) (string, error)

ExchangeAppKeyForToken enables authentication with the App Access Key

func (*Component) GetContext

func (c *Component) GetContext(token string) context.Context

GetContext returns a context for outgoing RPC request. If token is "", this function will generate a short lived token from the component

func (*Component) GetStatus

func (c *Component) GetStatus() Status

GetStatus gets the health status of the component

func (*Component) InitAuth

func (c *Component) InitAuth() error

InitAuth initializes Auth functionality

func (*Component) RegisterHandled

func (c *Component) RegisterHandled(msg message)

RegisterHandled registers a handled message

func (*Component) RegisterHealthServer

func (c *Component) RegisterHealthServer(srv *grpc.Server)

RegisterHealthServer registers the component's health status to the gRPC server

func (*Component) RegisterReceived

func (c *Component) RegisterReceived(msg message)

RegisterReceived registers a received message

func (*Component) ServerOptions

func (c *Component) ServerOptions() []grpc.ServerOption

func (*Component) SetStatus

func (c *Component) SetStatus(s Status)

SetStatus sets the health status of the component

func (*Component) UpdateTokenKey

func (c *Component) UpdateTokenKey() error

UpdateTokenKey updates the OAuth Bearer token key

func (*Component) ValidateNetworkContext

func (c *Component) ValidateNetworkContext(ctx context.Context) (component *pb_discovery.Announcement, err error)

ValidateNetworkContext validates the context of a network request (router-broker, broker-handler, etc)

func (*Component) ValidateTTNAuthContext

func (c *Component) ValidateTTNAuthContext(ctx context.Context) (*claims.Claims, error)

ValidateTTNAuthContext gets a token from the context and validates it

type Config

type Config struct {
	AuthServers   map[string]string
	KeyDir        string
	UseTLS        bool
	MinTLSVersion string
}

Config is the configuration for this component

func ConfigFromViper

func ConfigFromViper() Config

ConfigFromViper imports configuration from Viper

type Interface

type Interface interface {
	RegisterRPC(s *grpc.Server)
	Init(c *Component) error
	Shutdown()
	ValidateNetworkContext(ctx context.Context) (*pb_discovery.Announcement, error)
	ValidateTTNAuthContext(ctx context.Context) (*claims.Claims, error)
}

type ManagementInterface

type ManagementInterface interface {
	RegisterManager(s *grpc.Server)
}

type Status

type Status int

Status indicates the health status of this component

const (
	// StatusHealthy indicates a healthy component
	StatusHealthy Status = iota
	// StatusUnhealthy indicates an unhealthy component
	StatusUnhealthy
)

Jump to

Keyboard shortcuts

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