-
Notifications
You must be signed in to change notification settings - Fork 491
/
facade.go
43 lines (35 loc) · 1.29 KB
/
facade.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
// Copyright 2021 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package caasmodelconfigmanager
import (
"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/apiserver/facade"
"github.com/juju/juju/rpc/params"
"github.com/juju/juju/state"
"github.com/juju/juju/state/watcher"
)
//go:generate go run go.uber.org/mock/mockgen -package mocks -destination mocks/context_mock.go github.com/juju/juju/apiserver/facade Authorizer,Context,Resources
// State provides required state for the Facade.
type State interface {
WatchControllerConfig() state.NotifyWatcher
}
// Facade allows model config manager clients to watch controller config changes and fetch controller config.
type Facade struct {
auth facade.Authorizer
resources facade.Resources
ctrlState State
controllerConfigAPI *common.ControllerConfigAPI
}
func (f *Facade) ControllerConfig() (params.ControllerConfigResult, error) {
return f.controllerConfigAPI.ControllerConfig()
}
func (f *Facade) WatchControllerConfig() (params.NotifyWatchResult, error) {
result := params.NotifyWatchResult{}
w := f.ctrlState.WatchControllerConfig()
if _, ok := <-w.Changes(); ok {
result.NotifyWatcherId = f.resources.Register(w)
} else {
return result, watcher.EnsureErr(w)
}
return result, nil
}