Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions web/packages/teleterm/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ import {
PtyEventStartError,
PtyServerEvent,
} from 'teleterm/sharedProcess/api/protogen/ptyHostService_pb';
import {
ReloginRequest,
SendNotificationRequest,
CannotProxyGatewayConnection,
GatewayCertExpired,
} from 'teleterm/services/tshdEvents';

export function resourceOneOfIsServer(
resource: PaginatedResource['resource']
Expand Down Expand Up @@ -107,6 +113,7 @@ export function ptyEventOneOfIsExit(
} {
return event.oneofKind === 'exit';
}

export function ptyEventOneOfIsStartError(
event: PtyClientEvent['event'] | PtyServerEvent['event']
): event is {
Expand All @@ -116,6 +123,24 @@ export function ptyEventOneOfIsStartError(
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 {
Expand Down
6 changes: 1 addition & 5 deletions web/packages/teleterm/src/services/tshdEvents/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,18 @@ import { filterSensitiveProperties } from 'teleterm/services/tshd/interceptors';

export interface ReloginRequest extends api.ReloginRequest {
rootClusterUri: uri.RootClusterUri;
gatewayCertExpired?: GatewayCertExpired;
}
export interface GatewayCertExpired extends api.GatewayCertExpired {
gatewayUri: uri.GatewayUri;
targetUri: uri.DatabaseUri;
}

export interface SendNotificationRequest extends api.SendNotificationRequest {
cannotProxyGatewayConnection?: CannotProxyGatewayConnection;
}
export type SendNotificationRequest = api.SendNotificationRequest;
export interface CannotProxyGatewayConnection
extends api.CannotProxyGatewayConnection {
gatewayUri: uri.GatewayUri;
targetUri: uri.DatabaseUri;
}

export type PromptMfaRequest = api.PromptMFARequest & {
rootClusterUri: uri.RootClusterUri;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
ClusterConnectReason,
} from 'teleterm/ui/services/modals';
import { ClustersService } from 'teleterm/ui/services/clusters';
import { reloginReasonOneOfIsGatewayCertExpired } from 'teleterm/helpers';

export class ReloginService {
constructor(
Expand All @@ -38,13 +39,13 @@ export class ReloginService {
this.mainProcessClient.forceFocusWindow();
let reason: ClusterConnectReason;

if (request.gatewayCertExpired) {
if (reloginReasonOneOfIsGatewayCertExpired(request.reason)) {
const gateway = this.clustersService.findGateway(
request.gatewayCertExpired.gatewayUri
request.reason.gatewayCertExpired.gatewayUri
);
reason = {
kind: 'reason.gateway-cert-expired',
targetUri: request.gatewayCertExpired.targetUri,
targetUri: request.reason.gatewayCertExpired.targetUri,
gateway: gateway,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { SendNotificationRequest } from 'teleterm/services/tshdEvents';
import { ClustersService } from 'teleterm/ui/services/clusters';
import { NotificationsService } from 'teleterm/ui/services/notifications';
import { routing } from 'teleterm/ui/uri';
import { notificationRequestOneOfIsCannotProxyGatewayConnection } from 'teleterm/helpers';

export class TshdNotificationsService {
constructor(
Expand All @@ -29,9 +30,11 @@ export class TshdNotificationsService {
) {}

sendNotification(request: SendNotificationRequest) {
if (request.cannotProxyGatewayConnection) {
if (
notificationRequestOneOfIsCannotProxyGatewayConnection(request.subject)
) {
const { gatewayUri, targetUri, error } =
request.cannotProxyGatewayConnection;
request.subject.cannotProxyGatewayConnection;
const gateway = this.clustersService.findGateway(gatewayUri);
const clusterName = routing.parseClusterName(targetUri);
let targetName: string;
Expand Down