config: move acl_ttl to DeprecatedConfig

This commit is contained in:
Daniel Nephin 2021-09-22 13:38:40 -04:00
parent 977f6d8888
commit 5c40b717ed
6 changed files with 18 additions and 5 deletions

View File

@ -856,7 +856,7 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
Datacenter: datacenter, Datacenter: datacenter,
NodeName: b.nodeName(c.NodeName), NodeName: b.nodeName(c.NodeName),
ACLPolicyTTL: b.durationVal("acl.policy_ttl", c.ACL.PolicyTTL), ACLPolicyTTL: b.durationVal("acl.policy_ttl", c.ACL.PolicyTTL),
ACLTokenTTL: b.durationValWithDefault("acl.token_ttl", c.ACL.TokenTTL, b.durationVal("acl_ttl", c.ACLTTL)), ACLTokenTTL: b.durationVal("acl.token_ttl", c.ACL.TokenTTL),
ACLRoleTTL: b.durationVal("acl.role_ttl", c.ACL.RoleTTL), ACLRoleTTL: b.durationVal("acl.role_ttl", c.ACL.RoleTTL),
ACLDownPolicy: stringVal(c.ACL.DownPolicy), ACLDownPolicy: stringVal(c.ACL.DownPolicy),
ACLDefaultPolicy: stringVal(c.ACL.DefaultPolicy), ACLDefaultPolicy: stringVal(c.ACL.DefaultPolicy),

View File

@ -131,9 +131,7 @@ type Cache struct {
// changed and refactored at will since this will break existing setups. // changed and refactored at will since this will break existing setups.
type Config struct { type Config struct {
// DEPRECATED (ACL-Legacy-Compat) - moved into the "acl" stanza // DEPRECATED (ACL-Legacy-Compat) - moved into the "acl" stanza
ACLEnableKeyListPolicy *bool `mapstructure:"acl_enable_key_list_policy"` ACLEnableKeyListPolicy *bool `mapstructure:"acl_enable_key_list_policy"`
// DEPRECATED (ACL-Legacy-Compat) - moved into the "acl.tokens" stanza
ACLTTL *string `mapstructure:"acl_ttl"`
ACL ACL `mapstructure:"acl"` ACL ACL `mapstructure:"acl"`
Addresses Addresses `mapstructure:"addresses"` Addresses Addresses `mapstructure:"addresses"`
AdvertiseAddrLAN *string `mapstructure:"advertise_addr"` AdvertiseAddrLAN *string `mapstructure:"advertise_addr"`

View File

@ -27,8 +27,8 @@ func DefaultSource() Source {
Name: "default", Name: "default",
Format: "hcl", Format: "hcl",
Data: ` Data: `
acl_ttl = "30s"
acl = { acl = {
token_ttl = "30s"
policy_ttl = "30s" policy_ttl = "30s"
default_policy = "allow" default_policy = "allow"
down_policy = "extend-cache" down_policy = "extend-cache"

View File

@ -24,6 +24,8 @@ type DeprecatedConfig struct {
ACLDefaultPolicy *string `mapstructure:"acl_default_policy"` ACLDefaultPolicy *string `mapstructure:"acl_default_policy"`
// DEPRECATED (ACL-Legacy-Compat) - moved to "acl.down_policy" // DEPRECATED (ACL-Legacy-Compat) - moved to "acl.down_policy"
ACLDownPolicy *string `mapstructure:"acl_down_policy"` ACLDownPolicy *string `mapstructure:"acl_down_policy"`
// DEPRECATED (ACL-Legacy-Compat) - moved to "acl.token_ttl"
ACLTTL *string `mapstructure:"acl_ttl"`
} }
func applyDeprecatedConfig(d *decodeTarget) (Config, []string) { func applyDeprecatedConfig(d *decodeTarget) (Config, []string) {
@ -97,6 +99,13 @@ func applyDeprecatedConfig(d *decodeTarget) (Config, []string) {
warns = append(warns, deprecationWarning("acl_down_policy", "acl.down_policy")) warns = append(warns, deprecationWarning("acl_down_policy", "acl.down_policy"))
} }
if dep.ACLTTL != nil {
if d.Config.ACL.TokenTTL == nil {
d.Config.ACL.TokenTTL = dep.ACLTTL
}
warns = append(warns, deprecationWarning("acl_ttl", "acl.token_ttl"))
}
return d.Config, warns return d.Config, warns
} }

View File

@ -3,6 +3,7 @@ package config
import ( import (
"sort" "sort"
"testing" "testing"
"time"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -24,6 +25,8 @@ acl_replication_token = "token5"
acl_default_policy = "deny" acl_default_policy = "deny"
acl_down_policy = "async-cache" acl_down_policy = "async-cache"
acl_ttl = "3h"
`}, `},
} }
patchLoadOptsShims(&opts) patchLoadOptsShims(&opts)
@ -39,6 +42,7 @@ acl_down_policy = "async-cache"
deprecationWarning("acl_master_token", "acl.tokens.master"), deprecationWarning("acl_master_token", "acl.tokens.master"),
deprecationWarning("acl_replication_token", "acl.tokens.replication"), deprecationWarning("acl_replication_token", "acl.tokens.replication"),
deprecationWarning("acl_token", "acl.tokens.default"), deprecationWarning("acl_token", "acl.tokens.default"),
deprecationWarning("acl_ttl", "acl.token_ttl"),
} }
sort.Strings(result.Warnings) sort.Strings(result.Warnings)
require.Equal(t, expectWarns, result.Warnings) require.Equal(t, expectWarns, result.Warnings)
@ -56,6 +60,7 @@ acl_down_policy = "async-cache"
require.Equal(t, "token5", rt.ACLTokens.ACLReplicationToken) require.Equal(t, "token5", rt.ACLTokens.ACLReplicationToken)
require.Equal(t, "deny", rt.ACLResolverSettings.ACLDefaultPolicy) require.Equal(t, "deny", rt.ACLResolverSettings.ACLDefaultPolicy)
require.Equal(t, "async-cache", rt.ACLResolverSettings.ACLDownPolicy) require.Equal(t, "async-cache", rt.ACLResolverSettings.ACLDownPolicy)
require.Equal(t, 3*time.Hour, rt.ACLResolverSettings.ACLTokenTTL)
} }
func TestLoad_DeprecatedConfig_ACLReplication(t *testing.T) { func TestLoad_DeprecatedConfig_ACLReplication(t *testing.T) {

View File

@ -5923,6 +5923,7 @@ func TestLoad_FullConfig(t *testing.T) {
deprecationWarning("enable_acl_replication", "acl.enable_token_replication"), deprecationWarning("enable_acl_replication", "acl.enable_token_replication"),
deprecationWarning("acl_default_policy", "acl.default_policy"), deprecationWarning("acl_default_policy", "acl.default_policy"),
deprecationWarning("acl_down_policy", "acl.down_policy"), deprecationWarning("acl_down_policy", "acl.down_policy"),
deprecationWarning("acl_ttl", "acl.token_ttl"),
`bootstrap_expect > 0: expecting 53 servers`, `bootstrap_expect > 0: expecting 53 servers`,
} }
expectedWarns = append(expectedWarns, enterpriseConfigKeyWarnings...) expectedWarns = append(expectedWarns, enterpriseConfigKeyWarnings...)