Skip to content

Commit bfc9196

Browse files
authored
chore(connection-form): make TLS options a bit more reusable (#2921)
With the upcoming CSFLE work, TLS options will not just apply to the connection to the database, but also to the KMS servers used by CSFLE. Since those options are stored differently, making the TLS Certificate Authority and Client Certificate components more independent of the usage of connection strings will help with that CSFLE work.
1 parent acd5e6b commit bfc9196

File tree

3 files changed

+20
-37
lines changed

3 files changed

+20
-37
lines changed

packages/connection-form/src/components/advanced-options-tabs/tls-ssl-tab/tls-certificate-authority.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {
77
css,
88
cx,
99
} from '@mongodb-js/compass-components';
10-
import type ConnectionStringUrl from 'mongodb-connection-string-url';
11-
import type { MongoClientOptions } from 'mongodb';
1210
import {
1311
checkboxDescriptionStyles,
1412
disabledCheckboxDescriptionStyles,
@@ -21,23 +19,19 @@ const caFieldsContainer = css({
2119
});
2220

2321
function TLSCertificateAuthority({
24-
connectionStringUrl,
22+
tlsCAFile,
2523
useSystemCA,
2624
disabled,
2725
handleTlsOptionChanged,
2826
}: {
29-
connectionStringUrl: ConnectionStringUrl;
27+
tlsCAFile?: string | null;
3028
useSystemCA: boolean;
3129
disabled: boolean;
3230
handleTlsOptionChanged: (
3331
key: 'tlsCAFile' | 'useSystemCA',
3432
value: string | null
3533
) => void;
3634
}): React.ReactElement {
37-
const caFile = connectionStringUrl
38-
.typedSearchParams<MongoClientOptions>()
39-
.get('tlsCAFile');
40-
4135
return (
4236
<FormFieldContainer className={caFieldsContainer}>
4337
<FileInput
@@ -53,7 +47,7 @@ function TLSCertificateAuthority({
5347
handleTlsOptionChanged('tlsCAFile', files?.[0] ?? null);
5448
}}
5549
showFileOnNewLine
56-
values={caFile ? [caFile] : undefined}
50+
values={tlsCAFile ? [tlsCAFile] : undefined}
5751
optional
5852
/>
5953
<Checkbox

packages/connection-form/src/components/advanced-options-tabs/tls-ssl-tab/tls-client-certificate.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import React from 'react';
22
import { FileInput, TextInput, css } from '@mongodb-js/compass-components';
3-
import type ConnectionStringUrl from 'mongodb-connection-string-url';
4-
import type { MongoClientOptions } from 'mongodb';
53

64
import FormFieldContainer from '../../form-field-container';
75

@@ -10,25 +8,20 @@ const inputFieldStyles = css({
108
});
119

1210
function TLSClientCertificate({
13-
connectionStringUrl,
11+
tlsCertificateKeyFile,
12+
tlsCertificateKeyFilePassword,
1413
disabled,
1514
updateTLSClientCertificate,
1615
updateTLSClientCertificatePassword,
1716
}: {
18-
connectionStringUrl: ConnectionStringUrl;
17+
tlsCertificateKeyFile?: string | null;
18+
tlsCertificateKeyFilePassword?: string | null;
1919
disabled: boolean;
2020
updateTLSClientCertificate: (
2121
newClientCertificateKeyFile: string | null
2222
) => void;
2323
updateTLSClientCertificatePassword: (newPassword: string | null) => void;
2424
}): React.ReactElement {
25-
const typedParams =
26-
connectionStringUrl.typedSearchParams<MongoClientOptions>();
27-
const clientCertificateKeyFile = typedParams.get('tlsCertificateKeyFile');
28-
const tlsCertificateKeyFilePassword = typedParams.get(
29-
'tlsCertificateKeyFilePassword'
30-
);
31-
3225
return (
3326
<>
3427
<FormFieldContainer className={inputFieldStyles}>
@@ -41,7 +34,7 @@ function TLSClientCertificate({
4134
link={
4235
'https://docs.mongodb.com/manual/reference/connection-string/#mongodb-urioption-urioption.tlsCertificateKeyFile'
4336
}
44-
values={clientCertificateKeyFile ? [clientCertificateKeyFile] : []}
37+
values={tlsCertificateKeyFile ? [tlsCertificateKeyFile] : []}
4538
onChange={(files: string[]) => {
4639
updateTLSClientCertificate(
4740
files && files.length > 0 ? files[0] : null

packages/connection-form/src/components/advanced-options-tabs/tls-ssl-tab/tls-ssl-tab.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ function TLSTab({
104104
[updateConnectionFormField]
105105
);
106106

107+
const searchParams =
108+
connectionStringUrl.typedSearchParams<MongoClientOptions>();
107109
const tlsOptionFields: {
108110
name: TLSOptionName;
109111
description: string;
@@ -113,22 +115,18 @@ function TLSTab({
113115
name: 'tlsInsecure',
114116
description:
115117
'This includes tlsAllowInvalidHostnames and tlsAllowInvalidCertificates.',
116-
checked: connectionStringUrl.searchParams.get('tlsInsecure') === 'true',
118+
checked: searchParams.get('tlsInsecure') === 'true',
117119
},
118120
{
119121
name: 'tlsAllowInvalidHostnames',
120122
description:
121123
'Disable the validation of the hostnames in the certificate presented by the mongod/mongos instance.',
122-
checked:
123-
connectionStringUrl.searchParams.get('tlsAllowInvalidHostnames') ===
124-
'true',
124+
checked: searchParams.get('tlsAllowInvalidHostnames') === 'true',
125125
},
126126
{
127127
name: 'tlsAllowInvalidCertificates',
128128
description: 'Disable the validation of the server certificates.',
129-
checked:
130-
connectionStringUrl.searchParams.get('tlsAllowInvalidCertificates') ===
131-
'true',
129+
checked: searchParams.get('tlsAllowInvalidCertificates') === 'true',
132130
},
133131
];
134132

@@ -171,24 +169,22 @@ function TLSTab({
171169
</RadioBoxGroup>
172170
</FormFieldContainer>
173171
<TLSCertificateAuthority
174-
connectionStringUrl={connectionStringUrl}
172+
tlsCAFile={searchParams.get('tlsCAFile')}
175173
useSystemCA={!!connectionOptions.useSystemCA}
176174
disabled={tlsOptionsDisabled}
177175
handleTlsOptionChanged={handleTlsOptionChanged}
178176
/>
179177
<TLSClientCertificate
180-
connectionStringUrl={connectionStringUrl}
178+
tlsCertificateKeyFile={searchParams.get('tlsCertificateKeyFile')}
179+
tlsCertificateKeyFilePassword={searchParams.get(
180+
'tlsCertificateKeyFilePassword'
181+
)}
181182
disabled={tlsOptionsDisabled}
182183
updateTLSClientCertificate={(newCertificatePath: string | null) => {
183184
handleTlsOptionChanged('tlsCertificateKeyFile', newCertificatePath);
184185
}}
185-
updateTLSClientCertificatePassword={(
186-
newCertificatePath: string | null
187-
) => {
188-
handleTlsOptionChanged(
189-
'tlsCertificateKeyFilePassword',
190-
newCertificatePath
191-
);
186+
updateTLSClientCertificatePassword={(newPassword: string | null) => {
187+
handleTlsOptionChanged('tlsCertificateKeyFilePassword', newPassword);
192188
}}
193189
/>
194190
{tlsOptionFields.map((tlsOptionField) => (

0 commit comments

Comments
 (0)