-
Notifications
You must be signed in to change notification settings - Fork 492
/
facade.go
42 lines (36 loc) · 1.12 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
// Copyright 2023 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package lifeflag
import (
"github.com/juju/names/v5"
"github.com/juju/juju/apiserver/common"
apiservererrors "github.com/juju/juju/apiserver/errors"
"github.com/juju/juju/apiserver/facade"
"github.com/juju/juju/state"
)
// Backend represents the interface required for this facade to retried entity
// information.
type Backend interface {
state.EntityFinder
}
// NewFacade constructs a new life flag facade.
func NewFacade(backend Backend, resources facade.Resources, authorizer facade.Authorizer) (*Facade, error) {
if !authorizer.AuthUnitAgent() && authorizer.AuthApplicationAgent() {
return nil, apiservererrors.ErrPerm
}
getCanAccess := func() (common.AuthFunc, error) {
return func(tag names.Tag) bool {
return authorizer.AuthOwner(tag)
}, 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
}