Skip to content

Commit 7b1f797

Browse files
authored
feat(pinot-driver): add optional oAuth headers (#8953)
1 parent 4ea0740 commit 7b1f797

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

packages/cubejs-backend-shared/src/env.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,10 @@ const variables: Record<string, (...args: any) => any> = {
16131613
]
16141614
),
16151615

1616+
/** ***************************************************************
1617+
* Presto Driver *
1618+
**************************************************************** */
1619+
16161620
/**
16171621
* Presto catalog.
16181622
*/
@@ -1626,6 +1630,23 @@ const variables: Record<string, (...args: any) => any> = {
16261630
]
16271631
),
16281632

1633+
/** ***************************************************************
1634+
* Pinot Driver *
1635+
**************************************************************** */
1636+
1637+
/**
1638+
* Pinot / Startree Auth Token
1639+
*/
1640+
pinotAuthToken: ({
1641+
dataSource,
1642+
}: {
1643+
dataSource: string,
1644+
}) => (
1645+
process.env[
1646+
keyByDataSource('CUBEJS_DB_PINOT_AUTH_TOKEN', dataSource)
1647+
]
1648+
),
1649+
16291650
/** ****************************************************************
16301651
* Cube Store Driver *
16311652
***************************************************************** */

packages/cubejs-pinot-driver/src/PinotDriver.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,19 @@ export type PinotDriverConfiguration = {
2727
host?: string;
2828
port?: string;
2929
user?: string;
30+
database?: string;
3031
basicAuth?: { user: string, password: string };
32+
authToken?: string;
3133
ssl?: string | TLSConnectionOptions;
3234
dataSource?: string;
3335
queryTimeout?: number;
3436
};
3537

38+
type AuthorizationHeaders = {
39+
Authorization: string;
40+
database?: string;
41+
};
42+
3643
type PinotResponse = {
3744
exceptions: any[],
3845
minConsumingFreshnessTimeMs: number,
@@ -92,12 +99,14 @@ export class PinotDriver extends BaseDriver implements DriverInterface {
9299
host: getEnv('dbHost', { dataSource }),
93100
port: getEnv('dbPort', { dataSource }),
94101
user: getEnv('dbUser', { dataSource }),
102+
database: getEnv('dbName', { dataSource }),
95103
basicAuth: getEnv('dbPass', { dataSource })
96104
? {
97105
user: getEnv('dbUser', { dataSource }),
98106
password: getEnv('dbPass', { dataSource }),
99107
}
100108
: undefined,
109+
authToken: getEnv('pinotAuthToken', { dataSource }),
101110
ssl: this.getSslOptions(dataSource),
102111
queryTimeout: getEnv('dbQueryTimeout', { dataSource }),
103112
...config
@@ -127,7 +136,17 @@ export class PinotDriver extends BaseDriver implements DriverInterface {
127136
} : value)));
128137
}
129138

130-
public authorizationHeaders(): { Authorization?: string } {
139+
public authorizationHeaders(): AuthorizationHeaders | {} {
140+
if (this.config.authToken) {
141+
const res: AuthorizationHeaders = { Authorization: `Bearer ${this.config.authToken}` };
142+
143+
if (this.config.database) {
144+
res.database = this.config.database;
145+
}
146+
147+
return res;
148+
}
149+
131150
if (!this.config.basicAuth) {
132151
return {};
133152
}

0 commit comments

Comments
 (0)