Skip to content

Commit bf09dae

Browse files
authored
refactor(cubesql): Use corresponding name for checkSqlAuth (#9372)
To protect a situation with name collisions, I renamed functions used as checkSqlAuth to checkSqlAuth instead of checkAuth.
1 parent 3a2f4ac commit bf09dae

File tree

5 files changed

+27
-28
lines changed

5 files changed

+27
-28
lines changed

packages/cubejs-api-gateway/src/sql-server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,9 @@ export class SQLServer {
107107
this.sqlInterfaceInstance = await registerInterface({
108108
gatewayPort: this.gatewayPort,
109109
pgPort: options.pgSqlPort,
110-
checkAuth: async ({ request, user, password }) => {
110+
checkSqlAuth: async ({ request, user, password }) => {
111111
const { password: returnedPassword, superuser, securityContext, skipPasswordCheck } = await checkSqlAuth(request, user, password);
112112

113-
// Strip securityContext to improve speed deserialization
114113
return {
115114
password: returnedPassword,
116115
superuser: superuser || false,

packages/cubejs-backend-native/js/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export interface CanSwitchUserPayload {
8888

8989
export type SQLInterfaceOptions = {
9090
pgPort?: number,
91-
checkAuth: (payload: CheckAuthPayload) => CheckAuthResponse | Promise<CheckAuthResponse>,
91+
checkSqlAuth: (payload: CheckAuthPayload) => CheckAuthResponse | Promise<CheckAuthResponse>,
9292
load: (payload: LoadPayload) => unknown | Promise<unknown>,
9393
sql: (payload: SqlPayload) => unknown | Promise<unknown>,
9494
meta: (payload: MetaPayload) => unknown | Promise<unknown>,
@@ -347,8 +347,8 @@ export const registerInterface = async (options: SQLInterfaceOptions): Promise<S
347347
throw new Error('Argument options must be an object');
348348
}
349349

350-
if (typeof options.checkAuth !== 'function') {
351-
throw new Error('options.checkAuth must be a function');
350+
if (typeof options.checkSqlAuth !== 'function') {
351+
throw new Error('options.checkSqlAuth must be a function');
352352
}
353353

354354
if (typeof options.load !== 'function') {
@@ -378,7 +378,7 @@ export const registerInterface = async (options: SQLInterfaceOptions): Promise<S
378378
const native = loadNative();
379379
return native.registerInterface({
380380
...options,
381-
checkAuth: wrapNativeFunctionWithChannelCallback(options.checkAuth),
381+
checkSqlAuth: wrapNativeFunctionWithChannelCallback(options.checkSqlAuth),
382382
load: wrapNativeFunctionWithChannelCallback(options.load),
383383
sql: wrapNativeFunctionWithChannelCallback(options.sql),
384384
meta: wrapNativeFunctionWithChannelCallback(options.meta),

packages/cubejs-backend-native/src/auth.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ use crate::channel::call_js_with_channel_as_callback;
1717
#[derive(Debug)]
1818
pub struct NodeBridgeAuthService {
1919
channel: Arc<Channel>,
20-
check_auth: Arc<Root<JsFunction>>,
20+
check_sql_auth: Arc<Root<JsFunction>>,
2121
}
2222

2323
impl NodeBridgeAuthService {
24-
pub fn new(channel: Channel, check_auth: Root<JsFunction>) -> Self {
24+
pub fn new(channel: Channel, check_sql_auth: Root<JsFunction>) -> Self {
2525
Self {
2626
channel: Arc::new(channel),
27-
check_auth: Arc::new(check_auth),
27+
check_sql_auth: Arc::new(check_sql_auth),
2828
}
2929
}
3030
}
@@ -36,14 +36,14 @@ pub struct TransportRequest {
3636
}
3737

3838
#[derive(Debug, Serialize)]
39-
struct CheckAuthRequest {
39+
struct CheckSQLAuthRequest {
4040
request: TransportRequest,
4141
user: Option<String>,
4242
password: Option<String>,
4343
}
4444

4545
#[derive(Debug, Deserialize)]
46-
struct CheckAuthResponse {
46+
struct CheckSQLAuthResponse {
4747
password: Option<String>,
4848
superuser: bool,
4949
#[serde(rename = "securityContext", skip_serializing_if = "Option::is_none")]
@@ -76,17 +76,17 @@ impl SqlAuthService for NodeBridgeAuthService {
7676

7777
let request_id = Uuid::new_v4().to_string();
7878

79-
let extra = serde_json::to_string(&CheckAuthRequest {
79+
let extra = serde_json::to_string(&CheckSQLAuthRequest {
8080
request: TransportRequest {
8181
id: format!("{}-span-1", request_id),
8282
meta: None,
8383
},
8484
user: user.clone(),
8585
password: password.clone(),
8686
})?;
87-
let response: CheckAuthResponse = call_js_with_channel_as_callback(
87+
let response: CheckSQLAuthResponse = call_js_with_channel_as_callback(
8888
self.channel.clone(),
89-
self.check_auth.clone(),
89+
self.check_sql_auth.clone(),
9090
Some(extra),
9191
)
9292
.await?;

packages/cubejs-backend-native/src/node_export.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ impl SQLInterface {
4848

4949
fn register_interface<C: NodeConfiguration>(mut cx: FunctionContext) -> JsResult<JsPromise> {
5050
let options = cx.argument::<JsObject>(0)?;
51-
let check_auth = options
52-
.get::<JsFunction, _, _>(&mut cx, "checkAuth")?
51+
let check_sql_auth = options
52+
.get::<JsFunction, _, _>(&mut cx, "checkSqlAuth")?
5353
.root(&mut cx);
5454
let transport_sql_api_load = options
5555
.get::<JsFunction, _, _>(&mut cx, "sqlApiLoad")?
@@ -101,7 +101,7 @@ fn register_interface<C: NodeConfiguration>(mut cx: FunctionContext) -> JsResult
101101
transport_sql_generator,
102102
transport_can_switch_user_for_session,
103103
);
104-
let auth_service = NodeBridgeAuthService::new(cx.channel(), check_auth);
104+
let auth_service = NodeBridgeAuthService::new(cx.channel(), check_sql_auth);
105105

106106
std::thread::spawn(move || {
107107
let config = C::new(NodeConfigurationFactoryOptions {

packages/cubejs-backend-native/test/sql.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ function interfaceMethods() {
103103
dataSourceToSqlGenerator: {},
104104
};
105105
}),
106-
checkAuth: jest.fn(async ({ request, user }) => {
107-
console.log('[js] checkAuth', {
106+
checkSqlAuth: jest.fn(async ({ request, user }) => {
107+
console.log('[js] checkSqlAuth', {
108108
request,
109109
user,
110110
});
@@ -146,7 +146,7 @@ describe('SQLInterface', () => {
146146

147147
it('SHOW FULL TABLES FROM `db`', async () => {
148148
const methods = interfaceMethods();
149-
const { checkAuth, meta } = methods;
149+
const { checkSqlAuth, meta } = methods;
150150

151151
const instance = await native.registerInterface({
152152
pgPort: 5555,
@@ -178,9 +178,9 @@ describe('SQLInterface', () => {
178178
);
179179
}
180180

181-
console.log(checkAuth.mock.calls);
182-
expect(checkAuth.mock.calls.length).toEqual(1);
183-
expect(checkAuth.mock.calls[0][0]).toEqual({
181+
console.log(checkSqlAuth.mock.calls);
182+
expect(checkSqlAuth.mock.calls.length).toEqual(1);
183+
expect(checkSqlAuth.mock.calls[0][0]).toEqual({
184184
request: {
185185
id: expect.any(String),
186186
meta: null,
@@ -195,19 +195,19 @@ describe('SQLInterface', () => {
195195
user: 'random user',
196196
password: undefined,
197197
});
198-
checkAuth.mockClear();
198+
checkSqlAuth.mockClear();
199199

200200
await testConnectionFailed({
201201
user: 'allowed_user',
202202
password: undefined,
203203
});
204-
checkAuth.mockClear();
204+
checkSqlAuth.mockClear();
205205

206206
await testConnectionFailed({
207207
user: 'allowed_user',
208208
password: 'wrong_password',
209209
});
210-
checkAuth.mockClear();
210+
checkSqlAuth.mockClear();
211211

212212
const connection = new Client({
213213
host: '127.0.0.1',
@@ -236,8 +236,8 @@ describe('SQLInterface', () => {
236236
]);
237237
}
238238

239-
expect(checkAuth.mock.calls.length).toEqual(1);
240-
expect(checkAuth.mock.calls[0][0]).toEqual({
239+
expect(checkSqlAuth.mock.calls.length).toEqual(1);
240+
expect(checkSqlAuth.mock.calls[0][0]).toEqual({
241241
request: {
242242
id: expect.any(String),
243243
meta: null,

0 commit comments

Comments
 (0)