Skip to content

Commit

Permalink
Add ability to change port for db proxy (gravitational#900)
Browse files Browse the repository at this point in the history
* Refactor `DocumentGateway`

* Update protobuf files

* Do not hide port input on reconnect

* Update port of gateway connection when doc gets updated

Co-authored-by: Rafał Cieślak <[email protected]>
  • Loading branch information
gzdunek and ravicious authored Jul 29, 2022
1 parent aa5c34e commit eb2c4a0
Show file tree
Hide file tree
Showing 18 changed files with 876 additions and 257 deletions.
6 changes: 6 additions & 0 deletions web/packages/shared/components/FieldInput/FieldInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default function FieldInput({
onKeyPress,
placeholder,
defaultValue,
min,
max,
rule = defaultRule,
type = 'text',
autoFocus = false,
Expand Down Expand Up @@ -96,6 +98,8 @@ export default function FieldInput({
hasError={hasError}
placeholder={placeholder}
value={value}
min={min}
max={max}
autoComplete={autoComplete}
onChange={onChange}
onKeyPress={onKeyPress}
Expand Down Expand Up @@ -147,6 +151,8 @@ type Props = {
onKeyPress?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
readonly?: boolean;
defaultValue?: string;
min?: number;
max?: number;
// TS: temporary handles ...styles
[key: string]: any;
};
15 changes: 15 additions & 0 deletions web/packages/teleterm/src/services/tshd/createClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,21 @@ export default function createClient(
});
});
},

async setGatewayLocalPort(gatewayUri: string, localPort: string) {
const req = new api.SetGatewayLocalPortRequest()
.setGatewayUri(gatewayUri)
.setLocalPort(localPort);
return new Promise<types.Gateway>((resolve, reject) => {
tshd.setGatewayLocalPort(req, (err, response) => {
if (err) {
reject(err);
} else {
resolve(response.toObject());
}
});
});
},
};

return client;
Expand Down
4 changes: 4 additions & 0 deletions web/packages/teleterm/src/services/tshd/fixtures/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class MockTshClient implements TshClient {
gatewayUri: string,
targetSubresourceName: string
) => Promise<Gateway>;
setGatewayLocalPort: (
gatewayUri: string,
localPort: string
) => Promise<Gateway>;

getCluster: (clusterUri: string) => Promise<Cluster>;
getAuthSettings: (clusterUri: string) => Promise<AuthSettings>;
Expand Down
4 changes: 4 additions & 0 deletions web/packages/teleterm/src/services/tshd/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export type TshClient = {
gatewayUri: string,
targetSubresourceName: string
) => Promise<Gateway>;
setGatewayLocalPort: (
gatewayUri: string,
localPort: string
) => Promise<Gateway>;

getCluster: (clusterUri: string) => Promise<Cluster>;
getAuthSettings: (clusterUri: string) => Promise<AuthSettings>;
Expand Down
17 changes: 17 additions & 0 deletions web/packages/teleterm/src/services/tshd/v1/service_grpc_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface ITerminalServiceService extends grpc.ServiceDefinition<grpc.UntypedSer
removeGateway: ITerminalServiceService_IRemoveGateway;
restartGateway: ITerminalServiceService_IRestartGateway;
setGatewayTargetSubresourceName: ITerminalServiceService_ISetGatewayTargetSubresourceName;
setGatewayLocalPort: ITerminalServiceService_ISetGatewayLocalPort;
getAuthSettings: ITerminalServiceService_IGetAuthSettings;
getCluster: ITerminalServiceService_IGetCluster;
login: ITerminalServiceService_ILogin;
Expand Down Expand Up @@ -162,6 +163,15 @@ interface ITerminalServiceService_ISetGatewayTargetSubresourceName extends grpc.
responseSerialize: grpc.serialize<v1_gateway_pb.Gateway>;
responseDeserialize: grpc.deserialize<v1_gateway_pb.Gateway>;
}
interface ITerminalServiceService_ISetGatewayLocalPort extends grpc.MethodDefinition<v1_service_pb.SetGatewayLocalPortRequest, v1_gateway_pb.Gateway> {
path: "/teleport.terminal.v1.TerminalService/SetGatewayLocalPort";
requestStream: false;
responseStream: false;
requestSerialize: grpc.serialize<v1_service_pb.SetGatewayLocalPortRequest>;
requestDeserialize: grpc.deserialize<v1_service_pb.SetGatewayLocalPortRequest>;
responseSerialize: grpc.serialize<v1_gateway_pb.Gateway>;
responseDeserialize: grpc.deserialize<v1_gateway_pb.Gateway>;
}
interface ITerminalServiceService_IGetAuthSettings extends grpc.MethodDefinition<v1_service_pb.GetAuthSettingsRequest, v1_auth_settings_pb.AuthSettings> {
path: "/teleport.terminal.v1.TerminalService/GetAuthSettings";
requestStream: false;
Expand Down Expand Up @@ -216,6 +226,7 @@ export interface ITerminalServiceServer {
removeGateway: grpc.handleUnaryCall<v1_service_pb.RemoveGatewayRequest, v1_service_pb.EmptyResponse>;
restartGateway: grpc.handleUnaryCall<v1_service_pb.RestartGatewayRequest, v1_service_pb.EmptyResponse>;
setGatewayTargetSubresourceName: grpc.handleUnaryCall<v1_service_pb.SetGatewayTargetSubresourceNameRequest, v1_gateway_pb.Gateway>;
setGatewayLocalPort: grpc.handleUnaryCall<v1_service_pb.SetGatewayLocalPortRequest, v1_gateway_pb.Gateway>;
getAuthSettings: grpc.handleUnaryCall<v1_service_pb.GetAuthSettingsRequest, v1_auth_settings_pb.AuthSettings>;
getCluster: grpc.handleUnaryCall<v1_service_pb.GetClusterRequest, v1_cluster_pb.Cluster>;
login: grpc.handleUnaryCall<v1_service_pb.LoginRequest, v1_service_pb.EmptyResponse>;
Expand Down Expand Up @@ -265,6 +276,9 @@ export interface ITerminalServiceClient {
setGatewayTargetSubresourceName(request: v1_service_pb.SetGatewayTargetSubresourceNameRequest, callback: (error: grpc.ServiceError | null, response: v1_gateway_pb.Gateway) => void): grpc.ClientUnaryCall;
setGatewayTargetSubresourceName(request: v1_service_pb.SetGatewayTargetSubresourceNameRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: v1_gateway_pb.Gateway) => void): grpc.ClientUnaryCall;
setGatewayTargetSubresourceName(request: v1_service_pb.SetGatewayTargetSubresourceNameRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: v1_gateway_pb.Gateway) => void): grpc.ClientUnaryCall;
setGatewayLocalPort(request: v1_service_pb.SetGatewayLocalPortRequest, callback: (error: grpc.ServiceError | null, response: v1_gateway_pb.Gateway) => void): grpc.ClientUnaryCall;
setGatewayLocalPort(request: v1_service_pb.SetGatewayLocalPortRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: v1_gateway_pb.Gateway) => void): grpc.ClientUnaryCall;
setGatewayLocalPort(request: v1_service_pb.SetGatewayLocalPortRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: v1_gateway_pb.Gateway) => void): grpc.ClientUnaryCall;
getAuthSettings(request: v1_service_pb.GetAuthSettingsRequest, callback: (error: grpc.ServiceError | null, response: v1_auth_settings_pb.AuthSettings) => void): grpc.ClientUnaryCall;
getAuthSettings(request: v1_service_pb.GetAuthSettingsRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: v1_auth_settings_pb.AuthSettings) => void): grpc.ClientUnaryCall;
getAuthSettings(request: v1_service_pb.GetAuthSettingsRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: v1_auth_settings_pb.AuthSettings) => void): grpc.ClientUnaryCall;
Expand Down Expand Up @@ -323,6 +337,9 @@ export class TerminalServiceClient extends grpc.Client implements ITerminalServi
public setGatewayTargetSubresourceName(request: v1_service_pb.SetGatewayTargetSubresourceNameRequest, callback: (error: grpc.ServiceError | null, response: v1_gateway_pb.Gateway) => void): grpc.ClientUnaryCall;
public setGatewayTargetSubresourceName(request: v1_service_pb.SetGatewayTargetSubresourceNameRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: v1_gateway_pb.Gateway) => void): grpc.ClientUnaryCall;
public setGatewayTargetSubresourceName(request: v1_service_pb.SetGatewayTargetSubresourceNameRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: v1_gateway_pb.Gateway) => void): grpc.ClientUnaryCall;
public setGatewayLocalPort(request: v1_service_pb.SetGatewayLocalPortRequest, callback: (error: grpc.ServiceError | null, response: v1_gateway_pb.Gateway) => void): grpc.ClientUnaryCall;
public setGatewayLocalPort(request: v1_service_pb.SetGatewayLocalPortRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: v1_gateway_pb.Gateway) => void): grpc.ClientUnaryCall;
public setGatewayLocalPort(request: v1_service_pb.SetGatewayLocalPortRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: v1_gateway_pb.Gateway) => void): grpc.ClientUnaryCall;
public getAuthSettings(request: v1_service_pb.GetAuthSettingsRequest, callback: (error: grpc.ServiceError | null, response: v1_auth_settings_pb.AuthSettings) => void): grpc.ClientUnaryCall;
public getAuthSettings(request: v1_service_pb.GetAuthSettingsRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: v1_auth_settings_pb.AuthSettings) => void): grpc.ClientUnaryCall;
public getAuthSettings(request: v1_service_pb.GetAuthSettingsRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: v1_auth_settings_pb.AuthSettings) => void): grpc.ClientUnaryCall;
Expand Down
24 changes: 24 additions & 0 deletions web/packages/teleterm/src/services/tshd/v1/service_grpc_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ function deserialize_teleport_terminal_v1_RestartGatewayRequest(buffer_arg) {
return v1_service_pb.RestartGatewayRequest.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_teleport_terminal_v1_SetGatewayLocalPortRequest(arg) {
if (!(arg instanceof v1_service_pb.SetGatewayLocalPortRequest)) {
throw new Error('Expected argument of type teleport.terminal.v1.SetGatewayLocalPortRequest');
}
return Buffer.from(arg.serializeBinary());
}

function deserialize_teleport_terminal_v1_SetGatewayLocalPortRequest(buffer_arg) {
return v1_service_pb.SetGatewayLocalPortRequest.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_teleport_terminal_v1_SetGatewayTargetSubresourceNameRequest(arg) {
if (!(arg instanceof v1_service_pb.SetGatewayTargetSubresourceNameRequest)) {
throw new Error('Expected argument of type teleport.terminal.v1.SetGatewayTargetSubresourceNameRequest');
Expand Down Expand Up @@ -522,6 +533,19 @@ setGatewayTargetSubresourceName: {
responseSerialize: serialize_teleport_terminal_v1_Gateway,
responseDeserialize: deserialize_teleport_terminal_v1_Gateway,
},
// SetGatewayLocalPort starts a new gateway on the new port, stops the old gateway and then
// assigns the URI of the old gateway to the new one. It does so without fetching a new db cert.
setGatewayLocalPort: {
path: '/teleport.terminal.v1.TerminalService/SetGatewayLocalPort',
requestStream: false,
responseStream: false,
requestType: v1_service_pb.SetGatewayLocalPortRequest,
responseType: v1_gateway_pb.Gateway,
requestSerialize: serialize_teleport_terminal_v1_SetGatewayLocalPortRequest,
requestDeserialize: deserialize_teleport_terminal_v1_SetGatewayLocalPortRequest,
responseSerialize: serialize_teleport_terminal_v1_Gateway,
responseDeserialize: deserialize_teleport_terminal_v1_Gateway,
},
// GetAuthSettings returns cluster auth settigns
getAuthSettings: {
path: '/teleport.terminal.v1.TerminalService/GetAuthSettings',
Expand Down
25 changes: 25 additions & 0 deletions web/packages/teleterm/src/services/tshd/v1/service_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,31 @@ export namespace SetGatewayTargetSubresourceNameRequest {
}
}

export class SetGatewayLocalPortRequest extends jspb.Message {
getGatewayUri(): string;
setGatewayUri(value: string): SetGatewayLocalPortRequest;

getLocalPort(): string;
setLocalPort(value: string): SetGatewayLocalPortRequest;


serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): SetGatewayLocalPortRequest.AsObject;
static toObject(includeInstance: boolean, msg: SetGatewayLocalPortRequest): SetGatewayLocalPortRequest.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: SetGatewayLocalPortRequest, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): SetGatewayLocalPortRequest;
static deserializeBinaryFromReader(message: SetGatewayLocalPortRequest, reader: jspb.BinaryReader): SetGatewayLocalPortRequest;
}

export namespace SetGatewayLocalPortRequest {
export type AsObject = {
gatewayUri: string,
localPort: string,
}
}

export class ListServersRequest extends jspb.Message {
getClusterUri(): string;
setClusterUri(value: string): ListServersRequest;
Expand Down
182 changes: 182 additions & 0 deletions web/packages/teleterm/src/services/tshd/v1/service_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ goog.exportSymbol('proto.teleport.terminal.v1.LogoutRequest', null, global);
goog.exportSymbol('proto.teleport.terminal.v1.RemoveClusterRequest', null, global);
goog.exportSymbol('proto.teleport.terminal.v1.RemoveGatewayRequest', null, global);
goog.exportSymbol('proto.teleport.terminal.v1.RestartGatewayRequest', null, global);
goog.exportSymbol('proto.teleport.terminal.v1.SetGatewayLocalPortRequest', null, global);
goog.exportSymbol('proto.teleport.terminal.v1.SetGatewayTargetSubresourceNameRequest', null, global);
/**
* Generated by JsPbCodeGenerator.
Expand Down Expand Up @@ -522,6 +523,27 @@ if (goog.DEBUG && !COMPILED) {
*/
proto.teleport.terminal.v1.SetGatewayTargetSubresourceNameRequest.displayName = 'proto.teleport.terminal.v1.SetGatewayTargetSubresourceNameRequest';
}
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
* server response, or constructed directly in Javascript. The array is used
* in place and becomes part of the constructed object. It is not cloned.
* If no data is provided, the constructed object will be empty, but still
* valid.
* @extends {jspb.Message}
* @constructor
*/
proto.teleport.terminal.v1.SetGatewayLocalPortRequest = function(opt_data) {
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
};
goog.inherits(proto.teleport.terminal.v1.SetGatewayLocalPortRequest, jspb.Message);
if (goog.DEBUG && !COMPILED) {
/**
* @public
* @override
*/
proto.teleport.terminal.v1.SetGatewayLocalPortRequest.displayName = 'proto.teleport.terminal.v1.SetGatewayLocalPortRequest';
}
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
Expand Down Expand Up @@ -3962,6 +3984,166 @@ proto.teleport.terminal.v1.SetGatewayTargetSubresourceNameRequest.prototype.setT



if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto.
* Field names that are reserved in JavaScript and will be renamed to pb_name.
* Optional fields that are not set will be set to undefined.
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
* For the list of reserved names please see:
* net/proto2/compiler/js/internal/generator.cc#kKeyword.
* @param {boolean=} opt_includeInstance Deprecated. whether to include the
* JSPB instance for transitional soy proto support:
* http://goto/soy-param-migration
* @return {!Object}
*/
proto.teleport.terminal.v1.SetGatewayLocalPortRequest.prototype.toObject = function(opt_includeInstance) {
return proto.teleport.terminal.v1.SetGatewayLocalPortRequest.toObject(opt_includeInstance, this);
};


/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Deprecated. Whether to include
* the JSPB instance for transitional soy proto support:
* http://goto/soy-param-migration
* @param {!proto.teleport.terminal.v1.SetGatewayLocalPortRequest} msg The msg instance to transform.
* @return {!Object}
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.teleport.terminal.v1.SetGatewayLocalPortRequest.toObject = function(includeInstance, msg) {
var f, obj = {
gatewayUri: jspb.Message.getFieldWithDefault(msg, 1, ""),
localPort: jspb.Message.getFieldWithDefault(msg, 2, "")
};

if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
}


/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.teleport.terminal.v1.SetGatewayLocalPortRequest}
*/
proto.teleport.terminal.v1.SetGatewayLocalPortRequest.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.teleport.terminal.v1.SetGatewayLocalPortRequest;
return proto.teleport.terminal.v1.SetGatewayLocalPortRequest.deserializeBinaryFromReader(msg, reader);
};


/**
* Deserializes binary data (in protobuf wire format) from the
* given reader into the given message object.
* @param {!proto.teleport.terminal.v1.SetGatewayLocalPortRequest} msg The message object to deserialize into.
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
* @return {!proto.teleport.terminal.v1.SetGatewayLocalPortRequest}
*/
proto.teleport.terminal.v1.SetGatewayLocalPortRequest.deserializeBinaryFromReader = function(msg, reader) {
while (reader.nextField()) {
if (reader.isEndGroup()) {
break;
}
var field = reader.getFieldNumber();
switch (field) {
case 1:
var value = /** @type {string} */ (reader.readString());
msg.setGatewayUri(value);
break;
case 2:
var value = /** @type {string} */ (reader.readString());
msg.setLocalPort(value);
break;
default:
reader.skipField();
break;
}
}
return msg;
};


/**
* Serializes the message to binary data (in protobuf wire format).
* @return {!Uint8Array}
*/
proto.teleport.terminal.v1.SetGatewayLocalPortRequest.prototype.serializeBinary = function() {
var writer = new jspb.BinaryWriter();
proto.teleport.terminal.v1.SetGatewayLocalPortRequest.serializeBinaryToWriter(this, writer);
return writer.getResultBuffer();
};


/**
* Serializes the given message to binary data (in protobuf wire
* format), writing to the given BinaryWriter.
* @param {!proto.teleport.terminal.v1.SetGatewayLocalPortRequest} message
* @param {!jspb.BinaryWriter} writer
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.teleport.terminal.v1.SetGatewayLocalPortRequest.serializeBinaryToWriter = function(message, writer) {
var f = undefined;
f = message.getGatewayUri();
if (f.length > 0) {
writer.writeString(
1,
f
);
}
f = message.getLocalPort();
if (f.length > 0) {
writer.writeString(
2,
f
);
}
};


/**
* optional string gateway_uri = 1;
* @return {string}
*/
proto.teleport.terminal.v1.SetGatewayLocalPortRequest.prototype.getGatewayUri = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
};


/**
* @param {string} value
* @return {!proto.teleport.terminal.v1.SetGatewayLocalPortRequest} returns this
*/
proto.teleport.terminal.v1.SetGatewayLocalPortRequest.prototype.setGatewayUri = function(value) {
return jspb.Message.setProto3StringField(this, 1, value);
};


/**
* optional string local_port = 2;
* @return {string}
*/
proto.teleport.terminal.v1.SetGatewayLocalPortRequest.prototype.getLocalPort = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, ""));
};


/**
* @param {string} value
* @return {!proto.teleport.terminal.v1.SetGatewayLocalPortRequest} returns this
*/
proto.teleport.terminal.v1.SetGatewayLocalPortRequest.prototype.setLocalPort = function(value) {
return jspb.Message.setProto3StringField(this, 2, value);
};





if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto.
Expand Down
Loading

0 comments on commit eb2c4a0

Please sign in to comment.