-
Notifications
You must be signed in to change notification settings - Fork 128
/
managers.go
135 lines (119 loc) · 5.23 KB
/
managers.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
Copyright NetFoundry Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package model
import (
"github.com/openziti/ziti/common/pb/edge_cmd_pb"
"github.com/openziti/ziti/controller/command"
"github.com/openziti/ziti/controller/network"
"google.golang.org/protobuf/proto"
)
type Managers struct {
// fabric
Router *network.RouterManager
Service *network.ServiceManager
Terminator *network.TerminatorManager
Command *network.CommandManager
// edge
ApiSession *ApiSessionManager
ApiSessionCertificate *ApiSessionCertificateManager
Ca *CaManager
Config *ConfigManager
ConfigType *ConfigTypeManager
Controller *ControllerManager
EdgeRouter *EdgeRouterManager
EdgeRouterPolicy *EdgeRouterPolicyManager
EdgeService *EdgeServiceManager
ExternalJwtSigner *ExternalJwtSignerManager
Identity *IdentityManager
IdentityType *IdentityTypeManager
PolicyAdvisor *PolicyAdvisor
ServiceEdgeRouterPolicy *ServiceEdgeRouterPolicyManager
ServicePolicy *ServicePolicyManager
Revocation *RevocationManager
TransitRouter *TransitRouterManager
Session *SessionManager
Authenticator *AuthenticatorManager
Enrollment *EnrollmentManager
PostureCheck *PostureCheckManager
PostureCheckType *PostureCheckTypeManager
PostureResponse *PostureResponseManager
Mfa *MfaManager
AuthPolicy *AuthPolicyManager
}
func InitEntityManagers(env Env) *Managers {
managers := &Managers{}
managers.Command = env.GetDbProvider().GetManagers().Command
managers.Router = env.GetDbProvider().GetManagers().Routers
managers.Service = env.GetDbProvider().GetManagers().Services
managers.Terminator = env.GetDbProvider().GetManagers().Terminators
managers.ApiSession = NewApiSessionManager(env)
managers.ApiSessionCertificate = NewApiSessionCertificateManager(env)
managers.Authenticator = NewAuthenticatorManager(env)
managers.AuthPolicy = NewAuthPolicyManager(env)
managers.Ca = NewCaManager(env)
managers.Config = NewConfigManager(env)
managers.ConfigType = NewConfigTypeManager(env)
managers.Controller = NewControllerManager(env)
managers.EdgeRouter = NewEdgeRouterManager(env)
managers.EdgeRouterPolicy = NewEdgeRouterPolicyManager(env)
managers.EdgeService = NewEdgeServiceManager(env)
managers.Enrollment = NewEnrollmentManager(env)
managers.ExternalJwtSigner = NewExternalJwtSignerManager(env)
managers.Identity = NewIdentityManager(env)
managers.IdentityType = NewIdentityTypeManager(env)
managers.PolicyAdvisor = NewPolicyAdvisor(env)
managers.Revocation = NewRevocationManager(env)
managers.ServiceEdgeRouterPolicy = NewServiceEdgeRouterPolicyManager(env)
managers.ServicePolicy = NewServicePolicyManager(env)
managers.Session = NewSessionManager(env)
managers.TransitRouter = NewTransitRouterManager(env)
managers.PostureCheck = NewPostureCheckManager(env)
managers.PostureCheckType = NewPostureCheckTypeManager(env)
managers.PostureResponse = NewPostureResponseManager(env)
managers.Mfa = NewMfaManager(env)
RegisterCommand(env, &CreateEdgeTerminatorCmd{}, &edge_cmd_pb.CreateEdgeTerminatorCommand{})
return managers
}
// decodableCommand is a Command which knows how to decode itself from the given message type
//
// T is the type of the command. We want to enforce that the command is a pointer type so we can
// use new(T) to create new instances of it
// M is the message type that the command can use to set its internals
type decodableCommand[T any, M any] interface {
command.Command
Decode(env Env, msg M) error
*T
}
// RegisterCommand register a decoder for the given command and message pair
// MT is the message type (ex: cmd_pb.CreateServiceCommand)
// CT is the command type (ex: CreateServiceCommand)
// M is the CommandMsg/command.TypedMessage implementation (ex: *cmd_pb.CreateServiceCommand)
// C is the decodableCommand/command.Command implementation (ex: *CreateServiceCommand)
//
// We only have both types specified so that we can enforce that each is a pointer type. If didn't
// enforce that the instances were pointer types, we couldn't use new to instantiate new instances.
func RegisterCommand[MT any, CT any, M network.CommandMsg[MT], C decodableCommand[CT, M]](env Env, _ C, _ M) {
decoder := func(commandType int32, data []byte) (command.Command, error) {
var msg M = new(MT)
if err := proto.Unmarshal(data, msg); err != nil {
return nil, err
}
cmd := C(new(CT))
if err := cmd.Decode(env, msg); err != nil {
return nil, err
}
return cmd, nil
}
var msg M = new(MT)
env.GetHostController().GetNetwork().Managers.Command.Decoders.RegisterF(msg.GetCommandType(), decoder)
}