Documentation
¶
Index ¶
- func ActiveProfiles() []string
- func ConfigurationProperties[T any](prefix string, target *T) *T
- func MatchesProfiles(profiles ...string) bool
- func Value[T any](expression string) T
- type Base64PropertySource
- type Environment
- func (e *Environment) ActiveProfiles() []string
- func (e *Environment) MatchesProfiles(profiles ...string) bool
- func (e *Environment) Property(key string) string
- func (e *Environment) PropertySources() []PropertySource
- func (e *Environment) ResolveRequiredPlaceholders(expression string) any
- func (e *Environment) WithContextVariable(key string, value any) *Environment
- func (e *Environment) WithPropertySource(source PropertySource) *Environment
- type ExprProcessor
- type MapPropertySource
- func (s *MapPropertySource) ContainsProperty(key string) bool
- func (s *MapPropertySource) HasProperty(key string) bool
- func (s *MapPropertySource) Name() string
- func (s *MapPropertySource) Properties() map[string]string
- func (s *MapPropertySource) Property(key string) string
- func (s *MapPropertySource) SetProperties(properties map[string]string)
- func (s *MapPropertySource) SetProperty(key string, value string)
- type PropertiesPropertySource
- type PropertySource
- type RandomValuePropertySource
- func (s *RandomValuePropertySource) HasProperty(key string) bool
- func (s *RandomValuePropertySource) Name() string
- func (s *RandomValuePropertySource) Properties() map[string]string
- func (s *RandomValuePropertySource) Property(key string) string
- func (s *RandomValuePropertySource) RandomInt64Value(minInclusive, maxExclusive int64) int64
- func (s *RandomValuePropertySource) RandomString(length int) string
- func (s *RandomValuePropertySource) RandomUuid() string
- func (s *RandomValuePropertySource) RandomValue(bytes int) string
- type RsaPropertySource
- type YamlPropertySource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigurationProperties ¶
func MatchesProfiles ¶ added in v1.0.9
Determine whether one or more of the given profiles is active.
If a profile begins with '!' the logic is inverted, meaning this method will return true if the given profile is not active. For example, env.MatchesProfiles("p1", "!p2") will return true if profile 'p1' is active or 'p2' is not active. A compound expression allows for more complicated profile logic to be expressed, for example "production & cloud".
Types ¶
type Base64PropertySource ¶
type Base64PropertySource struct {
// contains filtered or unexported fields
}
Custom property source as an additional logic for properties processing, like property=base64:dGVzdAo=
func NewBase64PropertySource ¶
func NewBase64PropertySource(environment *Environment) *Base64PropertySource
func (*Base64PropertySource) HasProperty ¶
func (s *Base64PropertySource) HasProperty(key string) bool
func (*Base64PropertySource) Name ¶
func (s *Base64PropertySource) Name() string
func (*Base64PropertySource) Properties ¶
func (s *Base64PropertySource) Properties() map[string]string
func (*Base64PropertySource) Property ¶
func (s *Base64PropertySource) Property(key string) string
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
func Instance ¶
func Instance() *Environment
func SetActiveProfiles ¶
func SetActiveProfiles(profiles string) *Environment
Bootstrap new environment with profiles listed, last wins. Do nothing if very profiles are already set in the specified order. Reload environment if empty value provided
func (*Environment) MatchesProfiles ¶
func (e *Environment) MatchesProfiles(profiles ...string) bool
Determine whether one or more of the given profiles is active.
If a profile begins with '!' the logic is inverted, meaning this method will return true if the given profile is not active. For example, env.MatchesProfiles("p1", "!p2") will return true if profile 'p1' is active or 'p2' is not active. A compound expression allows for more complicated profile logic to be expressed, for example "production & cloud".
func (*Environment) Property ¶
func (e *Environment) Property(key string) string
func (*Environment) PropertySources ¶
func (e *Environment) PropertySources() []PropertySource
first wins
func (*Environment) ResolveRequiredPlaceholders ¶
func (e *Environment) ResolveRequiredPlaceholders(expression string) any
func (*Environment) WithContextVariable ¶ added in v1.0.18
func (e *Environment) WithContextVariable(key string, value any) *Environment
Add custom context variables to be evaluated. See env.ExprProcessor for expressions and variables available by default.
var _ = env.Instance().WithContextVariable("runtime", map[string]any{
"NumCPU": runtime.NumCPU(),
})
func (*Environment) WithPropertySource ¶ added in v1.0.18
func (e *Environment) WithPropertySource(source PropertySource) *Environment
Add custom property source to implement additional logic for properties processing, like property=base64:dGVzdAo=. See Base64PropertySource (available by default) and RsaPropertySource
var _ = env.Instance().WithPropertySource(env.NewRsaPropertySource())
type ExprProcessor ¶
type ExprProcessor struct {
text.PatternProcessor
// contains filtered or unexported fields
}
See expr-lang: https://expr-lang.org/docs/language-definition
func ExprProcessorOf ¶
func ExprProcessorOf(strict bool) *ExprProcessor
func (*ExprProcessor) Define ¶
func (p *ExprProcessor) Define(key string, value any)
func (*ExprProcessor) Reset ¶
func (p *ExprProcessor) Reset()
func (*ExprProcessor) SetStrict ¶
func (p *ExprProcessor) SetStrict(strict bool)
type MapPropertySource ¶
type MapPropertySource struct {
// contains filtered or unexported fields
}
func MapPropertySourceOf ¶
func MapPropertySourceOf(name string) *MapPropertySource
func MapPropertySourceOfMap ¶
func MapPropertySourceOfMap(name string, source map[string]string) *MapPropertySource
func (*MapPropertySource) ContainsProperty ¶
func (s *MapPropertySource) ContainsProperty(key string) bool
func (*MapPropertySource) HasProperty ¶
func (s *MapPropertySource) HasProperty(key string) bool
func (*MapPropertySource) Name ¶
func (s *MapPropertySource) Name() string
func (*MapPropertySource) Properties ¶
func (s *MapPropertySource) Properties() map[string]string
func (*MapPropertySource) Property ¶
func (s *MapPropertySource) Property(key string) string
func (*MapPropertySource) SetProperties ¶
func (s *MapPropertySource) SetProperties(properties map[string]string)
func (*MapPropertySource) SetProperty ¶
func (s *MapPropertySource) SetProperty(key string, value string)
type PropertiesPropertySource ¶
type PropertiesPropertySource struct {
MapPropertySource
}
func NewPropertiesPropertySource ¶
func NewPropertiesPropertySource(name, content string) *PropertiesPropertySource
type PropertySource ¶
type RandomValuePropertySource ¶ added in v1.0.16
type RandomValuePropertySource struct{}
Custom property source as an additional logic for properties processing, like property=${random.uuid}
${random.value} - Random 64-bit hexadecimal value
${random.int} - Random 32-bit integer (full range)
${random.int(max)} - Random int in [0, max)
${random.int(min,max)} - Random int in [min, max)
${random.int64} - Random 64-bit integer (full range)
${random.int64(max)} - Random int64 in [0, max)
${random.int64(min,max)} - Random int64 in [min, max)
${random.uuid} - Random UUID
${random.string(length)} - Random alphanumeric string
func NewRandomValuePropertySource ¶ added in v1.0.16
func NewRandomValuePropertySource() *RandomValuePropertySource
func (*RandomValuePropertySource) HasProperty ¶ added in v1.0.16
func (s *RandomValuePropertySource) HasProperty(key string) bool
func (*RandomValuePropertySource) Name ¶ added in v1.0.16
func (s *RandomValuePropertySource) Name() string
func (*RandomValuePropertySource) Properties ¶ added in v1.0.16
func (s *RandomValuePropertySource) Properties() map[string]string
func (*RandomValuePropertySource) Property ¶ added in v1.0.16
func (s *RandomValuePropertySource) Property(key string) string
func (*RandomValuePropertySource) RandomInt64Value ¶ added in v1.0.16
func (s *RandomValuePropertySource) RandomInt64Value(minInclusive, maxExclusive int64) int64
func (*RandomValuePropertySource) RandomString ¶ added in v1.0.16
func (s *RandomValuePropertySource) RandomString(length int) string
func (*RandomValuePropertySource) RandomUuid ¶ added in v1.0.16
func (s *RandomValuePropertySource) RandomUuid() string
func (*RandomValuePropertySource) RandomValue ¶ added in v1.0.16
func (s *RandomValuePropertySource) RandomValue(bytes int) string
type RsaPropertySource ¶ added in v1.0.15
type RsaPropertySource struct {
// contains filtered or unexported fields
}
Custom property source as an additional logic for decrypting properties using RSA private key, like pass=RSA:m+WQ5zMBqwMmEEP...
Initialize at the beginning of the main package:
_ = env.Instance().WithPropertySource(env.NewRsaPropertySource())
Provide rsa.privateKey.path property to a PEM file to decrypt properties on a target environment.
Encrypt property using RSA public key
echo -n "dbSecret123" | openssl pkeyutl -encrypt \ -pubin -inkey public2048.pem \ -pkeyopt rsa_padding_mode:oaep \ -pkeyopt rsa_oaep_md:sha256 | base64
echo -n "dbSecret123" - supplies plaintext to stdin (no trailing newline).
openssl pkeyutl -encrypt - tells OpenSSL to encrypt with a public key.
-pubin -inkey public2048.pem - uses your RSA public key.
-pkeyopt rsa_padding_mode:oaep - selects OAEP padding (modern, secure).
-pkeyopt rsa_oaep_md:sha256 - sets both OAEP digest and (implicitly) MGF1 digest to SHA-256. (OpenSSL ≥1.0.2 automatically uses the same digest for MGF1 if not overridden).
| base64 - encodes the ciphertext to text format. It is safe to remove any line breaks.
func NewRsaPropertySource ¶ added in v1.0.15
func NewRsaPropertySource() *RsaPropertySource
func (*RsaPropertySource) HasProperty ¶ added in v1.0.15
func (s *RsaPropertySource) HasProperty(key string) bool
func (*RsaPropertySource) Name ¶ added in v1.0.15
func (s *RsaPropertySource) Name() string
func (*RsaPropertySource) Properties ¶ added in v1.0.15
func (s *RsaPropertySource) Properties() map[string]string
func (*RsaPropertySource) Property ¶ added in v1.0.15
func (s *RsaPropertySource) Property(key string) string
type YamlPropertySource ¶
type YamlPropertySource struct {
MapPropertySource
}
func NewYamlPropertySource ¶
func NewYamlPropertySource(name, yaml string) *YamlPropertySource