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