-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
helpers.ts
223 lines (200 loc) · 6.29 KB
/
helpers.ts
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**
* 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/>.
*/
// ExcludesFalse is a method that can be used instead of [].filter(Boolean)
// this removes the false values from the array type
import { PaginatedResource } from 'gen-proto-ts/teleport/lib/teleterm/v1/service_pb';
import { Server } from 'gen-proto-ts/teleport/lib/teleterm/v1/server_pb';
import { Database } from 'gen-proto-ts/teleport/lib/teleterm/v1/database_pb';
import { App } from 'gen-proto-ts/teleport/lib/teleterm/v1/app_pb';
import { Kube } from 'gen-proto-ts/teleport/lib/teleterm/v1/kube_pb';
import * as prehog from 'gen-proto-ts/prehog/v1alpha/connect_pb';
import {
PtyClientEvent,
PtyEventData,
PtyEventExit,
PtyEventResize,
PtyEventStart,
PtyEventStartError,
PtyServerEvent,
} from 'teleterm/sharedProcess/api/protogen/ptyHostService_pb';
import {
ReloginRequest,
SendNotificationRequest,
CannotProxyGatewayConnection,
GatewayCertExpired,
} from 'teleterm/services/tshdEvents';
export function resourceOneOfIsServer(
resource: PaginatedResource['resource']
): resource is {
oneofKind: 'server';
server: Server;
} {
return resource.oneofKind === 'server';
}
export function resourceOneOfIsDatabase(
resource: PaginatedResource['resource']
): resource is {
oneofKind: 'database';
database: Database;
} {
return resource.oneofKind === 'database';
}
export function resourceOneOfIsApp(
resource: PaginatedResource['resource']
): resource is {
oneofKind: 'app';
app: App;
} {
return resource.oneofKind === 'app';
}
export function resourceOneOfIsKube(
resource: PaginatedResource['resource']
): resource is {
oneofKind: 'kube';
kube: Kube;
} {
return resource.oneofKind === 'kube';
}
export function ptyEventOneOfIsStart(
event: PtyClientEvent['event'] | PtyServerEvent['event']
): event is {
oneofKind: 'start';
start: PtyEventStart;
} {
return event.oneofKind === 'start';
}
export function ptyEventOneOfIsData(
event: PtyClientEvent['event'] | PtyServerEvent['event']
): event is {
oneofKind: 'data';
data: PtyEventData;
} {
return event.oneofKind === 'data';
}
export function ptyEventOneOfIsResize(
event: PtyClientEvent['event'] | PtyServerEvent['event']
): event is {
oneofKind: 'resize';
resize: PtyEventResize;
} {
return event.oneofKind === 'resize';
}
export function ptyEventOneOfIsExit(
event: PtyClientEvent['event'] | PtyServerEvent['event']
): event is {
oneofKind: 'exit';
exit: PtyEventExit;
} {
return event.oneofKind === 'exit';
}
export function ptyEventOneOfIsStartError(
event: PtyClientEvent['event'] | PtyServerEvent['event']
): event is {
oneofKind: 'startError';
startError: PtyEventStartError;
} {
return event.oneofKind === 'startError';
}
export function notificationRequestOneOfIsCannotProxyGatewayConnection(
subject: SendNotificationRequest['subject']
): subject is {
oneofKind: 'cannotProxyGatewayConnection';
cannotProxyGatewayConnection: CannotProxyGatewayConnection;
} {
return subject.oneofKind === 'cannotProxyGatewayConnection';
}
export function reloginReasonOneOfIsGatewayCertExpired(
reason: ReloginRequest['reason']
): reason is {
oneofKind: 'gatewayCertExpired';
gatewayCertExpired: GatewayCertExpired;
} {
return reason.oneofKind === 'gatewayCertExpired';
}
export function connectEventOneOfIsClusterLogin(
event: prehog.SubmitConnectEventRequest['event']
): event is {
oneofKind: 'clusterLogin';
clusterLogin: prehog.ConnectClusterLoginEvent;
} {
return event.oneofKind === 'clusterLogin';
}
export function connectEventOneOfIsProtocolUse(
event: prehog.SubmitConnectEventRequest['event']
): event is {
oneofKind: 'protocolUse';
protocolUse: prehog.ConnectProtocolUseEvent;
} {
return event.oneofKind === 'protocolUse';
}
export function connectEventOneOfIsAccessRequestCreate(
event: prehog.SubmitConnectEventRequest['event']
): event is {
oneofKind: 'accessRequestCreate';
accessRequestCreate: prehog.ConnectAccessRequestCreateEvent;
} {
return event.oneofKind === 'accessRequestCreate';
}
export function connectEventOneOfIsAccessRequestReview(
event: prehog.SubmitConnectEventRequest['event']
): event is {
oneofKind: 'accessRequestReview';
accessRequestReview: prehog.ConnectAccessRequestReviewEvent;
} {
return event.oneofKind === 'accessRequestReview';
}
export function connectEventOneOfIsAccessRequestAssumeRole(
event: prehog.SubmitConnectEventRequest['event']
): event is {
oneofKind: 'accessRequestAssumeRole';
accessRequestAssumeRole: prehog.ConnectAccessRequestAssumeRoleEvent;
} {
return event.oneofKind === 'accessRequestAssumeRole';
}
export function connectEventOneOfIsFileTransferRun(
event: prehog.SubmitConnectEventRequest['event']
): event is {
oneofKind: 'fileTransferRun';
fileTransferRun: prehog.ConnectFileTransferRunEvent;
} {
return event.oneofKind === 'fileTransferRun';
}
export function connectEventOneOfIsUserJobRoleUpdate(
event: prehog.SubmitConnectEventRequest['event']
): event is {
oneofKind: 'userJobRoleUpdate';
userJobRoleUpdate: prehog.ConnectUserJobRoleUpdateEvent;
} {
return event.oneofKind === 'userJobRoleUpdate';
}
export function connectEventOneOfIsConnectMyComputerSetup(
event: prehog.SubmitConnectEventRequest['event']
): event is {
oneofKind: 'connectMyComputerSetup';
connectMyComputerSetup: prehog.ConnectConnectMyComputerSetup;
} {
return event.oneofKind === 'connectMyComputerSetup';
}
export function connectEventOneOfIsConnectMyComputerAgentStart(
event: prehog.SubmitConnectEventRequest['event']
): event is {
oneofKind: 'connectMyComputerAgentStart';
connectMyComputerAgentStart: prehog.ConnectConnectMyComputerAgentStart;
} {
return event.oneofKind === 'connectMyComputerAgentStart';
}