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