common

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package common contains common types and functions used by the BindPlane CLI and Server

Index

Constants

View Source
const (
	// ProfilesFolderName is the name of the folder where individual configuration profiles are stored
	ProfilesFolderName = "profiles"
	// BindPlaneDirectoryName TODO(doc)
	BindPlaneDirectoryName = ".bindplane"
	// BoldDatabaseName is the name of the bbolt database file
	BoldDatabaseName = "storage"
	// DownloadsDirectoryName is the name of the directory where downloads are cached
	DownloadsDirectoryName = "downloads"
	// BindPlaneLogName returns the name of the BindPlane log file
	BindPlaneLogName = "bindplane.log"
	// DefaultProfileName is the name of the default profile
	DefaultProfileName = "default"
)
View Source
const (
	// StoreTypeMap uses an in-memory store
	StoreTypeMap = "map"
	// StoreTypeBbolt uses go.etcd.io/bbolt for storage
	StoreTypeBbolt = "bbolt"
)

Variables

This section is empty.

Functions

func DefaultBindPlaneHomePath

func DefaultBindPlaneHomePath() string

DefaultBindPlaneHomePath returns the default value of the bindplane home path

func NewFileLogger

func NewFileLogger(level zapcore.Level, path string) (*zap.Logger, error)

NewFileLogger takes a logging level and log file path and returns a zip.Logger

func NewLogger

func NewLogger(config Common, level zapcore.Level) (*zap.Logger, error)

NewLogger returns a new Logger for the specified config and level

func NewStdoutLogger

func NewStdoutLogger(level zapcore.Level) (*zap.Logger, error)

NewStdoutLogger returns a new Logger with the specified level, writing to stdout

Types

type Client

type Client struct {
	Common
}

Client TODO(doc)

type Command

type Command struct {
	// TODO(doc)
	Output string `mapstructure:"output" yaml:"output"`
}

Command TODO(doc)

type Common

type Common struct {
	// Env is one of
	Env Env `mapstructure:"env" yaml:"env,omitempty"`

	// Host is the Host to which the server will bind.
	Host string `mapstructure:"host" yaml:"host,omitempty"`

	// Port is the Port on which the server will serve.
	Port string `mapstructure:"port" yaml:"port,omitempty"`

	// ServerURL is the URL that clients should use to contact the server.
	ServerURL string `mapstructure:"serverURL" yaml:"serverURL,omitempty"`

	// Username the basic auth username used for communication between client and server.
	Username string `mapstructure:"username" yaml:"username,omitempty"`
	// The basic auth password used for communication between client and server.
	Password string `mapstructure:"password" yaml:"password,omitempty"`

	// TLSConfig is an optional TLS configuration for communication between client and server.
	TLSConfig `yaml:",inline" mapstructure:",squash"`

	// LogFilePath is the path of the bindplane log file, defaulting to $HOME/.bindplane/bindplane.log
	LogFilePath string `mapstructure:"logFilePath" yaml:"logFilePath,omitempty"`

	// LogOutput indicates where logs should be written, defaulting to "file"
	LogOutput LogOutput `mapstructure:"logOutput" yaml:"logOutput,omitempty"`

	// TraceType specifies the type of tracing to use. Valid values are "google" or "otlp".
	TraceType string `mapstructure:"traceType,omitempty" yaml:"traceType,omitempty"`

	// GoogleCloudTracing is used to send traces to Google Cloud when TraceType is set to "google".
	GoogleCloudTracing trace.GoogleCloudTracing `mapstructure:"googleTracing,omitempty" yaml:"googleTracing,omitempty"`

	// OpenTelemetryTracing is used to send traces to an Open Telemetry OTLP receiver when
	// TraceType is set to "otlp".
	OpenTelemetryTracing trace.OpenTelemetryTracing `mapstructure:"otlpTracing,omitempty" yaml:"otlpTracing,omitempty"`
	// contains filtered or unexported fields
}

Common TODO(doc)

func (*Common) BindPlaneEnv

func (c *Common) BindPlaneEnv() Env

BindPlaneEnv ensures that Env has a valid value and defaults to EnvProduction

func (*Common) BindPlaneHomePath

func (c *Common) BindPlaneHomePath() string

BindPlaneHomePath returns the path to the BindPlane home where files are stored by default

func (*Common) BindPlaneInsecureSkipVerify added in v1.7.0

func (c *Common) BindPlaneInsecureSkipVerify() bool

BindPlaneInsecureSkipVerify returns the value of InsecureSkipVerify from the TLSConfig

func (*Common) BindPlaneLogFilePath

func (c *Common) BindPlaneLogFilePath() string

BindPlaneLogFilePath returns the path to the log file for bindplane

func (*Common) BindPlaneURL

func (c *Common) BindPlaneURL() string

BindPlaneURL returns the configured server url. If one is not configured, a url derived from the configured host and port is used.

func (*Common) EnableTLS

func (c *Common) EnableTLS() bool

EnableTLS returns true if TLS is enabled

func (*Common) ServerScheme

func (c *Common) ServerScheme() string

ServerScheme returns http or https

func (*Common) WebsocketScheme

func (c *Common) WebsocketScheme() string

WebsocketScheme returns ws or wss

type Config

type Config struct {
	// Server TODO(doc)
	Server `mapstructure:"server" yaml:"server,omitempty"`
	// Client TODO(doc)
	Client `mapstructure:"client" yaml:"client,omitempty"`
	// Command TODO(doc)
	Command `mapstructure:"command" yaml:"command,omitempty"`
}

Config TODO(doc)

func InitConfig

func InitConfig(bindplaneHomePath string) *Config

InitConfig returns a Config struct with zero values, which will be assigned during Command's PersistentPreRun

func (*Config) Validate

func (c *Config) Validate() (errGroup error)

Validate checks the runtime configuration for issues and returns all errors, if any.

type Env

type Env string

Env is an enum indicating the environment in which BindPlane is running.

const (
	// EnvDevelopment should be used for development and uses debug logging and normal gin request logging to stdout.
	EnvDevelopment Env = "development"

	// EnvTest should be used for tests and uses debug logging with json gin request logging to the log file.
	EnvTest Env = "test"

	// EnvProduction the the default and should be used in production and uses info logging with json gin request logging to the log file.
	EnvProduction Env = "production"
)

type GoogleCloudDatastore

type GoogleCloudDatastore struct {
	ProjectID       string `mapstructure:"projectID,omitempty" yaml:"projectID,omitempty"`
	Endpoint        string `mapstructure:"endpoint,omitempty" yaml:"endpoint,omitempty"`
	CredentialsFile string `mapstructure:"credentialsFile,omitempty" yaml:"credentialsFile,omitempty"`
}

GoogleCloudDatastore contains the configuration for google cloud datastore

type GoogleCloudPubSub

type GoogleCloudPubSub struct {
	ProjectID       string `mapstructure:"projectID,omitempty" yaml:"projectID,omitempty"`
	Endpoint        string `mapstructure:"endpoint,omitempty" yaml:"endpoint,omitempty"`
	CredentialsFile string `mapstructure:"credentialsFile,omitempty" yaml:"credentialsFile,omitempty"`
	Topic           string `mapstructure:"topic,omitempty" yaml:"topic,omitempty"`

	// Subscription is the name of the subscription that this node should use. In production this will be generated but it
	// is useful to specify in development.
	Subscription string `mapstructure:"subscription,omitempty" yaml:"subscription,omitempty"`
}

GoogleCloudPubSub is configuration for a server's Pub/Sub subscriber and publisher

type LogOutput

type LogOutput string

LogOutput is an enum of possible values for the LogOutput configuration setting

const (
	// LogOutputFile will write logs to the file specified by LogFilePath
	LogOutputFile LogOutput = "file"

	// LogOutputStdout will write logs to stdout
	LogOutputStdout LogOutput = "stdout"
)

type Server

type Server struct {
	// StoreType indicates the type of store to use. "map", "bbolt", and "googlecloud" are currently supported.
	StoreType string `mapstructure:"storeType,omitempty" yaml:"storeType,omitempty"`

	// GoogleCloudDatastore contains configuration for contacting Google Could Datastore and is used if StoreType == "googlecloud"
	GoogleCloudDatastore *GoogleCloudDatastore `mapstructure:"datastore,omitempty" yaml:"datastore,omitempty"`

	// GoogleCloudPubSub contains configuration for contacting Google Could Pub/Sub and is used if StoreType == "googlecloud"
	GoogleCloudPubSub *GoogleCloudPubSub `yaml:"pubsub,omitempty" mapstructure:"pubsub,omitempty"`

	// StorageFilePath TODO(doc)
	StorageFilePath string `mapstructure:"storageFilePath,omitempty" yaml:"storageFilePath,omitempty"`

	// SecretKey is a shared secret between the server and the agent to ensure agents are authorized to communicate with the server.
	SecretKey string `mapstructure:"secretKey,omitempty" yaml:"secretKey,omitempty"`

	// RemoteURL is the URL that agents should use to contact the server
	RemoteURL string `mapstructure:"remoteURL,omitempty" yaml:"remoteURL,omitempty"`

	// Offline mode indicates if the server should be considered offline. An offline server will not attempt to contact
	// any other services. It will still allow agents to connect and serve api requests.
	Offline bool `mapstructure:"offline,omitempty" yaml:"offline,omitempty"`

	// SessionSecret is used to encode the user sessions cookies.  It should be a uuid.
	SessionsSecret string `mapstructure:"sessionsSecret,omitempty" yaml:"sessionsSecret,omitempty"`

	Common `yaml:",inline" mapstructure:",squash"`

	// SyncAgentVersionsInterval is the interval at which agent-versions will be synchronized with GitHub. Set to 0 to
	// turn off synchronization. Disabled if Offline is true.
	SyncAgentVersionsInterval time.Duration `mapstructure:"syncAgentVersionsInterval,omitempty" yaml:"syncAgentVersionsInterval,omitempty"`
}

Server TODO(doc)

func (*Server) BindAddress

func (c *Server) BindAddress() string

BindAddress is the address (host:port) to which the server will bind

func (*Server) BoltDatabasePath

func (c *Server) BoltDatabasePath() string

BoltDatabasePath returns the path to the bolt database file

func (*Server) WebsocketURL

func (c *Server) WebsocketURL() string

WebsocketURL is the URL that should be used for agents connecting to the server

type TLSConfig

type TLSConfig struct {
	// Certificate is the path to the x509 PEM encoded certificate file that will be used to
	// establish TLS connections.
	//
	// When operating in server mode, this certificate is presented to clients.
	// When operating in client mode with mTLS, this certificate is used for authentication
	// against the server.
	Certificate string `mapstructure:"tlsCert" yaml:"tlsCert,omitempty"`

	// PrivateKey is the matching x509 PEM encoded private key for the Certificate.
	PrivateKey string `mapstructure:"tlsKey" yaml:"tlsKey,omitempty"`

	// CertificateAuthority is one or more file paths to x509 PEM encoded certificate authority chains.
	// These certificate authorities are used for trusting incoming client mTLS connections.
	CertificateAuthority []string `mapstructure:"tlsCa" yaml:"tlsCa,omitempty"`

	// InsecureSkipVerify controls whether a client verifies the server's certificate chain and host name. If
	// InsecureSkipVerify is true, crypto/tls accepts any certificate presented by the server and any host name in that
	// certificate.
	//
	// It is also used to signal that clients, like the agent metrics pipeline, should connect to the server with
	// tls.insecure set to true.
	//
	// In this mode, TLS is susceptible to machine-in-the-middle attacks. This should be used only for testing only.
	InsecureSkipVerify bool `mapstructure:"tlsSkipVerify" yaml:"tlsSkipVerify,omitempty"`
}

TLSConfig contains configuration for connecting over TLS and mTLS.

Jump to

Keyboard shortcuts

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