|
| 1 | +# Function: generateDatabaseCredential() |
| 2 | + |
| 3 | +```ts |
| 4 | +function generateDatabaseCredential(workspaceClient: WorkspaceClient, request: GenerateDatabaseCredentialRequest): Promise<DatabaseCredential>; |
| 5 | +``` |
| 6 | + |
| 7 | +Generate OAuth credentials for Postgres database connection using the proper Postgres API. |
| 8 | + |
| 9 | +This generates a time-limited OAuth token (expires after 1 hour) that can be used |
| 10 | +as a password when connecting to Lakebase Postgres databases. |
| 11 | + |
| 12 | +## Parameters |
| 13 | + |
| 14 | +| Parameter | Type | Description | |
| 15 | +| ------ | ------ | ------ | |
| 16 | +| `workspaceClient` | `WorkspaceClient` | Databricks workspace client for authentication | |
| 17 | +| `request` | [`GenerateDatabaseCredentialRequest`](Interface.GenerateDatabaseCredentialRequest.md) | Request parameters including endpoint path and optional UC claims | |
| 18 | + |
| 19 | +## Returns |
| 20 | + |
| 21 | +`Promise`\<[`DatabaseCredential`](Interface.DatabaseCredential.md)\> |
| 22 | + |
| 23 | +Database credentials with OAuth token and expiration time |
| 24 | + |
| 25 | +## See |
| 26 | + |
| 27 | +https://docs.databricks.com/aws/en/oltp/projects/authentication |
| 28 | + |
| 29 | +## Examples |
| 30 | + |
| 31 | +```typescript |
| 32 | +// Format: projects/{project-id}/branches/{branch-id}/endpoints/{endpoint-id} |
| 33 | +// Note: Use actual IDs from Databricks (project-id is a UUID) |
| 34 | +const credential = await generateDatabaseCredential(workspaceClient, { |
| 35 | + endpoint: "projects/6bef4151-4b5d-4147-b4d0-c2f4fd5b40db/branches/br-sparkling-tree-y17uj7fn/endpoints/ep-restless-pine-y1ldaht0" |
| 36 | +}); |
| 37 | + |
| 38 | +// Use credential.token as password |
| 39 | +const conn = await pg.connect({ |
| 40 | + host: "ep-abc123.database.us-east-1.databricks.com", |
| 41 | + user: "user@example.com", |
| 42 | + password: credential.token |
| 43 | +}); |
| 44 | +``` |
| 45 | + |
| 46 | +```typescript |
| 47 | +// Format: projects/{project-id}/branches/{branch-id}/endpoints/{endpoint-id} |
| 48 | +const credential = await generateDatabaseCredential(workspaceClient, { |
| 49 | + endpoint: "projects/6bef4151-4b5d-4147-b4d0-c2f4fd5b40db/branches/br-sparkling-tree-y17uj7fn/endpoints/ep-restless-pine-y1ldaht0", |
| 50 | + claims: [{ |
| 51 | + permission_set: RequestedClaimsPermissionSet.READ_ONLY, |
| 52 | + resources: [{ table_name: "catalog.schema.users" }] |
| 53 | + }] |
| 54 | +}); |
| 55 | +``` |
0 commit comments