/
interface.go
76 lines (65 loc) · 1.86 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
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package charmrevisionupdater
import (
"github.com/juju/charm/v12"
"github.com/juju/errors"
"github.com/juju/names/v5"
"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/cloud"
"github.com/juju/juju/environs/config"
"github.com/juju/juju/state"
)
// State is the subset of *state.State that we need.
type State interface {
AddCharmPlaceholder(curl *charm.URL) error
AllApplications() ([]Application, error)
Charm(curl string) (*state.Charm, error)
Cloud(name string) (cloud.Cloud, error)
ControllerUUID() string
Model() (Model, error)
Resources() state.Resources
AliveRelationKeys() []string
}
// Application is the subset of *state.Application that we need.
type Application interface {
CharmURL() (curl *string, force bool)
CharmOrigin() *state.CharmOrigin
ApplicationTag() names.ApplicationTag
UnitCount() int
}
// Model is the subset of *state.Model that we need.
type Model interface {
CloudName() string
CloudRegion() string
Config() (*config.Config, error)
IsControllerModel() bool
Metrics() (state.ModelMetrics, error)
ModelTag() names.ModelTag
UUID() string
}
// StateShim takes a *state.State and implements this package's State interface.
type StateShim struct {
*state.State
}
func (s StateShim) AllApplications() ([]Application, error) {
stateApps, err := s.State.AllApplications()
if err != nil {
return nil, errors.Trace(err)
}
apps := make([]Application, len(stateApps))
for i, a := range stateApps {
apps[i] = a
}
return apps, nil
}
func (s StateShim) Model() (Model, error) {
return s.State.Model()
}
// charmhubClientStateShim takes a *state.State and implements common.ModelGetter.
type charmhubClientStateShim struct {
state State
}
func (s charmhubClientStateShim) Model() (common.ConfigModel, error) {
return s.state.Model()
}