/
state.go
68 lines (56 loc) · 1.64 KB
/
state.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
// Copyright 2017 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package caasoperatorprovisioner
import (
"github.com/juju/names/v5"
"github.com/juju/juju/apiserver/common"
charmscommon "github.com/juju/juju/apiserver/common/charms"
"github.com/juju/juju/controller"
"github.com/juju/juju/environs/config"
"github.com/juju/juju/state"
)
// CAASOperatorProvisionerState provides the subset of model state
// required by the CAAS operator provisioner facade.
type CAASOperatorProvisionerState interface {
WatchApplications() state.StringsWatcher
FindEntity(tag names.Tag) (state.Entity, error)
Model() (Model, error)
Application(string) (Application, error)
}
// CAASControllerState provides the subset of controller state
// required by the CAAS operator provisioner facade.
type CAASControllerState interface {
common.APIAddressAccessor
ControllerConfig() (controller.Config, error)
StateServingInfo() (controller.StateServingInfo, error)
}
type Model interface {
UUID() string
ModelConfig() (*config.Config, error)
}
type Application interface {
Charm() (ch charmscommon.Charm, force bool, err error)
}
type stateShim struct {
*state.State
}
func (s stateShim) Model() (Model, error) {
model, err := s.State.Model()
if err != nil {
return nil, err
}
return model.CAASModel()
}
func (s stateShim) Application(name string) (Application, error) {
app, err := s.State.Application(name)
if err != nil {
return nil, err
}
return &applicationShim{app}, nil
}
type applicationShim struct {
*state.Application
}
func (a *applicationShim) Charm() (charmscommon.Charm, bool, error) {
return a.Application.Charm()
}