From 86c7b1f56df47fe780e6c95860ce1135a48b14ce Mon Sep 17 00:00:00 2001
From: Matt Keeler <mjkeeler7@gmail.com>
Date: Tue, 17 Dec 2019 10:14:04 -0500
Subject: [PATCH] OSS changes to allow for parsing the enterprise DNS config
 properly

---
 agent/config/builder.go          |  4 ++--
 agent/config/default_oss.go      | 17 ++++++++++++++---
 agent/config/runtime_oss_test.go |  6 ++++++
 agent/config/runtime_test.go     |  4 +++-
 4 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/agent/config/builder.go b/agent/config/builder.go
index b4db831ecf..a674d8b013 100644
--- a/agent/config/builder.go
+++ b/agent/config/builder.go
@@ -99,7 +99,7 @@ func NewBuilder(flags Flags) (*Builder, error) {
 
 	b := &Builder{
 		Flags: flags,
-		Head:  []Source{DefaultSource()},
+		Head:  []Source{DefaultSource(), DefaultEnterpriseSource()},
 	}
 
 	if b.boolVal(b.Flags.DevMode) {
@@ -128,7 +128,7 @@ func NewBuilder(flags Flags) (*Builder, error) {
 			Data:   s,
 		})
 	}
-	b.Tail = append(b.Tail, NonUserSource(), DefaultConsulSource(), DefaultEnterpriseSource(), DefaultVersionSource())
+	b.Tail = append(b.Tail, NonUserSource(), DefaultConsulSource(), OverrideEnterpriseSource(), DefaultVersionSource())
 	if b.boolVal(b.Flags.DevMode) {
 		b.Tail = append(b.Tail, DevConsulSource())
 	}
diff --git a/agent/config/default_oss.go b/agent/config/default_oss.go
index 13f9daa20e..1c675f3aee 100644
--- a/agent/config/default_oss.go
+++ b/agent/config/default_oss.go
@@ -2,11 +2,22 @@
 
 package config
 
-// DefaultEnterpriseSource returns the consul agent configuration for the enterprise mode.
-// This should be merged in the tail after the DefaultConsulSource.
+// DefaultEnterpriseSource returns the consul agent configuration for enterprise mode.
+// These can be overridden by the user and therefore this source should be merged in the
+// head and processed before user configuration.
 func DefaultEnterpriseSource() Source {
 	return Source{
-		Name:   "enterprise",
+		Name:   "enterprise-defaults",
+		Format: "hcl",
+		Data:   ``,
+	}
+}
+
+// OverrideEnterpriseSource returns the consul agent configuration for the enterprise mode.
+// This should be merged in the tail after the DefaultConsulSource.
+func OverrideEnterpriseSource() Source {
+	return Source{
+		Name:   "enterprise-overrides",
 		Format: "hcl",
 		Data:   ``,
 	}
diff --git a/agent/config/runtime_oss_test.go b/agent/config/runtime_oss_test.go
index a59c5f3579..7371429923 100644
--- a/agent/config/runtime_oss_test.go
+++ b/agent/config/runtime_oss_test.go
@@ -5,3 +5,9 @@ package config
 var entMetaJSON = `{}`
 
 var entRuntimeConfigSanitize = `{}`
+
+var entFullDNSJSONConfig = ``
+
+var entFullDNSHCLConfig = ``
+
+var entFullRuntimeConfig = EnterpriseRuntimeConfig{}
diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go
index de732731bc..3d23076705 100644
--- a/agent/config/runtime_test.go
+++ b/agent/config/runtime_test.go
@@ -3782,7 +3782,7 @@ func TestFullConfig(t *testing.T) {
 				},
 				"udp_answer_limit": 29909,
 				"use_cache": true,
-				"cache_max_age": "5m"
+				"cache_max_age": "5m"` + entFullDNSJSONConfig + `
 			},
 			"enable_acl_replication": true,
 			"enable_agent_tls_for_checks": true,
@@ -4382,6 +4382,7 @@ func TestFullConfig(t *testing.T) {
 				udp_answer_limit = 29909
 				use_cache = true
 				cache_max_age = "5m"
+				` + entFullDNSHCLConfig + `
 			}
 			enable_acl_replication = true
 			enable_agent_tls_for_checks = true
@@ -5484,6 +5485,7 @@ func TestFullConfig(t *testing.T) {
 				"args":       []interface{}{"dltjDJ2a", "flEa7C2d"},
 			},
 		},
+		EnterpriseRuntimeConfig: entFullRuntimeConfig,
 	}
 
 	warns := []string{
-- 
GitLab