Skip to content

Commit

Permalink
chore: yaml struct tags
Browse files Browse the repository at this point in the history
  • Loading branch information
markphelps committed Sep 19, 2023
1 parent de92e35 commit 0a4bc1f
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 142 deletions.
26 changes: 13 additions & 13 deletions internal/config/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ var _ defaulter = (*AuditConfig)(nil)
// AuditConfig contains fields, which enable and configure
// Flipt's various audit sink mechanisms.
type AuditConfig struct {
Sinks SinksConfig `json:"sinks,omitempty" mapstructure:"sinks"`
Buffer BufferConfig `json:"buffer,omitempty" mapstructure:"buffer"`
Events []string `json:"events,omitempty" mapstructure:"events"`
Sinks SinksConfig `json:"sinks,omitempty" mapstructure:"sinks" yaml:"sinks,omitempty"`
Buffer BufferConfig `json:"buffer,omitempty" mapstructure:"buffer" yaml:"buffer,omitempty"`
Events []string `json:"events,omitempty" mapstructure:"events" yaml:"events,omitempty"`
}

// Enabled returns true if any nested sink is enabled
Expand Down Expand Up @@ -67,29 +67,29 @@ func (c *AuditConfig) validate() error {
// SinksConfig contains configuration held in structures for the different sinks
// that we will send audits to.
type SinksConfig struct {
LogFile LogFileSinkConfig `json:"log,omitempty" mapstructure:"log"`
Webhook WebhookSinkConfig `json:"webhook,omitempty" mapstructure:"webhook"`
LogFile LogFileSinkConfig `json:"log,omitempty" mapstructure:"log" yaml:"log,omitempty"`
Webhook WebhookSinkConfig `json:"webhook,omitempty" mapstructure:"webhook" yaml:"webhook,omitempty"`
}

// WebhookSinkConfig contains configuration for sending POST requests to specific
// URL as its configured.
type WebhookSinkConfig struct {
Enabled bool `json:"enabled,omitempty" mapstructure:"enabled"`
URL string `json:"url,omitempty" mapstructure:"url"`
MaxBackoffDuration time.Duration `json:"maxBackoffDuration,omitempty" mapstructure:"max_backoff_duration"`
SigningSecret string `json:"signingSecret,omitempty" mapstructure:"signing_secret"`
Enabled bool `json:"enabled" mapstructure:"enabled" yaml:"enabled"`
URL string `json:"url,omitempty" mapstructure:"url" yaml:"url,omitempty"`
MaxBackoffDuration time.Duration `json:"maxBackoffDuration,omitempty" mapstructure:"max_backoff_duration" yaml:"max_backoff_duration,omitempty"`
SigningSecret string `json:"-" mapstructure:"signing_secret" yaml:"-"`
}

// LogFileSinkConfig contains fields that hold configuration for sending audits
// to a log file.
type LogFileSinkConfig struct {
Enabled bool `json:"enabled,omitempty" mapstructure:"enabled"`
File string `json:"file,omitempty" mapstructure:"file"`
Enabled bool `json:"enabled,omitempty" mapstructure:"enabled" yaml:"enabled,omitempty"`
File string `json:"file,omitempty" mapstructure:"file" yaml:"file,omitempty"`
}

// BufferConfig holds configuration for the buffering of sending the audit
// events to the sinks.
type BufferConfig struct {
Capacity int `json:"capacity,omitempty" mapstructure:"capacity"`
FlushPeriod time.Duration `json:"flushPeriod,omitempty" mapstructure:"flush_period"`
Capacity int `json:"capacity,omitempty" mapstructure:"capacity" yaml:"capacity,omitempty"`
FlushPeriod time.Duration `json:"flushPeriod,omitempty" mapstructure:"flush_period" yaml:"flush_period,omitempty"`
}
76 changes: 38 additions & 38 deletions internal/config/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ type AuthenticationConfig struct {
// Required designates whether authentication credentials are validated.
// If required == true, then authentication is required for all API endpoints.
// Else, authentication is not required and Flipt's APIs are not secured.
Required bool `json:"required,omitempty" mapstructure:"required"`
Required bool `json:"required" mapstructure:"required" yaml:"required"`

// Exclude allows you to skip enforcing authentication on the different
// top-level sections of the API.
// By default, given required == true, the API is fully protected.
Exclude struct {
// Management refers to the section of the API with the prefix /api/v1
Management bool `json:"management,omitempty" mapstructure:"management"`
Management bool `json:"management,omitempty" mapstructure:"management" yaml:"management,omitempty"`
// Metadata refers to the section of the API with the prefix /meta
Metadata bool `json:"metadata,omitempty" mapstructure:"metadata"`
Metadata bool `json:"metadata,omitempty" mapstructure:"metadata" yaml:"metadata,omitempty"`
// Evaluation refers to the section of the API with the prefix /evaluation/v1
Evaluation bool `json:"evaluation,omitempty" mapstructure:"evaluation"`
} `json:"exclude,omitempty" mapstructure:"exclude"`
Evaluation bool `json:"evaluation,omitempty" mapstructure:"evaluation" yaml:"evaluation,omitempty"`
} `json:"exclude,omitempty" mapstructure:"exclude" yaml:"exclude,omitempty"`

Session AuthenticationSession `json:"session,omitempty" mapstructure:"session"`
Methods AuthenticationMethods `json:"methods,omitempty" mapstructure:"methods"`
Session AuthenticationSession `json:"session,omitempty" mapstructure:"session" yaml:"session,omitempty"`
Methods AuthenticationMethods `json:"methods,omitempty" mapstructure:"methods" yaml:"methods,omitempty"`
}

// Enabled returns true if authentication is marked as required
Expand Down Expand Up @@ -181,16 +181,16 @@ func getHostname(rawurl string) (string, error) {
// establishing authentication via HTTP.
type AuthenticationSession struct {
// Domain is the domain on which to register session cookies.
Domain string `json:"domain,omitempty" mapstructure:"domain"`
Domain string `json:"domain,omitempty" mapstructure:"domain" yaml:"domain,omitempty"`
// Secure sets the secure property (i.e. HTTPS only) on both the state and token cookies.
Secure bool `json:"secure" mapstructure:"secure"`
Secure bool `json:"secure,omitempty" mapstructure:"secure" yaml:"secure,omitempty"`
// TokenLifetime is the duration of the flipt client token generated once
// authentication has been established via a session compatible method.
TokenLifetime time.Duration `json:"tokenLifetime,omitempty" mapstructure:"token_lifetime"`
TokenLifetime time.Duration `json:"tokenLifetime,omitempty" mapstructure:"token_lifetime" yaml:"token_lifetime,omitempty"`
// StateLifetime is the lifetime duration of the state cookie.
StateLifetime time.Duration `json:"stateLifetime,omitempty" mapstructure:"state_lifetime"`
StateLifetime time.Duration `json:"stateLifetime,omitempty" mapstructure:"state_lifetime" yaml:"state_lifetime,omitempty"`
// CSRF configures CSRF provention mechanisms.
CSRF AuthenticationSessionCSRF `json:"csrf,omitempty" mapstructure:"csrf"`
CSRF AuthenticationSessionCSRF `json:"csrf,omitempty" mapstructure:"csrf" yaml:"csrf,omitempty"`
}

// AuthenticationSessionCSRF configures cross-site request forgery prevention.
Expand All @@ -202,10 +202,10 @@ type AuthenticationSessionCSRF struct {
// AuthenticationMethods is a set of configuration for each authentication
// method available for use within Flipt.
type AuthenticationMethods struct {
Token AuthenticationMethod[AuthenticationMethodTokenConfig] `json:"token,omitempty" mapstructure:"token"`
Github AuthenticationMethod[AuthenticationMethodGithubConfig] `json:"github,omitempty" mapstructure:"github"`
OIDC AuthenticationMethod[AuthenticationMethodOIDCConfig] `json:"oidc,omitempty" mapstructure:"oidc"`
Kubernetes AuthenticationMethod[AuthenticationMethodKubernetesConfig] `json:"kubernetes,omitempty" mapstructure:"kubernetes"`
Token AuthenticationMethod[AuthenticationMethodTokenConfig] `json:"token,omitempty" mapstructure:"token" yaml:"token,omitempty"`
Github AuthenticationMethod[AuthenticationMethodGithubConfig] `json:"github,omitempty" mapstructure:"github" yaml:"github,omitempty"`
OIDC AuthenticationMethod[AuthenticationMethodOIDCConfig] `json:"oidc,omitempty" mapstructure:"oidc" yaml:"oidc,omitempty"`
Kubernetes AuthenticationMethod[AuthenticationMethodKubernetesConfig] `json:"kubernetes,omitempty" mapstructure:"kubernetes" yaml:"kubernetes,omitempty"`
}

// AllMethods returns all the AuthenticationMethod instances available.
Expand Down Expand Up @@ -288,8 +288,8 @@ type AuthenticationMethodInfoProvider interface {
// nolint:musttag
type AuthenticationMethod[C AuthenticationMethodInfoProvider] struct {
Method C `mapstructure:",squash"`
Enabled bool `json:"enabled,omitempty" mapstructure:"enabled"`
Cleanup *AuthenticationCleanupSchedule `json:"cleanup,omitempty" mapstructure:"cleanup,omitempty"`
Enabled bool `json:"enabled,omitempty" mapstructure:"enabled" yaml:"enabled,omitempty"`
Cleanup *AuthenticationCleanupSchedule `json:"cleanup,omitempty" mapstructure:"cleanup,omitempty" yaml:"cleanup,omitempty"`
}

func (a *AuthenticationMethod[C]) setDefaults(defaults map[string]any) {
Expand Down Expand Up @@ -317,7 +317,7 @@ func (a *AuthenticationMethod[C]) info() StaticAuthenticationMethodInfo {
// This authentication method supports the ability to create static tokens via the
// /auth/v1/method/token prefix of endpoints.
type AuthenticationMethodTokenConfig struct {
Bootstrap AuthenticationMethodTokenBootstrapConfig `json:"bootstrap" mapstructure:"bootstrap"`
Bootstrap AuthenticationMethodTokenBootstrapConfig `json:"bootstrap" mapstructure:"bootstrap" yaml:"bootstrap"`
}

func (a AuthenticationMethodTokenConfig) setDefaults(map[string]any) {}
Expand All @@ -333,15 +333,15 @@ func (a AuthenticationMethodTokenConfig) info() AuthenticationMethodInfo {
// AuthenticationMethodTokenBootstrapConfig contains fields used to configure the
// bootstrap process for the authentication method "token".
type AuthenticationMethodTokenBootstrapConfig struct {
Token string `json:"-" mapstructure:"token"`
Expiration time.Duration `json:"expiration,omitempty" mapstructure:"expiration"`
Token string `json:"-" mapstructure:"token" yaml:"token"`
Expiration time.Duration `json:"expiration,omitempty" mapstructure:"expiration" yaml:"expiration,omitempty"`
}

// AuthenticationMethodOIDCConfig configures the OIDC authentication method.
// This method can be used to establish browser based sessions.
type AuthenticationMethodOIDCConfig struct {
EmailMatches []string `json:"emailMatches,omitempty" mapstructure:"email_matches"`
Providers map[string]AuthenticationMethodOIDCProvider `json:"providers,omitempty" mapstructure:"providers"`
EmailMatches []string `json:"emailMatches,omitempty" mapstructure:"email_matches" yaml:"email_matches,omitempty"`
Providers map[string]AuthenticationMethodOIDCProvider `json:"providers,omitempty" mapstructure:"providers" yaml:"providers,omitempty"`
}

func (a AuthenticationMethodOIDCConfig) setDefaults(map[string]any) {}
Expand Down Expand Up @@ -376,18 +376,18 @@ func (a AuthenticationMethodOIDCConfig) info() AuthenticationMethodInfo {

// AuthenticationOIDCProvider configures provider credentials
type AuthenticationMethodOIDCProvider struct {
IssuerURL string `json:"issuerURL,omitempty" mapstructure:"issuer_url"`
ClientID string `json:"clientID,omitempty" mapstructure:"client_id"`
ClientSecret string `json:"clientSecret,omitempty" mapstructure:"client_secret"`
RedirectAddress string `json:"redirectAddress,omitempty" mapstructure:"redirect_address"`
Scopes []string `json:"scopes,omitempty" mapstructure:"scopes"`
UsePKCE bool `json:"usePKCE,omitempty" mapstructure:"use_pkce"`
IssuerURL string `json:"issuerURL,omitempty" mapstructure:"issuer_url" yaml:"issuer_url,omitempty"`
ClientID string `json:"clientID,omitempty" mapstructure:"client_id" yaml:"client_id,omitempty"`
ClientSecret string `json:"-" mapstructure:"client_secret" yaml:"-"`
RedirectAddress string `json:"redirectAddress,omitempty" mapstructure:"redirect_address" yaml:"redirect_address,omitempty"`
Scopes []string `json:"scopes,omitempty" mapstructure:"scopes" yaml:"scopes,omitempty"`
UsePKCE bool `json:"usePKCE,omitempty" mapstructure:"use_pkce" yaml:"use_pkce,omitempty"`
}

// AuthenticationCleanupSchedule is used to configure a cleanup goroutine.
type AuthenticationCleanupSchedule struct {
Interval time.Duration `json:"interval,omitempty" mapstructure:"interval"`
GracePeriod time.Duration `json:"gracePeriod,omitempty" mapstructure:"grace_period"`
Interval time.Duration `json:"interval,omitempty" mapstructure:"interval" yaml:"interval,omitempty"`
GracePeriod time.Duration `json:"gracePeriod,omitempty" mapstructure:"grace_period" yaml:"grace_period,omitempty"`
}

// AuthenticationMethodKubernetesConfig contains the fields necessary for the Kubernetes authentication
Expand All @@ -397,13 +397,13 @@ type AuthenticationMethodKubernetesConfig struct {
// DiscoveryURL is the URL to the local Kubernetes cluster serving the "well-known" OIDC discovery endpoint.
// https://openid.net/specs/openid-connect-discovery-1_0.html
// The URL is used to fetch the OIDC configuration and subsequently the JWKS certificates.
DiscoveryURL string `json:"discoveryURL,omitempty" mapstructure:"discovery_url"`
DiscoveryURL string `json:"discoveryURL,omitempty" mapstructure:"discovery_url" yaml:"discovery_url,omitempty"`
// CAPath is the path on disk to the trusted certificate authority certificate for validating
// HTTPS requests to the issuer.
CAPath string `json:"caPath,omitempty" mapstructure:"ca_path"`
CAPath string `json:"caPath,omitempty" mapstructure:"ca_path" yaml:"ca_path,omitempty"`
// ServiceAccountTokenPath is the location on disk to the Flipt instances service account token.
// This should be the token issued for the service account associated with Flipt in the environment.
ServiceAccountTokenPath string `json:"serviceAccountTokenPath,omitempty" mapstructure:"service_account_token_path"`
ServiceAccountTokenPath string `json:"serviceAccountTokenPath,omitempty" mapstructure:"service_account_token_path" yaml:"service_account_token_path,omitempty"`
}

func (a AuthenticationMethodKubernetesConfig) setDefaults(defaults map[string]any) {
Expand All @@ -423,10 +423,10 @@ func (a AuthenticationMethodKubernetesConfig) info() AuthenticationMethodInfo {
// AuthenticationMethodGithubConfig contains configuration and information for completing an OAuth
// 2.0 flow with GitHub as a provider.
type AuthenticationMethodGithubConfig struct {
ClientSecret string `json:"clientSecret,omitempty" mapstructure:"client_secret"`
ClientId string `json:"clientId,omitempty" mapstructure:"client_id"`
RedirectAddress string `json:"redirectAddress,omitempty" mapstructure:"redirect_address"`
Scopes []string `json:"scopes,omitempty" mapstructure:"scopes"`
ClientId string `json:"clientId,omitempty" mapstructure:"client_id" yaml:"client_id,omitempty"`
ClientSecret string `json:"-" mapstructure:"client_secret" yaml:"-"`
RedirectAddress string `json:"redirectAddress,omitempty" mapstructure:"redirect_address" yaml:"redirect_address,omitempty"`
Scopes []string `json:"scopes,omitempty" mapstructure:"scopes" yaml:"scopes,omitempty"`
}

func (a AuthenticationMethodGithubConfig) setDefaults(defaults map[string]any) {}
Expand Down
30 changes: 15 additions & 15 deletions internal/config/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ var _ defaulter = (*CacheConfig)(nil)
//
// Currently, flipt support in-memory and redis backed caching.
type CacheConfig struct {
Enabled bool `json:"enabled" mapstructure:"enabled"`
TTL time.Duration `json:"ttl,omitempty" mapstructure:"ttl"`
Backend CacheBackend `json:"backend,omitempty" mapstructure:"backend"`
Memory MemoryCacheConfig `json:"memory,omitempty" mapstructure:"memory"`
Redis RedisCacheConfig `json:"redis,omitempty" mapstructure:"redis"`
Enabled bool `json:"enabled" mapstructure:"enabled" yaml:"enabled"`
TTL time.Duration `json:"ttl,omitempty" mapstructure:"ttl" yaml:"ttl,omitempty"`
Backend CacheBackend `json:"backend,omitempty" mapstructure:"backend" yaml:"backend,omitempty"`
Memory MemoryCacheConfig `json:"memory,omitempty" mapstructure:"memory" yaml:"memory,omitempty"`
Redis RedisCacheConfig `json:"redis,omitempty" mapstructure:"redis" yaml:"redis,omitempty"`
}

func (c *CacheConfig) setDefaults(v *viper.Viper) error {
Expand Down Expand Up @@ -75,19 +75,19 @@ var (

// MemoryCacheConfig contains fields, which configure in-memory caching.
type MemoryCacheConfig struct {
EvictionInterval time.Duration `json:"evictionInterval,omitempty" mapstructure:"eviction_interval"`
EvictionInterval time.Duration `json:"evictionInterval,omitempty" mapstructure:"eviction_interval" yaml:"eviction_interval,omitempty"`
}

// RedisCacheConfig contains fields, which configure the connection
// credentials for redis backed caching.
type RedisCacheConfig struct {
Host string `json:"host,omitempty" mapstructure:"host"`
Port int `json:"port,omitempty" mapstructure:"port"`
RequireTLS bool `json:"requireTLS" mapstructure:"require_tls"`
Password string `json:"password,omitempty" mapstructure:"password"`
DB int `json:"db,omitempty" mapstructure:"db"`
PoolSize int `json:"poolSize" mapstructure:"pool_size"`
MinIdleConn int `json:"minIdleConn" mapstructure:"min_idle_conn"`
ConnMaxIdleTime time.Duration `json:"connMaxIdleTime" mapstructure:"conn_max_idle_time"`
NetTimeout time.Duration `json:"netTimeout" mapstructure:"net_timeout"`
Host string `json:"host,omitempty" mapstructure:"host" yaml:"host,omitempty"`
Port int `json:"port,omitempty" mapstructure:"port" yaml:"port,omitempty"`
RequireTLS bool `json:"requireTLS,omitempty" mapstructure:"require_tls" yaml:"require_tls,omitempty"`
Password string `json:"-" mapstructure:"password" yaml:"-"`
DB int `json:"db,omitempty" mapstructure:"db" yaml:"db,omitempty"`
PoolSize int `json:"poolSize" mapstructure:"pool_size" yaml:"pool_size"`
MinIdleConn int `json:"minIdleConn" mapstructure:"min_idle_conn" yaml:"min_idle_conn"`
ConnMaxIdleTime time.Duration `json:"connMaxIdleTime" mapstructure:"conn_max_idle_time" yaml:"conn_max_idle_time"`
NetTimeout time.Duration `json:"netTimeout" mapstructure:"net_timeout" yaml:"net_timeout"`
}
Loading

0 comments on commit 0a4bc1f

Please sign in to comment.