config

package
v0.0.0-...-626d6d5 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InstallationModeEnv = "INSTALLATION_MODE"
	InstallationModeCMC = "CHILD_MANAGED_CHILD"
	InstallationModePMC = "PARENT_MANAGED_CHILD"
	InstallationModeP   = "PARENT"
	InstallationModeS   = "STANDALONE"

	SecVerPrefix = "_v1_"
)

Variables

View Source
var (
	// AllowFlags defines processing the cli arguments
	// true by default
	// false on init of C-shared library libtransit
	AllowFlags = true
	// EnvPrefix defines name prefix for environment variables
	// with struct-path selector and value, for example:
	//    TCG_GWCONNECTIONS_0_PASSWORD=TOK_EN
	EnvPrefix = "TCG_"
	// ConfigEnv defines environment variable for config file path, overrides the ConfigName
	ConfigEnv = "TCG_CONFIG"
	// ConfigName defines default filename for look in work directory if ConfigEnv is empty
	ConfigName = "tcg_config.yaml"
	// SecKeyEnv defines environment variable for
	SecKeyEnv = "TCG_SECKEY"
)

Functions

func Decrypt

func Decrypt(message, secret []byte) ([]byte, error)

Decrypt decrypts small messages golang.org/x/crypto/nacl/secretbox

func Encrypt

func Encrypt(message, secret []byte) ([]byte, error)

Encrypt encrypts small messages golang.org/x/crypto/nacl/secretbox

func Hashsum

func Hashsum(args ...interface{}) ([]byte, error)

Hashsum calculates FNV non-cryptographic hash suitable for checking the equality

Types

type BuildInfo

type BuildInfo struct {
	Tag  string `json:"tag"`
	Time string `json:"time"`
}

BuildInfo describes the build properties

func GetBuildInfo

func GetBuildInfo() BuildInfo

GetBuildInfo returns the build properties

type Config

type Config struct {
	Connector     Connector     `envPrefix:"CONNECTOR_" yaml:"connector"`
	DSConnection  DSConnection  `envPrefix:"DSCONNECTION_" yaml:"dsConnection"`
	GWConnections GWConnections `envPrefix:"GWCONNECTIONS_" yaml:"gwConnections"`
}

Config defines TCG Agent configuration

func GetConfig

func GetConfig() *Config

GetConfig implements Singleton pattern

func (Config) ConfigPath

func (cfg Config) ConfigPath() string

ConfigPath returns config file path

func (Config) Hashsum

func (cfg Config) Hashsum() ([]byte, error)

Hashsum calculates FNV non-cryptographic hash suitable for checking the equality

func (Config) InitTracerProvider

func (cfg Config) InitTracerProvider() (*tracesdk.TracerProvider, error)

InitTracerProvider inits provider

func (*Config) IsConfiguringPMC

func (cfg *Config) IsConfiguringPMC() bool

IsConfiguringPMC checks configuration stage

func (*Config) LoadConnectorDTO

func (cfg *Config) LoadConnectorDTO(data []byte) (*ConnectorDTO, error)

LoadConnectorDTO loads ConnectorDTO into Config

type Connector

type Connector struct {
	transit.AgentIdentity `yaml:",inline"`

	BatchEvents   time.Duration `env:"BATCHEVENTS" yaml:"batchEvents"`
	BatchMetrics  time.Duration `env:"BATCHMETRICS" yaml:"batchMetrics"`
	BatchMaxBytes int           `env:"BATCHMAXBYTES" yaml:"batchMaxBytes"`

	// ControllerAddr accepts value for combined "host:port"
	// used as `http.Server{Addr}`
	ControllerAddr     string `env:"CONTROLLERADDR" yaml:"controllerAddr"`
	ControllerCertFile string `env:"CONTROLLERCERTFILE" yaml:"controllerCertFile"`
	ControllerKeyFile  string `env:"CONTROLLERKEYFILE" yaml:"controllerKeyFile"`
	// ControllerPin accepts value from environment
	// provides local access for debug
	ControllerPin string `env:"CONTROLLERPIN" yaml:"-"`
	// Custom HTTP configuration
	ControllerReadTimeout  time.Duration `env:"CONTROLLERREADTIMEOUT" yaml:"-"`
	ControllerWriteTimeout time.Duration `env:"CONTROLLERWRITETIMEOUT" yaml:"-"`
	ControllerStartTimeout time.Duration `env:"CONTROLLERSTARTTIMEOUT" yaml:"-"`
	ControllerStopTimeout  time.Duration `env:"CONTROLLERSTOPTIMEOUT" yaml:"-"`

	Enabled            bool   `env:"ENABLED" yaml:"enabled"`
	InstallationMode   string `env:"INSTALLATIONMODE" yaml:"installationMode,omitempty"`
	IsDynamicInventory bool   `env:"ISDYNAMICINVENTORY" yaml:"-"`
	// GWEncode defines using HTTPEncode in Groundwork client: child|force|off
	// enabled for child by default
	GWEncode string `env:"GWENCODE" yaml:"-"`

	// LogCondense accepts time duration for condensing similar records
	// if 0 turn off condensing
	LogCondense time.Duration `env:"LOGCONDENSE" yaml:"logCondense"`
	// LogFile accepts file path to log in addition to stdout
	LogFile        string `env:"LOGFILE" yaml:"logFile"`
	LogFileMaxSize int64  `env:"LOGFILEMAXSIZE" yaml:"logFileMaxSize"`
	// Log files are rotated count times before being removed.
	// If count is 0, old versions are removed rather than rotated.
	LogFileRotate int      `env:"LOGFILEROTATE" yaml:"logFileRotate"`
	LogLevel      LogLevel `env:"LOGLEVEL" yaml:"logLevel"`
	LogColors     bool     `env:"LOGCOLORS" yaml:"logColors"`
	LogTimeFormat string   `env:"LOGTIMEFORMAT" yaml:"logTimeFormat"`

	Nats `yaml:",inline"`

	TransportStartRndDelay int `env:"TRANSPORTSTARTRNDDELAY" yaml:"-"`

	ExportProm bool `env:"EXPORTPROM" yaml:"exportProm"`
}

Connector defines TCG Connector configuration see GetConfig() for defaults

type ConnectorDTO

type ConnectorDTO struct {
	AgentID       string        `json:"agentId"`
	AppName       string        `json:"appName"`
	AppType       string        `json:"appType"`
	TcgURL        string        `json:"tcgUrl"`
	LogLevel      LogLevel      `json:"logLevel"`
	Enabled       bool          `json:"enabled"`
	DSConnection  DSConnection  `json:"dalekservicesConnection"`
	GWConnections GWConnections `json:"groundworkConnections"`
}

ConnectorDTO defines TCG Connector configuration

type DSConnection

type DSConnection clients.DSConnection

DSConnection defines DalekServices Connection configuration

func (*DSConnection) AsClient

func (c *DSConnection) AsClient() clients.DSConnection

AsClient returns as clients type

type GWConnection

type GWConnection clients.GWConnection

GWConnection defines Groundwork Connection configuration

func (*GWConnection) AsClient

func (c *GWConnection) AsClient() clients.GWConnection

AsClient returns as clients type

func (GWConnection) MarshalYAML

func (c GWConnection) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler interface overrides the password field

func (*GWConnection) UnmarshalYAML

func (c *GWConnection) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface. overrides the password field

type GWConnections

type GWConnections []GWConnection

GWConnections defines a set of configurations

func (*GWConnections) UnmarshalYAML

func (cc *GWConnections) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface. Applies decode to items in collection for setting only fields present in yaml. Note (as for gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b):

if yaml defines an empty set this method is not called but target is truncated.

type LogLevel

type LogLevel int

LogLevel defines levels in logrus-style

const (
	Error LogLevel = iota
	Warn
	Info
	Debug
)

Enum levels

func (LogLevel) String

func (l LogLevel) String() string

type Nats

type Nats struct {
	// NatsAckWait is the time the NATS server will wait before resending a message
	// Should be greater then the GWClient request duration
	NatsAckWait time.Duration `env:"NATSACKWAIT" yaml:"-"`
	// designates the maximum number of outstanding acknowledgements
	// (messages that have been delivered but not acknowledged)
	// that NATS Streaming will allow for a given subscription.
	// When this limit is reached, NATS Streaming will suspend delivery of messages
	// to this subscription until the number of unacknowledged messages falls below the specified limit
	NatsMaxInflight int `env:"NATSMAXINFLIGHT" yaml:"-"`
	// NatsMaxPubAcksInflight accepts number of unacknowledged messages
	// that a publisher may have in-flight at any given time.
	// When this maximum is reached, further async publish calls will block
	// until the number of unacknowledged messages falls below the specified limit
	NatsMaxPubAcksInflight int   `env:"NATSMAXPUBACKSINFLIGHT" yaml:"-"`
	NatsMaxPayload         int32 `env:"NATSMAXPAYLOAD" yaml:"-"`
	// NatsMonitorPort enables monitoring on http port useful for debug
	// curl 'localhost:8222/streaming/channelsz?limit=0&offset=0&subs=1'
	// More info: https://docs.nats.io/nats-streaming-concepts/monitoring
	NatsMonitorPort int    `env:"NATSMONITORPORT" yaml:"-"`
	NatsStoreDir    string `env:"NATSSTOREDIR" yaml:"natsFilestoreDir"`
	// NatsStoreType accepts "FILE"|"MEMORY"
	NatsStoreType string `env:"NATSSTORETYPE" yaml:"natsStoreType"`
	// How long messages are kept
	NatsStoreMaxAge time.Duration `env:"NATSSTOREMAXAGE" yaml:"natsStoreMaxAge"`
	// How many bytes are allowed per-channel
	NatsStoreMaxBytes int64 `env:"NATSSTOREMAXBYTES" yaml:"natsStoreMaxBytes"`
	// How many messages are allowed per-channel
	NatsStoreMaxMsgs int64 `env:"NATSSTOREMAXMSGS" yaml:"natsStoreMaxMsgs"`
	// NatsServerConfigFile is used to override yaml values for
	// NATS server configuration (debug only).
	NatsServerConfigFile string `env:"NATSSERVERCONFIGFILE" yaml:"natsServerConfigFile"`
}

func (Nats) Hashsum

func (c Nats) Hashsum() ([]byte, error)

Hashsum calculates FNV non-cryptographic hash suitable for checking the equality

Jump to

Keyboard shortcuts

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