mirror of
https://github.com/lancedb/lancedb.git
synced 2026-01-09 05:12:58 +00:00
allow passing api key as env var (#841)
Allow passing API key as env var:
```shell
export LANCEDB_API_KEY=sh_123...
```
with this set, apiKey argument can omitted from `connect`
```js
const db = await vectordb.connect({
uri: "db://test-proj-01-ae8343",
region: "us-east-1",
})
```
```py
db = lancedb.connect(
uri="db://test-proj-01-ae8343",
region="us-east-1",
)
```
This commit is contained in:
@@ -78,7 +78,11 @@ export interface ConnectionOptions {
|
||||
/** AWS region to connect to. Default is {@link defaultAwsRegion}. */
|
||||
awsRegion?: string
|
||||
|
||||
// API key for the remote connections
|
||||
/**
|
||||
* API key for the remote connections
|
||||
*
|
||||
* Can also be passed by setting environment variable `LANCEDB_API_KEY`
|
||||
*/
|
||||
apiKey?: string
|
||||
|
||||
/** Region to connect */
|
||||
|
||||
@@ -38,8 +38,13 @@ export class RemoteConnection implements Connection {
|
||||
if (!opts.uri.startsWith('db://')) {
|
||||
throw new Error(`Invalid remote DB URI: ${opts.uri}`)
|
||||
}
|
||||
if (opts.apiKey == null || opts.apiKey === '') {
|
||||
opts = Object.assign({}, opts, { apiKey: process.env.LANCEDB_API_KEY })
|
||||
}
|
||||
if (opts.apiKey === undefined || opts.region === undefined) {
|
||||
throw new Error('API key and region are not supported for remote connections')
|
||||
throw new Error(
|
||||
'API key and region are must be passed for remote connections. ' +
|
||||
'API key can also be set through LANCEDB_API_KEY env variable.')
|
||||
}
|
||||
|
||||
this._dbName = opts.uri.slice('db://'.length)
|
||||
|
||||
Reference in New Issue
Block a user