-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathpresence.go
201 lines (156 loc) · 8.38 KB
/
presence.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* Teleport
* Copyright (C) 2023 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package services
import (
"context"
"time"
"github.com/gravitational/teleport/api/client/proto"
"github.com/gravitational/teleport/api/internalutils/stream"
"github.com/gravitational/teleport/api/types"
)
// ProxyGetter is a service that gets proxies.
type ProxyGetter interface {
// GetProxies returns a list of registered proxies.
GetProxies() ([]types.Server, error)
}
// NodesGetter is a service that gets nodes.
type NodesGetter interface {
// GetNodes returns a list of registered servers.
GetNodes(ctx context.Context, namespace string) ([]types.Server, error)
}
// DatabaseServersGetter is a service that gets database servers.
type DatabaseServersGetter interface {
GetDatabaseServers(context.Context, string, ...MarshalOption) ([]types.DatabaseServer, error)
}
// AppServersGetter is a service that gets application servers.
type AppServersGetter interface {
GetApplicationServers(ctx context.Context, namespace string) ([]types.AppServer, error)
}
// NodesStreamGetter is a service that gets nodes.
type NodesStreamGetter interface {
// GetNodeStream returns a list of registered servers.
GetNodeStream(ctx context.Context, namespace string) stream.Stream[types.Server]
}
// Presence records and reports the presence of all components
// of the cluster - Nodes, Proxies and SSH nodes
type Presence interface {
// Inventory is a subset of Presence dedicated to tracking the status of all
// teleport instances independent of any specific service.
Inventory
// Semaphores is responsible for semaphore handling
types.Semaphores
// GetNode returns a node by name and namespace.
GetNode(ctx context.Context, namespace, name string) (types.Server, error)
// NodesGetter gets nodes
NodesGetter
// DeleteAllNodes deletes all nodes in a namespace.
DeleteAllNodes(ctx context.Context, namespace string) error
// DeleteNode deletes node in a namespace
DeleteNode(ctx context.Context, namespace, name string) error
// UpsertNode registers node presence, permanently if TTL is 0 or for the
// specified duration with second resolution if it's >= 1 second.
UpsertNode(ctx context.Context, server types.Server) (*types.KeepAlive, error)
// GetAuthServers returns a list of registered servers
GetAuthServers() ([]types.Server, error)
// UpsertAuthServer registers auth server presence, permanently if ttl is 0 or
// for the specified duration with second resolution if it's >= 1 second
UpsertAuthServer(ctx context.Context, server types.Server) error
// DeleteAuthServer deletes auth server by name
DeleteAuthServer(name string) error
// DeleteAllAuthServers deletes all auth servers
DeleteAllAuthServers() error
// UpsertProxy registers proxy server presence, permanently if ttl is 0 or
// for the specified duration with second resolution if it's >= 1 second
UpsertProxy(ctx context.Context, server types.Server) error
// ProxyGetter gets a list of proxies
ProxyGetter
// DeleteProxy deletes proxy by name
DeleteProxy(ctx context.Context, name string) error
// DeleteAllProxies deletes all proxies
DeleteAllProxies() error
// UpsertReverseTunnel upserts reverse tunnel entry temporarily or permanently
UpsertReverseTunnel(ctx context.Context, tunnel types.ReverseTunnel) error
// GetReverseTunnel returns reverse tunnel by name
GetReverseTunnel(ctx context.Context, name string) (types.ReverseTunnel, error)
// GetReverseTunnels returns a list of registered servers
// Deprecated: use ListReverseTunnels
GetReverseTunnels(ctx context.Context) ([]types.ReverseTunnel, error)
// DeleteReverseTunnel deletes reverse tunnel by its domain name
DeleteReverseTunnel(ctx context.Context, domainName string) error
// DeleteAllReverseTunnels deletes all reverse tunnels
DeleteAllReverseTunnels(ctx context.Context) error
// ListReverseTunnels returns a page of ReverseTunnels.
ListReverseTunnels(ctx context.Context, pageSize int, pageToken string) ([]types.ReverseTunnel, string, error)
// GetServerInfos returns a stream of ServerInfos.
GetServerInfos(ctx context.Context) stream.Stream[types.ServerInfo]
// GetServerInfo returns a ServerInfo by name.
GetServerInfo(ctx context.Context, name string) (types.ServerInfo, error)
// UpsertServerInfo upserts a ServerInfo.
UpsertServerInfo(ctx context.Context, si types.ServerInfo) error
// DeleteServerInfo deletes a ServerInfo by name.
DeleteServerInfo(ctx context.Context, name string) error
// DeleteAllServerInfos deletes all ServerInfos.
DeleteAllServerInfos(ctx context.Context) error
// GetApplicationServers returns all registered application servers.
GetApplicationServers(context.Context, string) ([]types.AppServer, error)
// UpsertApplicationServer registers an application server.
UpsertApplicationServer(context.Context, types.AppServer) (*types.KeepAlive, error)
// DeleteApplicationServer deletes specified application server.
DeleteApplicationServer(ctx context.Context, namespace, hostID, name string) error
// DeleteAllApplicationServers removes all registered application servers.
DeleteAllApplicationServers(context.Context, string) error
// GetDatabaseServers returns all registered database proxy servers.
GetDatabaseServers(context.Context, string, ...MarshalOption) ([]types.DatabaseServer, error)
// UpsertDatabaseServer creates or updates a new database proxy server.
UpsertDatabaseServer(context.Context, types.DatabaseServer) (*types.KeepAlive, error)
// DeleteDatabaseServer removes the specified database proxy server.
DeleteDatabaseServer(ctx context.Context, namespace, hostID, name string) error
// DeleteAllDatabaseServers removes all database proxy servers.
DeleteAllDatabaseServers(context.Context, string) error
// KeepAliveServer updates TTL of the server resource in the backend.
KeepAliveServer(ctx context.Context, h types.KeepAlive) error
// GetKubernetesServers returns a list of registered kubernetes servers.
GetKubernetesServers(context.Context) ([]types.KubeServer, error)
// DeleteKubernetesServer deletes a named kubernetes servers.
DeleteKubernetesServer(ctx context.Context, hostID, name string) error
// DeleteAllKubernetesServers deletes all registered kubernetes servers.
DeleteAllKubernetesServers(context.Context) error
// UpsertKubernetesServer registers an kubernetes server.
UpsertKubernetesServer(context.Context, types.KubeServer) (*types.KeepAlive, error)
// GetWindowsDesktopServices returns all registered Windows desktop services.
GetWindowsDesktopServices(context.Context) ([]types.WindowsDesktopService, error)
// GetWindowsDesktopService returns a Windows desktop service by name
GetWindowsDesktopService(ctx context.Context, name string) (types.WindowsDesktopService, error)
// UpsertWindowsDesktopService creates or updates a new Windows desktop service.
UpsertWindowsDesktopService(context.Context, types.WindowsDesktopService) (*types.KeepAlive, error)
// DeleteWindowsDesktopService removes the specified Windows desktop service.
DeleteWindowsDesktopService(ctx context.Context, name string) error
// DeleteAllWindowsDesktopServices removes all Windows desktop services.
DeleteAllWindowsDesktopServices(context.Context) error
// ListResources returns a paginated list of resources.
ListResources(ctx context.Context, req proto.ListResourcesRequest) (*types.ListResourcesResponse, error)
}
// PresenceInternal extends the Presence interface with auth-specific internal methods.
type PresenceInternal interface {
Presence
InventoryInternal
UpsertHostUserInteractionTime(ctx context.Context, name string, loginTime time.Time) error
GetHostUserInteractionTime(ctx context.Context, name string) (time.Time, error)
UpsertReverseTunnelV2(ctx context.Context, tunnel types.ReverseTunnel) (types.ReverseTunnel, error)
UpdateNode(ctx context.Context, server types.Server) (types.Server, error)
}