config

package
v0.0.0-...-845c20a Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

The scope of this file is: - Define the configuration struct. - Set default configuration values. - Map the data so viper can load the configuration there. See: https://articles.wesionary.team/environment-variable-configuration-in-your-golang-project-using-viper-4e8289ef664d See: https://consoledot.pages.redhat.com/docs/dev/getting-started/migration/config.html

Index

Constants

View Source
const (
	// DefaultAppName is used to compose the route paths
	DefaultAppName = "idmsvc"
	// API URL path prefix
	DefaultPathPrefix = "/api/idmsvc/v1"
	// DefaultExpirationTime is used for the default token expiration period
	// expressed in seconds. The default value is set to 7200 (2 hours)
	DefaultTokenExpirationTimeSeconds = 7200
	// HostconfJWKs expire after 90 days and get renewed when the last
	// token expires in less than 30 days.
	DefaultHostconfJwkValidity         = time.Duration(90 * 24 * time.Hour)
	DefaultHostconfJwkRenewalThreshold = time.Duration(30 * 24 * time.Hour)
	// DefaultWebPort is the default port where the public API is listening
	DefaultWebPort = 8000
	// DefaultEnableRBAC is true
	DefaultEnableRBAC = true

	// PaginationDefaultLimit is the default limit for the pagination
	PaginationDefaultLimit = 10
	// PaginationMaxLimit is the default max limit for the pagination
	PaginationMaxLimit = 1000

	// DefaultAcceptXRHFakeIdentity is disabled
	DefaultAcceptXRHFakeIdentity = false
	// DefaultValidateAPI is true
	DefaultValidateAPI = true
)

Variables

This section is empty.

Functions

func DefaultCloudwatchStream

func DefaultCloudwatchStream() string

func Load

func Load(cfg *Config) *viper.Viper

func Validate

func Validate(cfg *Config) (err error)

Types

type Application

type Application struct {
	// Name is the internal application name
	Name string `validate:"required"`
	// API URL's path prefix, e.g. /api/idmsvc/v1
	PathPrefix string `mapstructure:"url_path_prefix" validate:"required"`
	// This is the default expiration time for the token
	// generated when a RHEL IDM domain is created
	TokenExpirationTimeSeconds int `mapstructure:"token_expiration_seconds" validate:"gte=600,lte=86400"`
	// Expiration and renewal duration for hostconf JWKs
	// TODO: short gte for local testing
	HostconfJwkValidity         time.Duration `mapstructure:"hostconf_jwk_validity" validate:"gte=1m,lte=8760h"`
	HostconfJwkRenewalThreshold time.Duration `mapstructure:"hostconf_jwk_renewal_threshold" validate:"gte=1m,lte=2160h"`
	// Indicate the default pagination limit when it is 0 or not filled
	PaginationDefaultLimit int `mapstructure:"pagination_default_limit"`
	// Indicate the max pagination limit when it is grather
	PaginationMaxLimit int `mapstructure:"pagination_max_limit"`
	// AcceptXRHFakeIdentity define when the fake middleware is added to the route
	// to process the x-rh-fake-identity
	AcceptXRHFakeIdentity bool `mapstructure:"accept_x_rh_fake_identity"`
	// ValidateAPI indicate when the middleware to validate the API
	// requests and responses is disabled; by default it is enabled.
	ValidateAPI bool `mapstructure:"validate_api"`
	// secret for various MAC and encryptions like domain registration
	// token and encrypted private JWKs.
	// Secrets are derived with HKDF-SHA256.
	MainSecret string `mapstructure:"secret" validate:"required,base64rawurl" json:"-"`
	// Flag to enable/disable rbac
	EnableRBAC bool `mapstructure:"enable_rbac"`
}

Application hold specific application settings

type Clients

type Clients struct {
	// InventoryBaseURL is the base endpoint to launch inventory requests.
	InventoryBaseURL string `mapstructure:"inventory_base_url"`
	// RbacBaseURL is the base endpoint to launch RBAC requests.
	RbacBaseURL string `mapstructure:"rbac_base_url"`
}

Clients gather all the configuration to properly setup the third party services that idmsvc need to interact with.

type Cloudwatch

type Cloudwatch struct {
	Region  string
	Key     string
	Secret  string `json:"-"`
	Session string
	Group   string
	Stream  string
}

type Config

type Config struct {
	Loaded      bool
	Web         Web
	Database    Database
	Logging     Logging
	Kafka       Kafka
	Metrics     Metrics
	Clients     Clients
	Application Application `mapstructure:"app"`
	// Secrets is an untagged field and filled out on load
	Secrets secrets.AppSecrets `mapstructure:"-" json:"-"`
}

func Get

func Get() *Config

Get is a singleton to get the global loaded configuration.

type Database

type Database struct {
	Host     string
	Port     int
	User     string
	Password string `json:"-"`
	Name     string
	// https://stackoverflow.com/questions/54844546/how-to-unmarshal-golang-viper-snake-case-values
	CACertPath string `mapstructure:"ca_cert_path"`
}

type Kafka

type Kafka struct {
	Timeout int
	Group   struct {
		Id string
	}
	Auto struct {
		Offset struct {
			Reset string
		}
		Commit struct {
			Interval struct {
				Ms int
			}
		}
	}
	Bootstrap struct {
		Servers string
	}
	Topics []string
	Sasl   struct {
		Username  string
		Password  string `json:"-"`
		Mechanism string
		Protocol  string
	}
	Request struct {
		Timeout struct {
			Ms int
		}
		Required struct {
			Acks int
		}
	}
	Capath  string
	Message struct {
		Send struct {
			Max struct {
				Retries int
			}
		}
	}
	Retry struct {
		Backoff struct {
			Ms int
		}
	}
}

type Logging

type Logging struct {
	Level      string
	Console    bool
	Location   bool
	Type       string
	Cloudwatch Cloudwatch
}

type Metrics

type Metrics struct {
	// Defines the path to the metrics server that the app should be configured to
	// listen on for metric traffic.
	Path string `mapstructure:"path"`

	// Defines the metrics port that the app should be configured to listen on for
	// metric traffic.
	Port int `mapstructure:"port"`
}

type TopicTranslation

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

TopicMap is used to map between real and internal topics, this is it could be that the name we indicate for the topics into the clowderapp resource be different from the real created in kafka, so this type allow to preproce the mappings, and use them when needed to translate them into the producer and consumer functions

var TopicTranslationConfig *TopicTranslation = nil

It store the mapping between the internal topic managed by the service and the real topic managed by kafka

func NewTopicTranslationWithClowder

func NewTopicTranslationWithClowder(cfg *clowder.AppConfig) *TopicTranslation

NewTopicTranslationWithClowder Build a topic map based into the clowder configuration.

func NewTopicTranslationWithDefaults

func NewTopicTranslationWithDefaults() *TopicTranslation

NewDefaultTopicMap Build a default topic map that map all the allowed topics to itselfs Return A TopicMap initialized as default values

func (*TopicTranslation) GetInternal

func (tm *TopicTranslation) GetInternal(realTopic string) string

GetInternal translate the name of a real topic to the internal topic name. This will be used by the consumers.

func (*TopicTranslation) GetReal

func (tm *TopicTranslation) GetReal(internalTopic string) string

GetReal translate the name of an internal topic to the real topic name. This will be used by the producers. Returns empty string when the topic is not found into the translation map.

type Web

type Web struct {
	Port int16
}

Jump to

Keyboard shortcuts

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