config

package
v0.2.44 Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: AGPL-3.0 Imports: 36 Imported by: 15

Documentation

Overview

Package config defines the structures to configure a robot and its connected parts.

Index

Constants

View Source
const DefaultBindAddress = "localhost:8080"

DefaultBindAddress is the default address that will be listened on. This default may not be used in managed cases when no bind address is explicitly set. In those cases the server will bind to all interfaces.

View Source
const DefaultPackageVersionValue = "latest"

DefaultPackageVersionValue default value of the package version used when empty.

View Source
const DefaultSessionHeartbeatWindow = 2 * time.Second

DefaultSessionHeartbeatWindow is the default session heartbeat window to use when not specified. It can be set with network.sessions.heartbeat_window.

Variables

View Source
var (
	Version     = ""
	GitRevision = ""
)

RDK versioning variables which are replaced by LD flags.

Functions

func AssociatedResourceConfigFromProto added in v0.2.36

func AssociatedResourceConfigFromProto(proto *pb.ResourceLevelServiceConfig) (resource.AssociatedResourceConfig, error)

AssociatedResourceConfigFromProto creates AssociatedResourceConfig from the proto equivalent.

func AssociatedResourceConfigToProto added in v0.2.36

func AssociatedResourceConfigToProto(conf resource.AssociatedResourceConfig) (*pb.ResourceLevelServiceConfig, error)

AssociatedResourceConfigToProto converts AssociatedResourceConfig to the proto equivalent.

func AuthConfigToProto added in v0.0.6

func AuthConfigToProto(auth *AuthConfig) (*pb.AuthConfig, error)

AuthConfigToProto converts AuthConfig to the proto equivalent.

func CloudConfigToProto added in v0.0.6

func CloudConfigToProto(cloud *Cloud) (*pb.CloudConfig, error)

CloudConfigToProto converts Cloud to the proto equivalent.

func ComponentConfigFromProto added in v0.0.6

func ComponentConfigFromProto(protoConf *pb.ComponentConfig) (*resource.Config, error)

ComponentConfigFromProto creates Component from the proto equivalent.

func ComponentConfigToProto added in v0.0.6

func ComponentConfigToProto(conf *resource.Config) (*pb.ComponentConfig, error)

ComponentConfigToProto converts Component to the proto equivalent. Assumes config is valid except for partial names which will be completed.

func CreateNewGRPCClient added in v0.0.7

func CreateNewGRPCClient(ctx context.Context, cloudCfg *Cloud, logger golog.Logger) (rpc.ClientConn, error)

CreateNewGRPCClient creates a new grpc cloud configured to communicate with the robot service based on the cloud config given.

func FrameConfigFromProto added in v0.0.6

func FrameConfigFromProto(proto *pb.Frame) (*referenceframe.LinkConfig, error)

FrameConfigFromProto creates Frame from the proto equivalent.

func FrameConfigToProto added in v0.0.6

func FrameConfigToProto(frame referenceframe.LinkConfig) (*pb.Frame, error)

FrameConfigToProto converts Frame to the proto equivalent.

func ModuleConfigToProto added in v0.2.8

func ModuleConfigToProto(module *Module) (*pb.ModuleConfig, error)

ModuleConfigToProto converts Module to the proto equivalent.

func NetworkConfigToProto added in v0.0.6

func NetworkConfigToProto(network *NetworkConfig) (*pb.NetworkConfig, error)

NetworkConfigToProto converts NetworkConfig from the proto equivalent.

func PackageConfigToProto added in v0.2.14

func PackageConfigToProto(cfg *PackageConfig) (*pb.PackageConfig, error)

PackageConfigToProto converts a rdk package config to the proto version.

func ProcessConfigFromProto added in v0.0.6

func ProcessConfigFromProto(proto *pb.ProcessConfig) (*pexec.ProcessConfig, error)

ProcessConfigFromProto creates ProcessConfig from the proto equivalent.

func ProcessConfigToProto added in v0.0.6

func ProcessConfigToProto(process *pexec.ProcessConfig) (*pb.ProcessConfig, error)

ProcessConfigToProto converts ProcessConfig to proto equivalent.

func RemoteConfigToProto added in v0.0.6

func RemoteConfigToProto(remote *Remote) (*pb.RemoteConfig, error)

RemoteConfigToProto converts Remote to the proto equivalent.

func ServiceConfigFromProto added in v0.0.6

func ServiceConfigFromProto(protoConf *pb.ServiceConfig) (*resource.Config, error)

ServiceConfigFromProto creates Service from the proto equivalent shared with Components.

func ServiceConfigToProto added in v0.0.6

func ServiceConfigToProto(conf *resource.Config) (*pb.ServiceConfig, error)

ServiceConfigToProto converts Service to the proto equivalent. Assumes config is valid except for partial names which will be completed.

Types

type AuthConfig

type AuthConfig struct {
	Handlers           []AuthHandlerConfig `json:"handlers,omitempty"`
	TLSAuthEntities    []string            `json:"tls_auth_entities,omitempty"`
	ExternalAuthConfig *ExternalAuthConfig `json:"external_auth_config,omitempty"`
}

AuthConfig describes authentication and authorization settings for the web server.

func AuthConfigFromProto added in v0.0.6

func AuthConfigFromProto(proto *pb.AuthConfig) (*AuthConfig, error)

AuthConfigFromProto creates AuthConfig from the proto equivalent.

func (*AuthConfig) Validate

func (config *AuthConfig) Validate(path string) error

Validate ensures all parts of the config are valid.

type AuthHandlerConfig

type AuthHandlerConfig struct {
	Type   rpc.CredentialsType `json:"type"`
	Config rutils.AttributeMap `json:"config"`
}

AuthHandlerConfig describes the configuration for a particular auth handler.

func (*AuthHandlerConfig) Validate

func (config *AuthHandlerConfig) Validate(path string) error

Validate ensures all parts of the config are valid.

type Cloud

type Cloud struct {
	ID                string
	Secret            string
	LocationSecret    string // Deprecated: Use LocationSecrets
	LocationSecrets   []LocationSecret
	ManagedBy         string
	FQDN              string
	LocalFQDN         string
	SignalingAddress  string
	SignalingInsecure bool
	Path              string
	LogPath           string
	AppAddress        string
	RefreshInterval   time.Duration

	// cached by us and fetched from a non-config endpoint.
	TLSCertificate string
	TLSPrivateKey  string
}

A Cloud describes how to configure a robot controlled by the cloud. The cloud source could be anything that supports http. URL is constructed as $Path?id=ID and secret is put in a http header.

func CloudConfigFromProto added in v0.0.6

func CloudConfigFromProto(proto *pb.CloudConfig) (*Cloud, error)

CloudConfigFromProto creates Cloud from the proto equivalent.

func (Cloud) MarshalJSON added in v0.2.5

func (config Cloud) MarshalJSON() ([]byte, error)

MarshalJSON marshals out this config.

func (*Cloud) UnmarshalJSON added in v0.2.5

func (config *Cloud) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON data into this config.

func (*Cloud) Validate

func (config *Cloud) Validate(path string, fromCloud bool) error

Validate ensures all parts of the config are valid.

type Config

type Config struct {
	Cloud      *Cloud
	Modules    []Module
	Remotes    []Remote
	Components []resource.Config
	Processes  []pexec.ProcessConfig
	Services   []resource.Config
	Packages   []PackageConfig
	Network    NetworkConfig
	Auth       AuthConfig
	Debug      bool

	ConfigFilePath string

	// AllowInsecureCreds is used to have all connections allow insecure
	// downgrades and send credentials over plaintext. This is an option
	// a user must pass via command line arguments.
	AllowInsecureCreds bool

	// UntrustedEnv is used to disable Processes and shell for untrusted environments
	// where a process cannot be trusted. This is an option a user must pass via
	// command line arguments.
	UntrustedEnv bool

	// FromCommand indicates if this config was parsed via the web server command.
	// If false, it's for creating a robot via the RDK library. This is helpful for
	// error messages that can indicate flags/config fields to use.
	FromCommand bool

	// DisablePartialStart ensures that a robot will only start when all the components,
	// services, and remotes pass config validation. This value is false by default
	DisablePartialStart bool

	// PackagePath sets the directory used to store packages locally. Defaults to ~/.viam/packages
	PackagePath string
}

A Config describes the configuration of a robot.

func FromProto added in v0.1.0

func FromProto(proto *pb.RobotConfig, logger golog.Logger) (*Config, error)

FromProto converts the RobotConfig to the internal rdk equivalent.

func FromReader

func FromReader(
	ctx context.Context,
	originalPath string,
	r io.Reader,
	logger golog.Logger,
) (*Config, error)

FromReader reads a config from the given reader and specifies where, if applicable, the file the reader originated from.

func ProcessConfig

func ProcessConfig(in *Config, tlsCfg *TLSConfig) (*Config, error)

ProcessConfig processes robot configs.

func Read

func Read(
	ctx context.Context,
	filePath string,
	logger golog.Logger,
) (*Config, error)

Read reads a config from the given file.

func ReadLocalConfig added in v0.1.0

func ReadLocalConfig(
	ctx context.Context,
	filePath string,
	logger golog.Logger,
) (*Config, error)

ReadLocalConfig reads a config from the given file but does not fetch any config from the remote servers.

func (*Config) CopyOnlyPublicFields added in v0.0.6

func (c *Config) CopyOnlyPublicFields() (*Config, error)

CopyOnlyPublicFields returns a deep-copy of the current config only preserving JSON exported fields.

func (*Config) Ensure

func (c *Config) Ensure(fromCloud bool, logger golog.Logger) error

Ensure ensures all parts of the config are valid.

func (Config) FindComponent

func (c Config) FindComponent(name string) *resource.Config

FindComponent finds a particular component by name.

func (Config) MarshalJSON added in v0.2.36

func (c Config) MarshalJSON() ([]byte, error)

MarshalJSON marshals JSON from the config.

func (*Config) UnmarshalJSON added in v0.2.36

func (c *Config) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON into the config and adjusts some names if they are not fully filled in.

type Diff

type Diff struct {
	Left, Right    *Config
	Added          *Config
	Modified       *ModifiedConfigDiff
	Removed        *Config
	ResourcesEqual bool
	NetworkEqual   bool
	PrettyDiff     string
}

A Diff is the difference between two configs, left and right where left is usually old and right is new. So the diff is the changes from left to right.

func DiffConfigs

func DiffConfigs(left, right Config, revealSensitiveConfigDiffs bool) (_ *Diff, err error)

DiffConfigs returns the difference between the two given configs from left to right.

func (*Diff) String

func (diff *Diff) String() string

String returns a pretty version of the diff.

type ExternalAuthConfig added in v0.2.27

type ExternalAuthConfig struct {
	// contains the raw jwks json.
	JSONKeySet rutils.AttributeMap `json:"jwks"`

	// on validation the JSONKeySet is validated and parsed into this field and can be used.
	ValidatedKeySet jwks.KeySet `json:"-"`
}

ExternalAuthConfig contains information needed to verify externally authenticated tokens.

func (*ExternalAuthConfig) Validate added in v0.2.27

func (c *ExternalAuthConfig) Validate(path string) error

Validate returns true if the config is valid. Ensures each key is valid and meets the required constraints.

type LocationSecret added in v0.1.7

type LocationSecret struct {
	ID string `json:"id"`
	// Payload of the secret
	Secret string `json:"secret"`
}

LocationSecret describes a location secret that can be used to authenticate to the rdk.

type ModifiedConfigDiff

type ModifiedConfigDiff struct {
	Remotes    []Remote
	Components []resource.Config
	Processes  []pexec.ProcessConfig
	Services   []resource.Config
	Packages   []PackageConfig
	Modules    []Module
}

ModifiedConfigDiff is the modificative different between two configs.

type Module added in v0.2.8

type Module struct {
	// Name is an arbitrary name used to identify the module, and is used to name it's socket as well.
	Name string `json:"name"`
	// ExePath is the path (either absolute, or relative to the working directory) to the executable module file.
	ExePath string `json:"executable_path"`
}

Module represents an external resource module, with a path to the binary module file.

func ModuleConfigFromProto added in v0.2.8

func ModuleConfigFromProto(proto *pb.ModuleConfig) (*Module, error)

ModuleConfigFromProto creates Module from the proto equivalent.

func (*Module) Validate added in v0.2.8

func (m *Module) Validate(path string) error

Validate checks if the config is valid.

type NetworkConfig

type NetworkConfig struct {
	NetworkConfigData
}

NetworkConfig describes networking settings for the web server.

func NetworkConfigFromProto added in v0.0.6

func NetworkConfigFromProto(proto *pb.NetworkConfig) (*NetworkConfig, error)

NetworkConfigFromProto creates NetworkConfig from the proto equivalent.

func (NetworkConfig) MarshalJSON

func (nc NetworkConfig) MarshalJSON() ([]byte, error)

MarshalJSON marshals out this config.

func (*NetworkConfig) Validate

func (nc *NetworkConfig) Validate(path string) error

Validate ensures all parts of the config are valid.

type NetworkConfigData

type NetworkConfigData struct {
	// FQDN is the unique name of this server.
	FQDN string `json:"fqdn,omitempty"`

	// Listener is the listener that the web server will use. This is mutually
	// exclusive with BindAddress.
	Listener net.Listener `json:"-"`

	// BindAddress is the address that the web server will bind to.
	// The default behavior is to bind to localhost:8080. This is mutually
	// exclusive with Listener.
	BindAddress string `json:"bind_address,omitempty"`

	BindAddressDefaultSet bool `json:"-"`

	// TLSCertFile is used to enable secure communications on the hosted HTTP server.
	// This is mutually exclusive with TLSCertPEM and TLSKeyPEM.
	TLSCertFile string `json:"tls_cert_file,omitempty"`

	// TLSKeyFile is used to enable secure communications on the hosted HTTP server.
	// This is mutually exclusive with TLSCertPEM and TLSKeyPEM.
	TLSKeyFile string `json:"tls_key_file,omitempty"`

	// TLSConfig is used to enable secure communications on the hosted HTTP server.
	// This is mutually exclusive with TLSCertFile and TLSKeyFile.
	TLSConfig *tls.Config `json:"-"`

	// Sessions configures session management.
	Sessions SessionsConfig `json:"sessions"`
}

NetworkConfigData is the network config data that gets marshaled/unmarshaled.

type PackageConfig added in v0.2.14

type PackageConfig struct {
	// Name is the local name of the package on the RDK. Must be unique across Packages. Must not be empty.
	Name string `json:"name"`
	// Package is the unqiue package name hosted by a remote PackageService. Must not be empty.
	Package string `json:"package"`
	// Version of the package ID hosted by a remote PackageService. If not specified "latest" is assumed.
	Version string `json:"version,omitempty"`
}

A PackageConfig describes the configuration of a Package.

func PackageConfigFromProto added in v0.2.14

func PackageConfigFromProto(proto *pb.PackageConfig) (*PackageConfig, error)

PackageConfigFromProto converts a proto package config to the rdk version.

func (*PackageConfig) Validate added in v0.2.14

func (p *PackageConfig) Validate(path string) error

Validate package config is valid.

type PackageReference added in v0.2.15

type PackageReference struct {
	Package       string
	PathInPackage string
}

PackageReference contains the deconstructed parts of a package reference in the config. Eg: ${packages.some-package}/path/a/b/c -> {"some-package", "/path/a/b/c"}.

func GetPackageReference added in v0.2.15

func GetPackageReference(path string) *PackageReference

GetPackageReference a PackageReference if the given path has a Package reference eg. ${packages.some-package}/path. Returns nil if no package reference is found.

type Remote

type Remote struct {
	Name                      string
	Address                   string
	Frame                     *referenceframe.LinkConfig
	Auth                      RemoteAuth
	ManagedBy                 string
	Insecure                  bool
	ConnectionCheckInterval   time.Duration
	ReconnectInterval         time.Duration
	AssociatedResourceConfigs []resource.AssociatedResourceConfig

	// Secret is a helper for a robot location secret.
	Secret string
	// contains filtered or unexported fields
}

A Remote describes a remote robot that should be integrated. The Frame field defines how the "world" node of the remote robot should be reconciled with the "world" node of the current robot. All components of the remote robot who have Parent as "world" will be attached to the parent defined in Frame, and with the given offset as well.

func RemoteConfigFromProto added in v0.0.6

func RemoteConfigFromProto(proto *pb.RemoteConfig) (*Remote, error)

RemoteConfigFromProto creates Remote from the proto equivalent.

func (Remote) Equals added in v0.2.36

func (conf Remote) Equals(other Remote) bool

Equals checks if the two configs are deeply equal to each other.

func (Remote) MarshalJSON added in v0.2.5

func (conf Remote) MarshalJSON() ([]byte, error)

MarshalJSON marshals out this config.

func (*Remote) UnmarshalJSON added in v0.2.5

func (conf *Remote) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON data into this config.

func (*Remote) Validate

func (conf *Remote) Validate(path string) ([]string, error)

Validate ensures all parts of the config are valid.

type RemoteAuth

type RemoteAuth struct {
	Credentials *rpc.Credentials `json:"credentials"`
	Entity      string           `json:"entity"`

	// only used internally right now
	ExternalAuthAddress    string           `json:"-"`
	ExternalAuthInsecure   bool             `json:"-"`
	ExternalAuthToEntity   string           `json:"-"`
	Managed                bool             `json:"-"`
	SignalingServerAddress string           `json:"-"`
	SignalingAuthEntity    string           `json:"-"`
	SignalingCreds         *rpc.Credentials `json:"-"`
}

RemoteAuth specifies how to authenticate against a remote. If no credentials are specified, authentication does not happen. If an entity is specified, the authentication request will specify it.

type SessionsConfig added in v0.2.5

type SessionsConfig struct {
	// HeartbeatWindow is the window within which clients must send at least one
	// heartbeat in order to keep a session alive.
	HeartbeatWindow time.Duration
}

SessionsConfig configures various parameters used in session management.

func (SessionsConfig) MarshalJSON added in v0.2.5

func (sc SessionsConfig) MarshalJSON() ([]byte, error)

MarshalJSON marshals out this config.

func (*SessionsConfig) UnmarshalJSON added in v0.2.5

func (sc *SessionsConfig) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON data into this config.

func (*SessionsConfig) Validate added in v0.2.5

func (sc *SessionsConfig) Validate(path string) error

Validate ensures all parts of the config are valid.

type TLSConfig

type TLSConfig struct {
	*tls.Config
	// contains filtered or unexported fields
}

TLSConfig stores the TLS config for the robot.

func NewTLSConfig

func NewTLSConfig(cfg *Config) *TLSConfig

NewTLSConfig creates a new tls config.

func (*TLSConfig) UpdateCert

func (t *TLSConfig) UpdateCert(cfg *Config) error

UpdateCert updates the TLS certificate to be returned.

type Watcher

type Watcher interface {
	Config() <-chan *Config
	Close() error
}

A Watcher is responsible for watching for changes to a config from some source and delivering those changes to some destination.

func NewWatcher

func NewWatcher(ctx context.Context, config *Config, logger golog.Logger) (Watcher, error)

NewWatcher returns an optimally selected Watcher based on the given config.

Directories

Path Synopsis
Package testutils helpers for testing the config retrievial.
Package testutils helpers for testing the config retrievial.

Jump to

Keyboard shortcuts

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