config

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package config includes definitions for the Emissary configuration file, along with adapters for reading/writing from the filesystem or a mongodb database.

Index

Constants

View Source
const ConfigSourceCommandLine = "COMMAND"

ConfigSourceCommandLine represents that the config file location was specified via the "--config" command line argument

View Source
const ConfigSourceDefault = "DEFAULT"

ConfigSourceDefault represents that the config file location was not specified, so the default value of "file://./config.json" was used

View Source
const ConfigSourceEnvironment = "ENVIRONMENT"

ConfigSourceEnvironment represents that the config file location was specified via the "EMISSARY_CONFIG" environment variable

View Source
const FolderAdapterEmbed = "EMBED"
View Source
const FolderAdapterFile = "FILE"
View Source
const FolderAdapterGit = "GIT"
View Source
const FolderAdapterS3 = "S3"
View Source
const StorageTypeFile = "FILE"

StorageTypeFile represents a configuration database stored in a JSON file

View Source
const StorageTypeMongo = "MONGODB"

StorageTypeMongo represents a configuration database stored in a MongoDB database

Variables

This section is empty.

Functions

func DatabaseConnectInfo added in v0.6.0

func DatabaseConnectInfo() schema.Element

func DomainSchema

func DomainSchema() schema.Element

func OwnerSchema

func OwnerSchema() schema.Element

func ProviderSchema

func ProviderSchema() schema.Element

ProviderSchema returns a schema that validates the Provider object

func ReadableFolderSchema

func ReadableFolderSchema() schema.Element

func SMTPConnectionSchema

func SMTPConnectionSchema() schema.Element

func Schema

func Schema() schema.Schema

Schema returns the data schema for the configuration file.

func WritableFolderSchema

func WritableFolderSchema() schema.Element

Types

type CommandLineArgs

type CommandLineArgs struct {
	Source   string // Type of configuration file (Command Line | Enviornment Variable | Default)
	Protocol string // Protocol to use when loading the configuration (MONGODB | FILE)
	Location string // URI of the configuration file
	Setup    bool   // If TRUE, then the server will run in SETUP mode
	HTTPPort int    // Port to use in setup mode (only)
}

CommandLineArgs represents the command line arguments passed to the server

func GetCommandLineArgs

func GetCommandLineArgs() CommandLineArgs

GetCommandLineArgs returns the location of the configuration file

func (CommandLineArgs) ConfigOptions added in v0.6.0

func (args CommandLineArgs) ConfigOptions() []Option

ConfigOptions returns any config modifiers specified in the command line (like --port)

type Config

type Config struct {
	Domains             set.Slice[Domain]            `json:"domains"`             // Slice of one or more domain configurations
	Providers           set.Slice[Provider]          `json:"providers"`           // Slice of one or more OAuth client configurations
	Templates           sliceof.Object[mapof.String] `json:"templates"`           // Folders containing all stream templates
	Emails              sliceof.Object[mapof.String] `json:"emails"`              // Folders containing email templates
	AttachmentOriginals mapof.String                 `json:"attachmentOriginals"` // Folder where original attachments will be stored
	AttachmentCache     mapof.String                 `json:"attachmentCache"`     // Folder (possibly memory cache) where cached versions of attachmented files will be stored.
	Certificates        mapof.String                 `json:"certificates"`        // Folder containing the SSL certificate cache for Let's Encrypt AutoSSL
	ActivityPubCache    mapof.String                 `json:"activityPubCache"`    // Connection string for ActivityPub cache database
	AdminEmail          string                       `json:"adminEmail"`          // Email address of the administrator
	HTTPPort            int                          `json:"httpPort"`            // Port to listen on for HTTP requests
	HTTPSPort           int                          `json:"httpsPort"`           // Port to listen on for HTTPS requests
	DebugLevel          string                       `json:"debugLevel"`          // Amount of debugging information to log for the server, using zerolog levels (Trace, Debug, Info, Error, None)
	Source              string                       `json:"-"`                   // READONLY: Where did the initial config location come from?  (Command Line, Environment Variable, Default)
	Location            string                       `json:"-"`                   // READONLY: Location where this config file is read from/to.  Not a part of the configuration itself.
	MongoID             primitive.ObjectID           `json:"-" bson:"_id"`        // Used as unique key for MongoDB
}

Config defines all of the domains available on this server

func DefaultConfig

func DefaultConfig() Config

DefaultConfig return sthe default configuration for this application.

func NewConfig

func NewConfig() Config

NewConfig returns a fully initialized (but empty) Config data structure.

func (Config) AllProviders

func (config Config) AllProviders() []form.LookupCode

func (Config) DomainNames

func (config Config) DomainNames() []string

DomainNames returns an array of domains names in this configuration.

func (*Config) GetPointer added in v0.6.0

func (config *Config) GetPointer(name string) (any, bool)

func (Config) HTTPPortString added in v0.6.0

func (config Config) HTTPPortString() (string, bool)

HTTPPortString returns the HTTP port as a string (prefixed with a colon). This defaults to ":80" if no port is specified.

func (Config) HTTPSPortString added in v0.6.0

func (config Config) HTTPSPortString() (string, bool)

HTTPSPortString returns the HTTPS port as a string (prefixed with a colon). This defaults to ":443" if no port is specified.

func (Config) IsEmpty added in v0.6.0

func (config Config) IsEmpty() bool

IsEmpty returns TRUE if this configuration is not usable (no ports or domains)

func (Config) Schema

func (config Config) Schema() schema.Schema

func (*Config) With added in v0.6.0

func (config *Config) With(options ...Option)

With applies one or more options to this configuration

type Domain

type Domain struct {
	DomainID         string         `json:"domainId"         bson:"domainId"`         // Unique ID for this domain
	Label            string         `json:"label"            bson:"label"`            // Human-friendly label for administrators
	Hostname         string         `json:"hostname"         bson:"hostname"`         // Domain name of a virtual server
	ConnectString    string         `json:"connectString"    bson:"connectString"`    // MongoDB connect string
	DatabaseName     string         `json:"databaseName"     bson:"databaseName"`     // Name of the MongoDB Database (can be empty string to use default db for the connect string)
	SMTPConnection   SMTPConnection `json:"smtp"             bson:"smtp"`             // Information for connecting to an SMTP server to send email on behalf of the domain.
	Owner            Owner          `json:"owner"            bson:"owner"`            // Information about the owner of this domain
	KeyEncryptingKey string         `json:"keyEncryptingKey" bson:"keyEncryptingKey"` // Key used to encrypt/decrypt JWT keys stored in the database
}

Domain contains all of the configuration data required to operate a single domain.

func NewDomain

func NewDomain() Domain

NewDomain returns a fully initialized Domain object.

func (*Domain) GetPointer added in v0.6.0

func (domain *Domain) GetPointer(name string) (any, bool)

func (Domain) ID

func (domain Domain) ID() string

ID returns the domain ID.

type FileStorage

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

FileStorage is a file-based storage engine for the server configuration

func NewFileStorage

func NewFileStorage(args *CommandLineArgs) FileStorage

NewFileStorage creates a fully initialized FileStorage instance

func (FileStorage) Subscribe

func (storage FileStorage) Subscribe() <-chan Config

Subscribe returns a channel that will receive the configuration every time it is updated

func (FileStorage) Write

func (storage FileStorage) Write(config Config) error

Write writes the configuration to the filesystem

type MongoStorage

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

MongoStorage is a MongoDB-backed configuration storage

func NewMongoStorage

func NewMongoStorage(args *CommandLineArgs) MongoStorage

NewMongoStorage creates a fully initialized MongoStorage instance

func (MongoStorage) Subscribe

func (storage MongoStorage) Subscribe() <-chan Config

Subscribe returns a channel that will receive the configuration every time it is updated

func (MongoStorage) Write

func (storage MongoStorage) Write(config Config) error

Write writes the configuration to the database

type Option added in v0.6.0

type Option func(*Config)

func WithHTTPPort added in v0.6.0

func WithHTTPPort(port int) Option

WithHTTPPort overrides the HTTP port used by the server

type Owner

type Owner struct {
	DisplayName    string `json:"displayName"     bson:"displayName"`
	Username       string `json:"username"        bson:"username"`
	EmailAddress   string `json:"emailAddress"    bson:"emailAddress"`
	PhoneNumber    string `json:"phoneNumber"     bson:"phoneNumber"`
	MailingAddress string `json:"mailingAddress"  bson:"mailingAddress"`
}

func NewOwner

func NewOwner() Owner

func (Owner) GetStringOK

func (owner Owner) GetStringOK(name string) (string, bool)

func (*Owner) SetString

func (owner *Owner) SetString(name string, value string) bool

type Provider

type Provider struct {
	ProviderID   string `json:"providerId"   bson:"providerId"`   // Unique identifier for this provider
	ClientID     string `json:"clientId"     bson:"clientId"`     // Client ID for this provider
	ClientSecret string `json:"clientSecret" bson:"clientSecret"` // Client Secret for this provider
}

Provider represents a single external service provider (typically OAuth2)

func NewProvider

func NewProvider(providerID string) Provider

NewProvider returns a fully initialized Provider object

func (Provider) GetStringOK

func (provider Provider) GetStringOK(key string) (string, bool)

func (Provider) ID

func (provider Provider) ID() string

ID implements the set.Value interface

func (Provider) IsEmpty

func (provider Provider) IsEmpty() bool

IsEmpty returns TRUE if the provider is empty

func (*Provider) SetString

func (provider *Provider) SetString(key string, value string) bool

type SMTPConnection

type SMTPConnection struct {
	Hostname string `json:"hostname"` // Server name to connect to
	Username string `json:"username"` // Username for authentication
	Password string `json:"password"` // Password/secret for authentication
	Port     int    `json:"port"`     // Port to connect to
	TLS      bool   `json:"tls"`      // If TRUE, then use TLS to connect
}

func NewSMTPConnection

func NewSMTPConnection() SMTPConnection

func (SMTPConnection) GetBoolOK

func (smtp SMTPConnection) GetBoolOK(name string) (bool, bool)

func (SMTPConnection) GetIntOK

func (smtp SMTPConnection) GetIntOK(name string) (int, bool)

func (SMTPConnection) GetStringOK

func (smtp SMTPConnection) GetStringOK(name string) (string, bool)

func (SMTPConnection) Server

func (smtp SMTPConnection) Server() (*mail.SMTPServer, bool)

Server generates a fully initialized SMTP server object. This object may still be invalid, if the SMTPConnection is not populated with correct information.

func (*SMTPConnection) SetBool

func (smtp *SMTPConnection) SetBool(name string, value bool) bool

func (*SMTPConnection) SetInt

func (smtp *SMTPConnection) SetInt(name string, value int) bool

func (*SMTPConnection) SetString

func (smtp *SMTPConnection) SetString(name string, value string) bool

func (SMTPConnection) Validate

func (smtp SMTPConnection) Validate() error

Validate confirms that the SMTPConnection matches ths SMTPConnectionSchema

type Storage

type Storage interface {
	Subscribe() <-chan Config
	Write(Config) error
}

func Load

func Load(args *CommandLineArgs) Storage

Load retrieves a Storage object from the location designated in the config file

Jump to

Keyboard shortcuts

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