forked from juju/juju
/
interface.go
97 lines (77 loc) · 3.02 KB
/
interface.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package configstore
import (
"errors"
)
var ErrEnvironInfoAlreadyExists = errors.New("environment info already exists")
// APIEndpoint holds information about an API endpoint.
type APIEndpoint struct {
// APIAddress holds a list of API addresses. It may not be
// current, and it will be empty if the environment has not been
// bootstrapped.
Addresses []string
// CACert holds the CA certificate that
// signed the API server's key.
CACert string
// EnvironUUID holds the UUID for the environment we are connecting to.
// This may be empty if the environment has not been bootstrapped.
EnvironUUID string
}
// APICredentials hold credentials for connecting to an API endpoint.
type APICredentials struct {
// User holds the name of the user to connect as.
User string
Password string
}
// Storage stores environment configuration data.
type Storage interface {
// ReadInfo reads information associated with
// the environment with the given name.
// If there is no such information, it will
// return an errors.NotFound error.
ReadInfo(envName string) (EnvironInfo, error)
// CreateInfo creates some uninitialized information associated
// with the environment with the given name.
// It return ErrAlreadyExists if the
// information has already been created.
CreateInfo(envName string) (EnvironInfo, error)
// List returns a slice of existing environment names that the Storage
// knows about.
List() ([]string, error)
}
// EnvironInfo holds information associated with an environment.
type EnvironInfo interface {
// Initialized returns whether the environment information has
// been initialized. It will return true for EnvironInfo instances
// that have been created but not written.
Initialized() bool
// BootstrapConfig returns the configuration attributes
// that an environment will be bootstrapped with.
BootstrapConfig() map[string]interface{}
// APIEndpoint returns the current API endpoint information.
APIEndpoint() APIEndpoint
// APICredentials returns the current API credentials.
APICredentials() APICredentials
// SetBootstrapConfig sets the configuration attributes
// to be used for bootstrapping.
// This method may only be called on an EnvironInfo
// obtained using ConfigStorage.CreateInfo.
SetBootstrapConfig(map[string]interface{})
// SetAPIEndpoint sets the API endpoint information
// currently associated with the environment.
SetAPIEndpoint(APIEndpoint)
// SetAPICreds sets the API credentials currently
// associated with the environment.
SetAPICredentials(APICredentials)
// Location returns the location of the source of the environment
// information in a human readable format.
Location() string
// Write writes the current information to persistent storage.
// A subsequent call to ConfigStorage.ReadInfo
// can retrieve it. After this call succeeds, Initialized will return true.
Write() error
// Destroy destroys the information associated with
// the environment.
Destroy() error
}