1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
"github.com/juju/errors"
8
"github.com/juju/schema"
12
// ConfigStorageDir is the path to the directory which a
13
// machine-scoped storage source may use to contain storage
14
// artifacts. This should not be used for environment-wide
15
// storage sources, as the contents are bound to the
16
// lifetime of the machine.
18
// ConfigStorageDir is set by the storage provisioner, so
19
// should not be relied upon until a storage source is
21
ConfigStorageDir = "storage-dir"
24
// Config defines the configuration for a storage source.
28
attrs map[string]interface{}
31
var fields = schema.Fields{}
33
var configChecker = schema.FieldMap(
38
// NewConfig creates a new Config for instantiating a storage source.
39
func NewConfig(name string, provider ProviderType, attrs map[string]interface{}) (*Config, error) {
40
_, err := configChecker.Coerce(attrs, nil)
42
return nil, errors.Annotate(err, "validating common storage config")
51
// Name returns the name of a storage source. This is not necessarily unique,
52
// and should only be used for informational purposes.
53
func (c *Config) Name() string {
57
// Provider returns the name of a storage provider.
58
func (c *Config) Provider() ProviderType {
62
// Attrs returns the configuration attributes for a storage source.
63
func (c *Config) Attrs() map[string]interface{} {
67
attrs := make(map[string]interface{})
68
for k, v := range c.attrs {
74
// ValueString returns the named config attribute as a string.
75
func (c *Config) ValueString(name string) (string, bool) {
76
v, ok := c.attrs[name].(string)