Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf3f038

Browse files
authored
fix: SSL fields missing in some integration metadata schemas (#123)
1 parent 412679a commit cf3f038

File tree

6 files changed

+155
-19
lines changed

6 files changed

+155
-19
lines changed

cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
"awsathena",
4141
"bijective",
4242
"Braund",
43+
"CACERTIFICATENAME",
44+
"CACERTIFICATETEXT",
4345
"cleye",
4446
"daed",
4547
"dataframe",

packages/database-integrations/src/database-integration-env-vars.test.ts

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,43 @@ describe('Database integration env variables', () => {
158158
expect(sqlAlchemyInput.url).toBe('postgresql://my-user:my-password@my-host/my-database')
159159
})
160160

161+
it('should exclude caCertificateText from env vars', () => {
162+
const { envVars, errors } = getEnvironmentVariablesForIntegrations(
163+
[
164+
{
165+
type: 'alloydb',
166+
id: 'my-alloydb',
167+
name: 'My AlloyDB Connection',
168+
metadata: {
169+
host: 'my-host',
170+
user: 'my-user',
171+
password: 'my-password',
172+
database: 'my-database',
173+
caCertificateName: 'my-ca-certificate-name',
174+
caCertificateText: 'my-ca-certificate-text',
175+
},
176+
},
177+
],
178+
{ projectRootDirectory: '/path/to/project' }
179+
)
180+
expect(errors).toHaveLength(0)
181+
182+
// Verify that caCertificateText is not in the env vars
183+
const caCertTextEnvVar = envVars.find(envVar => envVar.name === 'MY_ALLOYDB_CONNECTION_CACERTIFICATETEXT')
184+
expect(caCertTextEnvVar).toBeUndefined()
185+
186+
// Verify that caCertificateName is still included
187+
const caCertNameEnvVar = envVars.find(envVar => envVar.name === 'MY_ALLOYDB_CONNECTION_CACERTIFICATENAME')
188+
expect(caCertNameEnvVar).toBeDefined()
189+
expect(caCertNameEnvVar?.value).toBe('my-ca-certificate-name')
190+
191+
// Verify that the SQL Alchemy input uses the path, not the text
192+
const sqlAlchemyInput = getSqlAlchemyInputVar(envVars, 'my-alloydb')
193+
expect(sqlAlchemyInput.params.connect_args.sslrootcert).toBe(
194+
'/path/to/project/.deepnote/my-alloydb/my-ca-certificate-name'
195+
)
196+
})
197+
161198
it('should generate env vars for metadata', () => {
162199
const { envVars, errors } = getEnvironmentVariablesForIntegrations(
163200
[
@@ -1321,6 +1358,43 @@ describe('Database integration env variables', () => {
13211358
expect(sqlAlchemyInput.url).toBe('mysql+pymysql://my-user:my-password@my-host/my-database')
13221359
})
13231360

1361+
it('should exclude caCertificateText from env vars', () => {
1362+
const { envVars, errors } = getEnvironmentVariablesForIntegrations(
1363+
[
1364+
{
1365+
type: 'mysql',
1366+
id: 'my-mysql',
1367+
name: 'My MySQL Connection',
1368+
metadata: {
1369+
host: 'my-host',
1370+
user: 'my-user',
1371+
password: 'my-password',
1372+
database: 'my-database',
1373+
caCertificateName: 'my-ca-certificate-name',
1374+
caCertificateText: 'my-ca-certificate-text',
1375+
},
1376+
},
1377+
],
1378+
{ projectRootDirectory: '/path/to/project' }
1379+
)
1380+
expect(errors).toHaveLength(0)
1381+
1382+
// Verify that caCertificateText is not in the env vars
1383+
const caCertTextEnvVar = envVars.find(envVar => envVar.name === 'MY_MYSQL_CONNECTION_CACERTIFICATETEXT')
1384+
expect(caCertTextEnvVar).toBeUndefined()
1385+
1386+
// Verify that caCertificateName is still included
1387+
const caCertNameEnvVar = envVars.find(envVar => envVar.name === 'MY_MYSQL_CONNECTION_CACERTIFICATENAME')
1388+
expect(caCertNameEnvVar).toBeDefined()
1389+
expect(caCertNameEnvVar?.value).toBe('my-ca-certificate-name')
1390+
1391+
// Verify that the SQL Alchemy input uses the path, not the text
1392+
const sqlAlchemyInput = getSqlAlchemyInputVar(envVars, 'my-mysql')
1393+
expect(sqlAlchemyInput.params.connect_args.ssl.ca).toBe(
1394+
'/path/to/project/.deepnote/my-mysql/my-ca-certificate-name'
1395+
)
1396+
})
1397+
13241398
it('should generate env vars for metadata', () => {
13251399
const { envVars, errors } = getEnvironmentVariablesForIntegrations(
13261400
[
@@ -1666,6 +1740,43 @@ describe('Database integration env variables', () => {
16661740
expect(sqlAlchemyInput.url).toBe('postgresql://my-user:my-password@my-host/my-database')
16671741
})
16681742

1743+
it('should exclude caCertificateText from env vars', () => {
1744+
const { envVars, errors } = getEnvironmentVariablesForIntegrations(
1745+
[
1746+
{
1747+
type: 'pgsql',
1748+
id: 'my-postgres',
1749+
name: 'My PostgreSQL Connection',
1750+
metadata: {
1751+
host: 'my-host',
1752+
user: 'my-user',
1753+
password: 'my-password',
1754+
database: 'my-database',
1755+
caCertificateName: 'my-ca-certificate-name',
1756+
caCertificateText: 'my-ca-certificate-text',
1757+
},
1758+
},
1759+
],
1760+
{ projectRootDirectory: '/path/to/project' }
1761+
)
1762+
expect(errors).toHaveLength(0)
1763+
1764+
// Verify that caCertificateText is not in the env vars
1765+
const caCertTextEnvVar = envVars.find(envVar => envVar.name === 'MY_POSTGRESQL_CONNECTION_CACERTIFICATETEXT')
1766+
expect(caCertTextEnvVar).toBeUndefined()
1767+
1768+
// Verify that caCertificateName is still included
1769+
const caCertNameEnvVar = envVars.find(envVar => envVar.name === 'MY_POSTGRESQL_CONNECTION_CACERTIFICATENAME')
1770+
expect(caCertNameEnvVar).toBeDefined()
1771+
expect(caCertNameEnvVar?.value).toBe('my-ca-certificate-name')
1772+
1773+
// Verify that the SQL Alchemy input uses the path, not the text
1774+
const sqlAlchemyInput = getSqlAlchemyInputVar(envVars, 'my-postgres')
1775+
expect(sqlAlchemyInput.params.connect_args.sslrootcert).toBe(
1776+
'/path/to/project/.deepnote/my-postgres/my-ca-certificate-name'
1777+
)
1778+
})
1779+
16691780
it('should generate env vars for metadata', () => {
16701781
const { envVars, errors } = getEnvironmentVariablesForIntegrations(
16711782
[

packages/database-integrations/src/database-integration-env-vars.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,33 @@ export function getEnvironmentVariablesForIntegrations(
4343
integrations.forEach(integration => {
4444
const namePrefix = convertToEnvironmentVariableName(integration.name)
4545

46-
const envVarsForThisIntegration: Array<EnvVar> = Object.entries(integration.metadata).map(([key, rawValue]) => {
47-
const name = `${namePrefix}_${key.toUpperCase()}`
48-
const value = String(rawValue) // converts booleans to "true" or "false"
46+
const envVarsForThisIntegration: Array<EnvVar> = Object.entries(integration.metadata)
47+
.filter(([key]) => {
48+
// Filter out caCertificateText - we only provide the path, not the cert text
49+
return key !== 'caCertificateText'
50+
})
51+
.map(([key, rawValue]) => {
52+
const name = `${namePrefix}_${key.toUpperCase()}`
53+
const value = String(rawValue) // converts booleans to "true" or "false"
54+
55+
// For MongoDB, we need to inject the SSL options into the connection string.
56+
if (integration.type === 'mongodb' && integration.metadata.sslEnabled && key === 'connection_string') {
57+
return {
58+
name,
59+
value: addSslOptionsToMongoConnectionString(
60+
params.projectRootDirectory,
61+
value,
62+
integration.id,
63+
integration.metadata
64+
),
65+
}
66+
}
4967

50-
// For MongoDB, we need to inject the SSL options into the connection string.
51-
if (integration.type === 'mongodb' && integration.metadata.sslEnabled && key === 'connection_string') {
5268
return {
5369
name,
54-
value: addSslOptionsToMongoConnectionString(
55-
params.projectRootDirectory,
56-
value,
57-
integration.id,
58-
integration.metadata
59-
),
70+
value: value,
6071
}
61-
}
62-
63-
return {
64-
name,
65-
value: value,
66-
}
67-
})
72+
})
6873

6974
// NOTE: MongoDB is not a SQL integration, we only set the normal integration env variables without the SQL alchemy config.
7075
if (integration.type !== 'mongodb') {

packages/database-integrations/src/database-integration-metadata-schemas.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,9 @@ describe('SQL integration metadata schemas', () => {
760760
password: 'my-password',
761761
database: 'my-database',
762762
port: 'my-port',
763+
sslEnabled: true,
763764
caCertificateName: 'my-ca-certificate-name',
765+
caCertificateText: 'my-ca-certificate-text',
764766
})
765767

766768
expect(result.success).toBe(true)
@@ -770,7 +772,9 @@ describe('SQL integration metadata schemas', () => {
770772
password: 'my-password',
771773
database: 'my-database',
772774
port: 'my-port',
775+
sslEnabled: true,
773776
caCertificateName: 'my-ca-certificate-name',
777+
caCertificateText: 'my-ca-certificate-text',
774778
})
775779
})
776780

@@ -810,7 +814,9 @@ describe('SQL integration metadata schemas', () => {
810814
password: 'my-password',
811815
database: 'my-database',
812816
port: 'my-port',
817+
sslEnabled: true,
813818
caCertificateName: 'my-ca-certificate-name',
819+
caCertificateText: 'my-ca-certificate-text',
814820
})
815821

816822
expect(result.success).toBe(true)
@@ -820,7 +826,9 @@ describe('SQL integration metadata schemas', () => {
820826
password: 'my-password',
821827
database: 'my-database',
822828
port: 'my-port',
829+
sslEnabled: true,
823830
caCertificateName: 'my-ca-certificate-name',
831+
caCertificateText: 'my-ca-certificate-text',
824832
})
825833
})
826834

@@ -860,7 +868,9 @@ describe('SQL integration metadata schemas', () => {
860868
password: 'my-password',
861869
database: 'my-database',
862870
port: 'my-port',
871+
sslEnabled: true,
863872
caCertificateName: 'my-ca-certificate-name',
873+
caCertificateText: 'my-ca-certificate-text',
864874
})
865875

866876
expect(result.success).toBe(true)
@@ -870,7 +880,9 @@ describe('SQL integration metadata schemas', () => {
870880
password: 'my-password',
871881
database: 'my-database',
872882
port: 'my-port',
883+
sslEnabled: true,
873884
caCertificateName: 'my-ca-certificate-name',
885+
caCertificateText: 'my-ca-certificate-text',
874886
})
875887
})
876888

packages/database-integrations/src/database-integration-metadata-schemas.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,23 @@ const alloydbMetadataSchema = commonDatabaseSchema.extend({
215215

216216
const mariadbMetadataSchema = commonDatabaseSchema.extend({
217217
port: z.string().optional(),
218-
// Note: SSL is always attempted, only certificate can be specified
218+
sslEnabled: z.boolean().optional(),
219219
caCertificateName: z.string().optional(),
220+
caCertificateText: z.string().optional(),
220221
})
221222

222223
const mindsdbMetadataSchema = commonDatabaseSchema.extend({
223224
port: z.string().optional(),
225+
sslEnabled: z.boolean().optional(),
224226
caCertificateName: z.string().optional(),
227+
caCertificateText: z.string().optional(),
225228
})
226229

227230
const mysqlMetadataSchema = commonDatabaseSchema.extend({
228231
port: z.string().optional(),
232+
sslEnabled: z.boolean().optional(),
229233
caCertificateName: z.string().optional(),
234+
caCertificateText: z.string().optional(),
230235
})
231236

232237
const pgsqlMetadataSchema = commonDatabaseSchema.extend({

packages/database-integrations/src/database-integration-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const databaseIntegrationTypes = [...sqlIntegrationTypes, 'mongodb'] as c
2525
export type DatabaseIntegrationType = (typeof databaseIntegrationTypes)[number]
2626

2727
export const databaseIntegrationTypesWithSslSupport = [
28+
'alloydb',
2829
'clickhouse',
2930
'dremio',
3031
'mariadb',

0 commit comments

Comments
 (0)