/
register.go
45 lines (37 loc) · 1.24 KB
/
register.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
// Copyright 2022 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package highavailability
import (
"reflect"
"github.com/juju/errors"
apiservererrors "github.com/juju/juju/apiserver/errors"
"github.com/juju/juju/apiserver/facade"
"github.com/juju/juju/state"
)
// Register is called to expose a package of facades onto a given registry.
func Register(registry facade.FacadeRegistry) {
registry.MustRegister("HighAvailability", 2, func(ctx facade.Context) (facade.Facade, error) {
return newHighAvailabilityAPI(ctx)
}, reflect.TypeOf((*HighAvailabilityAPI)(nil)))
}
// newHighAvailabilityAPI creates a new server-side highavailability API end point.
func newHighAvailabilityAPI(ctx facade.Context) (*HighAvailabilityAPI, error) {
// Only clients can access the high availability facade.
authorizer := ctx.Auth()
if !authorizer.AuthClient() {
return nil, apiservererrors.ErrPerm
}
st := ctx.State()
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
if model.Type() == state.ModelTypeCAAS {
return nil, errors.NotSupportedf("high availability on kubernetes controllers")
}
return &HighAvailabilityAPI{
state: st,
resources: ctx.Resources(),
authorizer: authorizer,
}, nil
}