/
facade.go
39 lines (33 loc) · 923 Bytes
/
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
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package lifeflag
import (
"github.com/juju/names"
"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/state"
)
type Backend interface {
ModelUUID() string
state.EntityFinder
}
func NewFacade(backend Backend, resources *common.Resources, authorizer common.Authorizer) (*Facade, error) {
if !authorizer.AuthModelManager() {
return nil, common.ErrPerm
}
expect := names.NewModelTag(backend.ModelUUID())
getCanAccess := func() (common.AuthFunc, error) {
return func(tag names.Tag) bool {
return tag == expect
}, nil
}
life := common.NewLifeGetter(backend, getCanAccess)
watch := common.NewAgentEntityWatcher(backend, resources, getCanAccess)
return &Facade{
LifeGetter: life,
AgentEntityWatcher: watch,
}, nil
}
type Facade struct {
*common.LifeGetter
*common.AgentEntityWatcher
}