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
4 changes: 4 additions & 0 deletions packages/data-service/src/connection-secrets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('connection secrets', function () {
const newConnectionInfo = mergeSecrets(originalConnectionInfo, {
awsSessionToken: 'sessionToken',
password: 'userPassword',
sshTunnelPassword: 'password',
sshTunnelPassphrase: 'passphrase',
tlsCertificateKeyFilePassword: 'tlsCertPassword',
proxyPassword: 'bar',
Expand All @@ -81,6 +82,7 @@ describe('connection secrets', function () {
sshTunnel: {
host: 'localhost',
username: 'user',
password: 'password',
port: 22,
identityKeyPassphrase: 'passphrase',
},
Expand Down Expand Up @@ -141,6 +143,7 @@ describe('connection secrets', function () {
sshTunnel: {
host: 'localhost',
username: 'user',
password: 'password',
port: 22,
identityKeyPassphrase: 'passphrase',
},
Expand All @@ -166,6 +169,7 @@ describe('connection secrets', function () {
expect(secrets).to.be.deep.equal({
awsSessionToken: 'sessionToken',
password: 'userPassword',
sshTunnelPassword: 'password',
sshTunnelPassphrase: 'passphrase',
tlsCertificateKeyFilePassword: 'tlsCertPassword',
proxyPassword: 'bar',
Expand Down
10 changes: 10 additions & 0 deletions packages/data-service/src/connection-secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { MongoClientOptions, AuthMechanismProperties } from 'mongodb';

export interface ConnectionSecrets {
password?: string;
sshTunnelPassword?: string;
sshTunnelPassphrase?: string;
awsSessionToken?: string;
tlsCertificateKeyFilePassword?: string;
Expand Down Expand Up @@ -35,6 +36,10 @@ export function mergeSecrets(
uri.password = secrets.password;
}

if (secrets.sshTunnelPassword && connectionOptions.sshTunnel) {
connectionOptions.sshTunnel.password = secrets.sshTunnelPassword;
}

if (secrets.sshTunnelPassphrase && connectionOptions.sshTunnel) {
connectionOptions.sshTunnel.identityKeyPassphrase =
secrets.sshTunnelPassphrase;
Expand Down Expand Up @@ -89,6 +94,11 @@ export function extractSecrets(connectionInfo: Readonly<ConnectionInfo>): {
uri.password = '';
}

if (connectionOptions.sshTunnel?.password) {
secrets.sshTunnelPassword = connectionOptions.sshTunnel.password;
delete connectionOptions.sshTunnel.password;
}

if (connectionOptions.sshTunnel?.identityKeyPassphrase) {
secrets.sshTunnelPassphrase =
connectionOptions.sshTunnel.identityKeyPassphrase;
Expand Down