2022-11-18 15:21:15 +01:00
|
|
|
package internal
|
|
|
|
|
2023-04-11 14:05:20 +02:00
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
)
|
2022-11-24 20:57:01 +01:00
|
|
|
|
2022-11-18 15:21:15 +01:00
|
|
|
type Configuration interface {
|
2022-11-29 10:16:07 +01:00
|
|
|
UsesMetrics() bool
|
2022-11-18 15:21:15 +01:00
|
|
|
UsesTracing() bool
|
|
|
|
UsesProfiling() bool
|
2022-11-22 10:10:07 +01:00
|
|
|
UsesKubeconfig() bool
|
2023-04-11 09:12:05 +02:00
|
|
|
UsesPolicyExceptions() bool
|
|
|
|
UsesConfigMapCaching() bool
|
2023-04-11 15:32:17 +02:00
|
|
|
UsesRegistryClient() bool
|
2022-11-24 20:57:01 +01:00
|
|
|
FlagSets() []*flag.FlagSet
|
2022-11-18 15:21:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewConfiguration(options ...ConfigurationOption) Configuration {
|
|
|
|
c := &configuration{}
|
|
|
|
for _, option := range options {
|
|
|
|
option(c)
|
|
|
|
}
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
type ConfigurationOption func(c *configuration)
|
|
|
|
|
2022-11-29 10:16:07 +01:00
|
|
|
func WithMetrics() ConfigurationOption {
|
|
|
|
return func(c *configuration) {
|
|
|
|
c.usesMetrics = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-18 15:21:15 +01:00
|
|
|
func WithTracing() ConfigurationOption {
|
|
|
|
return func(c *configuration) {
|
|
|
|
c.usesTracing = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithProfiling() ConfigurationOption {
|
|
|
|
return func(c *configuration) {
|
|
|
|
c.usesProfiling = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-22 10:10:07 +01:00
|
|
|
func WithKubeconfig() ConfigurationOption {
|
|
|
|
return func(c *configuration) {
|
|
|
|
c.usesKubeconfig = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-11 09:12:05 +02:00
|
|
|
func WithPolicyExceptions() ConfigurationOption {
|
|
|
|
return func(c *configuration) {
|
|
|
|
c.usesPolicyExceptions = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithConfigMapCaching() ConfigurationOption {
|
|
|
|
return func(c *configuration) {
|
|
|
|
c.usesConfigMapCaching = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-11 15:32:17 +02:00
|
|
|
func WithRegistryClient() ConfigurationOption {
|
|
|
|
return func(c *configuration) {
|
|
|
|
c.usesRegistryClient = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-24 20:57:01 +01:00
|
|
|
func WithFlagSets(flagsets ...*flag.FlagSet) ConfigurationOption {
|
|
|
|
return func(c *configuration) {
|
|
|
|
c.flagSets = append(c.flagSets, flagsets...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-18 15:21:15 +01:00
|
|
|
type configuration struct {
|
2023-04-11 09:12:05 +02:00
|
|
|
usesMetrics bool
|
|
|
|
usesTracing bool
|
|
|
|
usesProfiling bool
|
|
|
|
usesKubeconfig bool
|
|
|
|
usesPolicyExceptions bool
|
|
|
|
usesConfigMapCaching bool
|
2023-04-11 15:32:17 +02:00
|
|
|
usesRegistryClient bool
|
2023-04-11 09:12:05 +02:00
|
|
|
flagSets []*flag.FlagSet
|
2022-11-18 15:21:15 +01:00
|
|
|
}
|
|
|
|
|
2022-11-29 10:16:07 +01:00
|
|
|
func (c *configuration) UsesMetrics() bool {
|
|
|
|
return c.usesMetrics
|
|
|
|
}
|
|
|
|
|
2022-11-18 15:21:15 +01:00
|
|
|
func (c *configuration) UsesTracing() bool {
|
|
|
|
return c.usesTracing
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *configuration) UsesProfiling() bool {
|
|
|
|
return c.usesProfiling
|
|
|
|
}
|
2022-11-22 10:10:07 +01:00
|
|
|
|
|
|
|
func (c *configuration) UsesKubeconfig() bool {
|
|
|
|
return c.usesKubeconfig
|
|
|
|
}
|
2022-11-24 20:57:01 +01:00
|
|
|
|
2023-04-11 09:12:05 +02:00
|
|
|
func (c *configuration) UsesPolicyExceptions() bool {
|
|
|
|
return c.usesPolicyExceptions
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *configuration) UsesConfigMapCaching() bool {
|
|
|
|
return c.usesConfigMapCaching
|
|
|
|
}
|
|
|
|
|
2023-04-11 15:32:17 +02:00
|
|
|
func (c *configuration) UsesRegistryClient() bool {
|
|
|
|
return c.usesRegistryClient
|
|
|
|
}
|
|
|
|
|
2022-11-24 20:57:01 +01:00
|
|
|
func (c *configuration) FlagSets() []*flag.FlagSet {
|
|
|
|
return c.flagSets
|
|
|
|
}
|