fileconfiguration

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 7 Imported by: 31

Documentation

Index

Constants

View Source
const (
	Autoscaling             = "autoscaling"
	APIGateway              = "apigateway"
	CDN                     = "cdn"
	Cert                    = "cert"
	Cloud                   = "cloud"
	ContainerRegistry       = "containerregistry"
	DNS                     = "dns"
	Mongo                   = "mongo"
	ObjectStorageManagement = "objectstoragemanagement"
	PSQL                    = "psql"
)

products that do not have a location and will override the endpoint that is used globally

View Source
const (
	InMemoryDB    = "inmemorydb"
	InMemoryDBV2  = "inmemorydbv2"
	Kafka         = "kafka"
	Logging       = "logging"
	Mariadb       = "mariadb"
	Monitoring    = "monitoring"
	NFS           = "nfs"
	ObjectStorage = "objectstorage"
	VPN           = "vpn"
	PSQLV2        = "psqlv2"
)

products that have a location and will override the endpoint that is for each location

Variables

This section is empty.

Functions

func DefaultConfigFileName

func DefaultConfigFileName() (string, error)

DefaultConfigFileName returns the default file path for the loaded configuration

Types

type Endpoint

type Endpoint struct {
	// the location or the region
	// Products that do not have a location and will override the endpoint that is used globally:
	// cloud, objectstoragemanagement, kafka, dns, mongo, psql, creg, autoscaling, apigateway
	// Products that have location-based endpoints: logging, monitoring, containerregistry, vpn, inmemorydb, nfs, objectstorage, mariadb
	Location            string `yaml:"location,omitempty"`
	Name                string `yaml:"name"`
	SkipTLSVerify       bool   `yaml:"skipTlsVerify"`
	CertificateAuthData string `yaml:"certificateAuthData,omitempty"`
}

Endpoint is a struct that represents an endpoint

type Environment

type Environment struct {
	Name string `yaml:"name"`
	// CertificateAuthData
	CertificateAuthData string `yaml:"certificateAuthData,omitempty"`
	// Products is a list of ionos products for which we will override endpoint, tls verification
	Products []Product `yaml:"products"`
}

Environment is a struct that represents an environment

type FileConfig

type FileConfig struct {
	// Version of the configuration
	Version Version `yaml:"version"`
	// CurrentProfile active profile for configuration
	CurrentProfile string `yaml:"currentProfile"`
	// Profiles list of profiles
	Profiles []Profile `yaml:"profiles"`
	// Environments list of environments
	Environments []Environment `yaml:"environments"`
	// Failover controls transport-level endpoint failover behaviour and,
	// when set, is propagated to the runtime configuration by the caller.
	Failover *failover.Options `yaml:"failover,omitempty"`
}

FileConfig is a struct that represents the loaded configuration

func New

func New(filePath string) (*FileConfig, error)

New reads yaml file, loads it into a struct and returns it IONOS_CONFIG_FILE environment variable can be set to point to the file to be loaded

func NewFromEnv

func NewFromEnv() (*FileConfig, error)

func (*FileConfig) FilterGlobalOverrides added in v0.1.7

func (f *FileConfig) FilterGlobalOverrides(productName string) []Endpoint

FilterGlobalOverrides returns all global endpoints defined for a given product

func (*FileConfig) FilterLocationOverrides added in v0.1.7

func (f *FileConfig) FilterLocationOverrides(productName string) []Endpoint

FilterLocationOverrides returns all location-based endpoints defined for a given product

func (*FileConfig) FilterOverrides added in v0.1.7

func (f *FileConfig) FilterOverrides(productName string, predicate func(Endpoint) bool) []Endpoint

FilterOverrides returns all endpoints for which the predicate function returns true

func (*FileConfig) GetCurrentProfile

func (f *FileConfig) GetCurrentProfile() *Profile

GetCurrentProfile returns the current profile from the loaded configuration if the current profile is not set, it returns nil if the current profile is set and found in the loaded configuration, it returns the profile

func (*FileConfig) GetEnvForCurrentProfile

func (f *FileConfig) GetEnvForCurrentProfile() string

func (*FileConfig) GetEnvironmentNames added in v0.1.5

func (f *FileConfig) GetEnvironmentNames() []string

GetEnvironmentNames returns a list of environment names from the loaded configuration

func (*FileConfig) GetFailoverOptions added in v0.1.8

func (f *FileConfig) GetFailoverOptions() *failover.Options

GetFailoverOptions returns the failover options from the file configuration. Returns nil when no failover block is defined in the config file.

func (*FileConfig) GetLocationOverridesWithGlobalFallback added in v0.1.7

func (f *FileConfig) GetLocationOverridesWithGlobalFallback(productName, location string) *Endpoint

GetLocationOverridesWithGlobalFallback returns the endpoint for a specific product and location with fallback to the first global endpoint defined if the location is not found. Unlike GetOverride, this function ensures that fallback is done only with global endpoints. It will maintain the order in which the endpoints are defined.

GetLocationOverridesWithGlobalFallback should fail only if the location requested does not exist and there are no global endpoints in the product configuration to fallback on.

func (*FileConfig) GetOverride added in v0.1.5

func (f *FileConfig) GetOverride(productName, location string) *Endpoint

GetOverride returns the endpoint for a specific product and location with fallback to the global endpoint if no location is found. This function will pick the first endpoint defined for the product to attempt fallback. Even if there are global endpoints configured, if the first is location-based, fallback will fail.

It is a helper function combining GetProductLocationOverrides and GetProductOverrides

func (*FileConfig) GetProductGlobalOverrides added in v0.1.7

func (f *FileConfig) GetProductGlobalOverrides(productName string, index int) *Endpoint

GetProductGlobalOverrides returns the n-th overrides for a specific product for the current environment.

func (*FileConfig) GetProductLocationOverrides

func (f *FileConfig) GetProductLocationOverrides(productName, location string) *Endpoint

GetProductLocationOverrides returns the overrides for a specific product and location for the current environment

func (*FileConfig) GetProductOverrides

func (f *FileConfig) GetProductOverrides(productName string) *Product

GetProductOverrides returns the overrides for a specific product for the current environment if no current environment is found, the first environment is used for the product that matches productName is returned

func (*FileConfig) GetProfileNames added in v0.1.5

func (f *FileConfig) GetProfileNames() []string

GetProfileNames returns a list of profile names from the loaded configuration

type Product

type Product struct {
	// Name is the name of the product
	Name      string     `yaml:"name"`
	Endpoints []Endpoint `yaml:"endpoints"`
}

Product is a struct that represents a product

type Profile

type Profile struct {
	Name        string `yaml:"name"`
	Environment string `yaml:"environment"`
	Credentials shared.Credentials
}

Profile is a struct that represents a profile and it's Credentials

type Profiles

type Profiles struct {
	// CurrentProfile active profile for configuration
	CurrentProfile string `yaml:"currentProfile"`
	// Profiles
	Profiles []Profile `yaml:"profiles"`
}

Profiles wrapper to read only the profiles from the config file

func ReadProfilesFromFile

func ReadProfilesFromFile() *Profiles

ReadProfilesFromFile reads profiles from yaml file, loads it into a struct and returns it

type Version added in v0.1.6

type Version float64

Version wraps float64 so we can control its YAML output.

func (Version) MarshalYAML added in v0.1.6

func (v Version) MarshalYAML() (interface{}, error)

MarshalYAML ensures that, e.g., 1.0 is emitted as "1.0" instead of "1".

Jump to

Keyboard shortcuts

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