github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/environs/config/source.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package config 5 6 import ( 7 "github.com/juju/schema" 8 ) 9 10 // These constants define named sources of model config attributes. 11 // After a call to UpdateModelConfig, any attributes added/removed 12 // will have a source of JujuModelConfigSource. 13 const ( 14 // JujuDefaultSource is used to label model config attributes that 15 // come from hard coded defaults. 16 JujuDefaultSource = "default" 17 18 // JujuControllerSource is used to label model config attributes that 19 // come from those associated with the controller. 20 JujuControllerSource = "controller" 21 22 // JujuRegionSource is used to label model config attributes that come from 23 // those associated with the region where the model is 24 // running. 25 JujuRegionSource = "region" 26 27 // JujuModelConfigSource is used to label model config attributes that 28 // have been explicitly set by the user. 29 JujuModelConfigSource = "model" 30 ) 31 32 // ConfigValue encapsulates a configuration 33 // value and its source. 34 type ConfigValue struct { 35 // Value is the configuration value. 36 Value interface{} 37 38 // Source is the name of the inherited config 39 // source from where the value originates. 40 Source string 41 } 42 43 // ConfigValues is a map of configuration values keyed by attribute name. 44 type ConfigValues map[string]ConfigValue 45 46 // AllAttrs returns just the attribute values from the config. 47 func (c ConfigValues) AllAttrs() map[string]interface{} { 48 result := make(map[string]interface{}) 49 for attr, val := range c { 50 result[attr] = val 51 } 52 return result 53 } 54 55 // ConfigSchemaSource instances provide information on config attributes 56 // and the default attribute values. 57 type ConfigSchemaSource interface { 58 // ConfigSchema returns extra config attributes specific 59 // to this provider only. 60 ConfigSchema() schema.Fields 61 62 // ConfigDefaults returns the default values for the 63 // provider specific config attributes. 64 ConfigDefaults() schema.Defaults 65 } 66 67 // ModelDefaultAttributes is a map of configuration values to a list of possible 68 // values. 69 type ModelDefaultAttributes map[string]AttributeDefaultValues 70 71 // AttributeDefaultValues represents all the default values at each level for a given 72 // setting. 73 type AttributeDefaultValues struct { 74 // Default and Controller represent the values as set at those levels. 75 Default interface{} `json:"default,omitempty" yaml:"default,omitempty"` 76 Controller interface{} `json:"controller,omitempty" yaml:"controller,omitempty"` 77 // Regions is a slice of Region representing the values as set in each 78 // region. 79 Regions []RegionDefaultValue `json:"regions,omitempty" yaml:"regions,omitempty"` 80 } 81 82 // RegionDefaultValue holds the region information for each region in DefaultSetting. 83 type RegionDefaultValue struct { 84 // Name represents the region name for this specific setting. 85 Name string `json:"name" yaml:"name"` 86 // Value is the value of the setting this represents in the named region. 87 Value interface{} `json:"value" yaml:"value"` 88 }