github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/caas/config.go (about) 1 // Copyright 2017 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package caas 5 6 import ( 7 "github.com/juju/errors" 8 "github.com/juju/schema" 9 "gopkg.in/juju/environschema.v1" 10 ) 11 12 const ( 13 // JujuExternalHostNameKey specifies the hostname of a CAAS application. 14 JujuExternalHostNameKey = "juju-external-hostname" 15 16 // JujuApplicationPath specifies the relative http path used to access a CAAS application. 17 JujuApplicationPath = "juju-application-path" 18 19 // JujuDefaultApplicationPath is the default value for juju-application-path. 20 JujuDefaultApplicationPath = "/" 21 ) 22 23 var configFields = environschema.Fields{ 24 JujuExternalHostNameKey: { 25 Description: "the external hostname of an exposed application", 26 Type: environschema.Tstring, 27 Group: environschema.EnvironGroup, 28 }, 29 JujuApplicationPath: { 30 Description: "the relative http path used to access an application", 31 Type: environschema.Tstring, 32 Group: environschema.EnvironGroup, 33 }, 34 } 35 36 // ConfigSchema returns the valid fields for a CAAS application config. 37 func ConfigSchema(providerFields environschema.Fields) (environschema.Fields, error) { 38 fields, err := configSchema(providerFields) 39 if err != nil { 40 return nil, errors.Trace(err) 41 } 42 return fields, nil 43 } 44 45 func configSchema(extra environschema.Fields) (environschema.Fields, error) { 46 fields := make(environschema.Fields) 47 for name, field := range configFields { 48 fields[name] = field 49 } 50 for name, field := range extra { 51 if _, ok := configFields[name]; ok { 52 return nil, errors.Errorf("config field %q clashes with common config", name) 53 } 54 fields[name] = field 55 } 56 return fields, nil 57 } 58 59 // ConfigDefaults returns the default values for a CAAS application config. 60 func ConfigDefaults(providerDefaults schema.Defaults) schema.Defaults { 61 defaults := schema.Defaults{ 62 JujuApplicationPath: JujuDefaultApplicationPath, 63 } 64 for key, value := range providerDefaults { 65 if value == schema.Omit { 66 continue 67 } 68 defaults[key] = value 69 } 70 return defaults 71 }