Skip to content

Commit 71d9f54

Browse files
committed
fix: update connection string validation to allow only apikey or token, and set apikey from environment if not provided
1 parent 82ee066 commit 71d9f54

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/drivers/utilities.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ export function parseconnectionstring(connectionstring: string): SQLiteCloudConf
269269
verbose: options.verbose ? parseBoolean(options.verbose) : undefined
270270
}
271271

272-
// either you use an apikey, token or username and password
273-
if (Number(!!config.apikey) + Number(!!config.token) + Number(!!(config.username || config.password)) > 1) {
274-
console.error('SQLiteCloudConnection.parseconnectionstring - choose between apikey, token or username/password')
275-
throw new SQLiteCloudError('Choose between apikey, token or username/password')
272+
// either you use an apikey or a token
273+
if (Number(!!config.apikey) + Number(!!config.token) > 1) {
274+
console.error('SQLiteCloudConnection.parseconnectionstring - choose between apikey or token')
275+
throw new SQLiteCloudError('Choose between apikey or token')
276276
}
277277

278278
const database = url.pathname.replace('/', '') // pathname is database name, remove the leading slash
@@ -392,9 +392,7 @@ export function decodeWebsocketRowsetData(
392392
return decodeBigIntMarkers(data, safeIntegerMode)
393393
}
394394

395-
const blobColumnIndexes = new Set(
396-
metadata.columns.flatMap((column, index) => (column.type && BLOB_COLUMN_TYPE_RE.test(column.type) ? [index] : []))
397-
)
395+
const blobColumnIndexes = new Set(metadata.columns.flatMap((column, index) => (column.type && BLOB_COLUMN_TYPE_RE.test(column.type) ? [index] : [])))
398396
const decodeCell = (value: any, columnIndex: number) => {
399397
if (blobTransferFormat === 'base64-blobs-v1' && blobColumnIndexes.has(columnIndex) && typeof value === 'string') {
400398
return Buffer.from(value, 'base64')

test/shared.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export function getChinookConfig(url = CHINOOK_DATABASE_URL, extraConfig?: Parti
9494
ca: SELF_SIGNED_CERTIFICATE
9595
}
9696
}
97+
if (!chinookConfig.apikey && !chinookConfig.token && CHINOOK_API_KEY) {
98+
chinookConfig.apikey = CHINOOK_API_KEY
99+
}
97100
chinookConfig.gatewayurl = GATEWAY_URL
98101
chinookConfig.timeout = 10 * 1000 // 10 seconds
99102
if (extraConfig) {

0 commit comments

Comments
 (0)