-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
methods.go
103 lines (84 loc) · 3.9 KB
/
methods.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
/*
Copyright 2023 Avi Zimmerman <avi.zimmerman@gmail.com>
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
http://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 leaderproxy
import (
v1 "github.com/webmeshproj/api/v1"
)
// MethodPolicy defines the policy for routing requests to the leader.
type MethodPolicy int
const (
// RequireLeader requires that the request is routed to the leader.
RequireLeader MethodPolicy = iota
// AllowNonLeader allows the request to be routed to a non-leader.
AllowNonLeader
// RequireLocal requires that the request is routed to the local node.
RequireLocal
)
// RouteRequiresInNetworkSource returns true if the given route requires that the
// request is routed from a peer in the network.
func RouteRequiresInNetworkSource(route string) bool {
return route == v1.Membership_Update_FullMethodName ||
route == v1.Membership_Leave_FullMethodName ||
route == v1.Membership_Apply_FullMethodName ||
route == v1.Membership_SubscribePeers_FullMethodName ||
route == v1.Membership_GetRaftConfiguration_FullMethodName ||
route == v1.Node_NegotiateDataChannel_FullMethodName
}
// MethodPolicyMap is a map of method names to their MethodPolicy.
var MethodPolicyMap = map[string]MethodPolicy{
// Membership API
v1.Membership_Join_FullMethodName: RequireLeader,
v1.Membership_Update_FullMethodName: RequireLeader,
v1.Membership_Leave_FullMethodName: RequireLeader,
v1.Membership_Apply_FullMethodName: RequireLeader,
v1.Membership_SubscribePeers_FullMethodName: AllowNonLeader,
v1.Membership_GetRaftConfiguration_FullMethodName: AllowNonLeader,
// Node API
v1.Node_GetStatus_FullMethodName: RequireLocal,
v1.Node_NegotiateDataChannel_FullMethodName: RequireLocal,
// Storage API
v1.Storage_Query_FullMethodName: AllowNonLeader,
v1.Storage_Publish_FullMethodName: AllowNonLeader,
v1.Storage_Subscribe_FullMethodName: RequireLocal,
// Mesh API
v1.Mesh_GetNode_FullMethodName: AllowNonLeader,
v1.Mesh_ListNodes_FullMethodName: AllowNonLeader,
v1.Mesh_GetMeshGraph_FullMethodName: AllowNonLeader,
// WebRTC API
v1.WebRTC_StartDataChannel_FullMethodName: AllowNonLeader,
// Admin API
v1.Admin_PutRole_FullMethodName: RequireLeader,
v1.Admin_DeleteRole_FullMethodName: RequireLeader,
v1.Admin_GetRole_FullMethodName: AllowNonLeader,
v1.Admin_ListRoles_FullMethodName: AllowNonLeader,
v1.Admin_PutRoleBinding_FullMethodName: RequireLeader,
v1.Admin_DeleteRoleBinding_FullMethodName: RequireLeader,
v1.Admin_GetRoleBinding_FullMethodName: AllowNonLeader,
v1.Admin_ListRoleBindings_FullMethodName: AllowNonLeader,
v1.Admin_PutGroup_FullMethodName: RequireLeader,
v1.Admin_DeleteGroup_FullMethodName: RequireLeader,
v1.Admin_GetGroup_FullMethodName: AllowNonLeader,
v1.Admin_ListGroups_FullMethodName: AllowNonLeader,
v1.Admin_PutNetworkACL_FullMethodName: RequireLeader,
v1.Admin_DeleteNetworkACL_FullMethodName: RequireLeader,
v1.Admin_GetNetworkACL_FullMethodName: AllowNonLeader,
v1.Admin_ListNetworkACLs_FullMethodName: AllowNonLeader,
v1.Admin_PutRoute_FullMethodName: RequireLeader,
v1.Admin_DeleteRoute_FullMethodName: RequireLeader,
v1.Admin_GetRoute_FullMethodName: AllowNonLeader,
v1.Admin_ListRoutes_FullMethodName: AllowNonLeader,
v1.Admin_PutEdge_FullMethodName: RequireLeader,
v1.Admin_DeleteEdge_FullMethodName: RequireLeader,
v1.Admin_GetEdge_FullMethodName: AllowNonLeader,
v1.Admin_ListEdges_FullMethodName: AllowNonLeader,
}