github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/command/agent/consul/self.go (about) 1 package consul 2 3 import ( 4 "strings" 5 6 "github.com/hashicorp/go-version" 7 ) 8 9 // Self represents the response body from Consul /v1/agent/self API endpoint. 10 // Care must always be taken to do type checks when casting, as structure could 11 // potentially change over time. 12 type Self = map[string]map[string]interface{} 13 14 func SKU(info Self) (string, bool) { 15 v, ok := info["Config"]["Version"].(string) 16 if !ok { 17 return "", ok 18 } 19 20 ver, vErr := version.NewVersion(v) 21 if vErr != nil { 22 return "", false 23 } 24 if strings.Contains(ver.Metadata(), "ent") { 25 return "ent", true 26 } 27 return "oss", true 28 } 29 30 // Namespaces returns true if the "Namespaces" feature is enabled in Consul, and 31 // false otherwise. Consul OSS will always return false, and Consul ENT will return 32 // false if the license file does not contain the necessary feature. 33 func Namespaces(info Self) bool { 34 return feature("Namespaces", info) 35 } 36 37 // feature returns whether the indicated feature is enabled by Consul and the 38 // associated License. 39 // possible values as of v1.9.5+ent: 40 // 41 // Automated Backups, Automated Upgrades, Enhanced Read Scalability, 42 // Network Segments, Redundancy Zone, Advanced Network Federation, 43 // Namespaces, SSO, Audit Logging 44 func feature(name string, info Self) bool { 45 lic, licOK := info["Stats"]["license"].(map[string]interface{}) 46 if !licOK { 47 return false 48 } 49 50 features, exists := lic["features"].(string) 51 if !exists { 52 return false 53 } 54 55 return strings.Contains(features, name) 56 }