Skip to content

Commit

Permalink
feat(firebolt): Switch to the new auth method (#8182)
Browse files Browse the repository at this point in the history
* feat(firebolt): Switch to the new auth method

* fix env test
  • Loading branch information
ptiurin committed May 15, 2024
1 parent a20f4b2 commit e559114
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 15 deletions.
11 changes: 6 additions & 5 deletions docs/pages/product/configuration/data-sources/firebolt.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ their [Help Center][firebolt-help].

## Prerequisites

- The username/password for your [Firebolt][firebolt] account
- The id/secret (client id/client secret) for your [Firebolt][firebolt] [service account][firebolt-service-accounts]

## Setup

Expand All @@ -24,7 +24,7 @@ Add the following to a `.env` file in your Cube project:

```dotenv
CUBEJS_DB_NAME=firebolt_database
CUBEJS_DB_USER=firebolt_user@customer.com
CUBEJS_DB_USER=aaaa-bbb-3244-wwssd
CUBEJS_DB_PASS=**********
CUBEJS_FIREBOLT_ACCOUNT=cube
CUBEJS_FIREBOLT_ENGINE_NAME=engine_name
Expand All @@ -35,13 +35,14 @@ CUBEJS_FIREBOLT_ENGINE_NAME=engine_name
| Environment Variable | Description | Possible Values | Required |
| ------------------------------ | ----------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | :------: |
| `CUBEJS_DB_NAME` | The name of the database to connect to | A valid database name ||
| `CUBEJS_DB_USER` | The username used to connect to the database | A valid database username ||
| `CUBEJS_DB_PASS` | The password used to connect to the database | A valid database password ||
| `CUBEJS_FIREBOLT_ACCOUNT` | Account name | An account name | - |
| `CUBEJS_DB_USER` | A service account ID for accessing Firebolt programmatically | A valid service id ||
| `CUBEJS_DB_PASS` | A service account secret for accessing Firebolt programmatically | A valid service secret ||
| `CUBEJS_FIREBOLT_ACCOUNT` | Account name | An account name | |
| `CUBEJS_FIREBOLT_ENGINE_NAME` | Engine name to connect to | A valid engine name ||
| `CUBEJS_FIREBOLT_API_ENDPOINT` | Firebolt API endpoint. Used for authentication | `api.dev.firebolt.io`, `api.staging.firebolt.io`, `api.app.firebolt.io` | - |
| `CUBEJS_CONCURRENCY` | The number of concurrent connections each queue has to the database. Default is `5` | A valid number ||
| `CUBEJS_DB_MAX_POOL` | The maximum number of concurrent database connections to pool. Default is `20` | A valid number ||

[firebolt]: https://www.firebolt.io/
[firebolt-help]: https://help.firebolt.io/
[firebolt-service-accounts]: https://docs.firebolt.io/godocs/Guides/managing-your-organization/service-accounts.html
13 changes: 13 additions & 0 deletions packages/cubejs-backend-shared/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,19 @@ const variables: Record<string, (...args: any) => any> = {
]
),

/**
* Firebolt account name.
*/
fireboltAccount: ({
dataSource
}: {
dataSource: string,
}) => (
process.env[
keyByDataSource('CUBEJS_FIREBOLT_ACCOUNT', dataSource)
]
),

/** ****************************************************************
* Hive Driver *
***************************************************************** */
Expand Down
17 changes: 17 additions & 0 deletions packages/cubejs-backend-shared/test/db_env_single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,23 @@ describe('Single datasources', () => {
expect(getEnv('fireboltEngineEndpoint', { dataSource: 'wrong' })).toBeUndefined();
});

test('getEnv("fireboltAccount")', () => {
process.env.CUBEJS_FIREBOLT_ACCOUNT = "default1";
expect(getEnv('fireboltAccount', { dataSource: 'default' })).toEqual('default1');
expect(getEnv('fireboltAccount', { dataSource: 'postgres' })).toEqual('default1');
expect(getEnv('fireboltAccount', { dataSource: 'wrong' })).toEqual('default1');

process.env.CUBEJS_FIREBOLT_ACCOUNT = "default2";
expect(getEnv('fireboltAccount', { dataSource: 'default' })).toEqual('default2');
expect(getEnv('fireboltAccount', { dataSource: 'postgres' })).toEqual('default2');
expect(getEnv('fireboltAccount', { dataSource: 'wrong' })).toEqual('default2');

delete process.env.CUBEJS_FIREBOLT_ACCOUNT;
expect(getEnv('fireboltAccount', { dataSource: 'default' })).toBeUndefined();
expect(getEnv('fireboltAccount', { dataSource: 'postgres' })).toBeUndefined();
expect(getEnv('fireboltAccount', { dataSource: 'wrong' })).toBeUndefined();
});

test('getEnv("hiveType")', () => {
process.env.CUBEJS_DB_HIVE_TYPE = 'default1';
expect(getEnv('hiveType', { dataSource: 'default' })).toEqual('default1');
Expand Down
2 changes: 1 addition & 1 deletion packages/cubejs-firebolt-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@cubejs-backend/base-driver": "^0.35.26",
"@cubejs-backend/schema-compiler": "^0.35.32",
"@cubejs-backend/shared": "^0.35.2",
"firebolt-sdk": "^0.1.14"
"firebolt-sdk": "^1.2.0"
},
"license": "Apache-2.0",
"devDependencies": {
Expand Down
14 changes: 8 additions & 6 deletions packages/cubejs-firebolt-driver/src/FireboltDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,19 @@ export class FireboltDriver extends BaseDriver implements DriverInterface {
config.dataSource ||
assertDataSource('default');

const username = getEnv('dbUser', { dataSource });
const auth = username.includes('@')
? { username, password: getEnv('dbPass', { dataSource }) }
: { client_id: username, client_secret: getEnv('dbPass', { dataSource }) };

this.config = {
readOnly: true,
apiEndpoint: getEnv('fireboltApiEndpoint', { dataSource }),
...config,
connection: {
username: getEnv('dbUser', { dataSource }),
password: getEnv('dbPass', { dataSource }),
auth,
database: getEnv('dbName', { dataSource }),
// The propery `account` is deprecated according to Firebolt SDK docs
// and will be removed in the future.
// account: <string>process.env.CUBEJS_FIREBOLT_ACCOUNT,
account: getEnv('fireboltAccount', { dataSource }),
engineName: getEnv('fireboltEngineName', { dataSource }),
// engineEndpoint was deprecated in favor of engineName + account
engineEndpoint: getEnv('fireboltEngineEndpoint', { dataSource }),
Expand Down Expand Up @@ -349,7 +351,7 @@ export class FireboltDriver extends BaseDriver implements DriverInterface {
public async release() {
if (this.connection) {
const connection = await this.connection;
connection.destroy();
await connection.destroy();
this.connection = null;
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/cubejs-firebolt-driver/test/autostart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ describe('FireboltDriver autostart', () => {
driver.connection = {
execute: jest.fn().mockRejectedValue({
status: 404
})
}),
destroy: jest.fn(),
};
driver.ensureEngineRunning = jest.fn();
tests = new DriverTests(driver, { expectStringFields: true });
Expand Down
14 changes: 12 additions & 2 deletions packages/cubejs-playground/src/shared/env-vars-db-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,19 @@ Upload a service account JSON keyfile to connect to BigQuery.<br/>Alternatively,
],
},
{
databases: [{ title: 'Firebolt', driver: 'firebolt', logo: logoFirebolt }],
databases: [
{
title: 'Firebolt',
driver: 'firebolt',
logo: logoFirebolt,
instructions: `
Specify the Firebolt Service Account <a href="https://docs.firebolt.io/godocs/Guides/managing-your-organization/service-accounts.html" target="_blank">client ID and secret.</a>
`,
},
],
settings: [
...BASE_CRED,
{ env: 'CUBEJS_DB_USER', title: 'Client ID' },
{ env: 'CUBEJS_DB_PASS', title: 'Client Secret' },
DB_NAME,
{ env: 'CUBEJS_FIREBOLT_ACCOUNT', title: 'Account' },
{ env: 'CUBEJS_FIREBOLT_ENGINE_NAME', title: 'Engine name' },
Expand Down

0 comments on commit e559114

Please sign in to comment.