/
interface.go
97 lines (79 loc) · 2.71 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 2017 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package firewaller
import (
"github.com/juju/errors"
"github.com/juju/names/v5"
"gopkg.in/macaroon.v2"
"github.com/juju/juju/apiserver/common/firewall"
"github.com/juju/juju/controller"
"github.com/juju/juju/core/network"
"github.com/juju/juju/rpc/params"
"github.com/juju/juju/state"
)
// State provides the subset of global state required by the
// remote firewaller facade.
type State interface {
firewall.State
ControllerConfig() (controller.Config, error)
IsController() bool
ModelUUID() string
GetMacaroon(entity names.Tag) (*macaroon.Macaroon, error)
WatchOpenedPorts() state.StringsWatcher
FindEntity(tag names.Tag) (state.Entity, error)
AllEndpointBindings() (map[string]map[string]string, error)
SpaceInfos() (network.SpaceInfos, error)
}
// ControllerConfigAPI provides the subset of common.ControllerConfigAPI
// required by the remote firewaller facade
type ControllerConfigAPI interface {
// ControllerConfig returns the controller's configuration.
ControllerConfig() (params.ControllerConfigResult, error)
// ControllerAPIInfoForModels returns the controller api connection details for the specified models.
ControllerAPIInfoForModels(args params.Entities) (params.ControllerAPIInfoResults, error)
}
// TODO(wallyworld) - for tests, remove when remaining firewaller tests become unit tests.
func StateShim(st *state.State, m *state.Model) stateShim {
return stateShim{st: st, State: firewall.StateShim(st, m)}
}
type stateShim struct {
firewall.State
st *state.State
}
func (st stateShim) ControllerConfig() (controller.Config, error) {
return st.st.ControllerConfig()
}
func (st stateShim) IsController() bool {
return st.st.IsController()
}
func (st stateShim) ModelUUID() string {
return st.st.ModelUUID()
}
func (st stateShim) GetMacaroon(entity names.Tag) (*macaroon.Macaroon, error) {
r := st.st.RemoteEntities()
return r.GetMacaroon(entity)
}
func (st stateShim) FindEntity(tag names.Tag) (state.Entity, error) {
return st.st.FindEntity(tag)
}
func (st stateShim) WatchOpenedPorts() state.StringsWatcher {
return st.st.WatchOpenedPorts()
}
func (st stateShim) AllEndpointBindings() (map[string]map[string]string, error) {
model, err := st.st.Model()
if err != nil {
return nil, errors.Trace(err)
}
allEndpointBindings, err := model.AllEndpointBindings()
if err != nil {
return nil, errors.Trace(err)
}
res := make(map[string]map[string]string, len(allEndpointBindings))
for appName, bindings := range allEndpointBindings {
res[appName] = bindings.Map() // endpoint -> spaceID
}
return res, nil
}
func (st stateShim) SpaceInfos() (network.SpaceInfos, error) {
return st.st.AllSpaceInfos()
}