Skip to content

Commit

Permalink
Revert "chore(cubejs-api-gateway): added endpoint to run sql query di…
Browse files Browse the repository at this point in the history
…rectly (#5723)" (#5784)

This reverts commit f1e25bb.
  • Loading branch information
MikeNitsenko committed Dec 9, 2022
1 parent 17ba3e2 commit f1140de
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 113 deletions.
61 changes: 0 additions & 61 deletions packages/cubejs-api-gateway/src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,6 @@ class ApiGateway {
}
}));

app.post(
`${this.basePath}/v1/sql-runner`,
jsonParser,
userMiddlewares,
async (req: Request, res: Response) => {
await this.sqlRunner({
query: req.body.query,
context: req.context!,
res: this.resToResultFn(res),
});
}
);

app.get(`${this.basePath}/v1/run-scheduled-refresh`, userMiddlewares, (async (req, res) => {
await this.runScheduledRefresh({
queryingOptions: req.query.queryingOptions,
Expand Down Expand Up @@ -1083,54 +1070,6 @@ class ApiGateway {
}
}

public async sqlRunner({ query, context, res }: QueryRequest) {
const requestStarted = new Date();
try {
if (!query) {
throw new UserError(
'A user\'s query must contain a body'
);
}

if (!(query as Record<string, any>).query) {
throw new UserError(
'A user\'s query must contain at least one query param.'
);
}

query = {
...query,
requestId: context.requestId
};

this.log(
{
type: 'Load SQL Runner Request',
query,
},
context
);

const result = await this.getAdapterApi(context).executeQuery(query);

this.log(
{
type: 'Load SQL Runner Request Success',
query,
duration: this.duration(requestStarted),
dbType: result.dbType,
},
context
);

res(result);
} catch (e) {
this.handleError({
e, context, query, res, requestStarted
});
}
}

protected createSecurityContextExtractor(options?: JWTOptions): SecurityContextExtractorFn {
if (options?.claimsNamespace) {
return (ctx: Readonly<RequestContext>) => {
Expand Down
52 changes: 0 additions & 52 deletions packages/cubejs-api-gateway/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,58 +339,6 @@ describe('API Gateway', () => {
expect(res.body.query.measures).toStrictEqual(['Foo.bar']);
});

test('post http method for sql-runner route required params', async () => {
const { app } = createApiGateway();

const res = await request(app)
.post('/cubejs-api/v1/sql-runner')
.set('Content-type', 'application/json')
.set(
'Authorization',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M'
)
.send({})
.expect(400);

expect(res.body && res.body.error).toStrictEqual('A user\'s query must contain a body');

const res2 = await request(app)
.post('/cubejs-api/v1/sql-runner')
.set('Content-type', 'application/json')
.set(
'Authorization',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M'
)
.send({ query: { query: '' } })
.expect(400);

expect(res2.body && res2.body.error).toStrictEqual(
'A user\'s query must contain at least one query param.'
);
});

test('post http method for sql-runner route', async () => {
const { app } = createApiGateway();

const query = {
query: 'SELECT * FROM Foo',
};

const res = await request(app)
.post('/cubejs-api/v1/sql-runner')
.set('Content-type', 'application/json')
.set(
'Authorization',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M'
)
.send({ query })
.expect(200);

expect(res.body.data).toStrictEqual([
{ foo__bar: 42 },
]);
});

test('meta endpoint to get schema information', async () => {
const { app } = createApiGateway();

Expand Down

0 comments on commit f1140de

Please sign in to comment.