Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPLT-1049 Provision separate DB per user #144

Merged
merged 10 commits into from
Jul 26, 2023
5 changes: 5 additions & 0 deletions .github/workflows/deploy-lambdas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
HASURA_ENDPOINT: ${{ vars.HASURA_ENDPOINT }}
HASURA_ADMIN_SECRET: ${{ secrets.HASURA_ADMIN_SECRET }}
PG_ADMIN_USER: ${{ secrets.PG_ADMIN_USER }}
PG_ADMIN_PASSWORD: ${{ secrets.PG_ADMIN_PASSWORD }}
PG_ADMIN_DATABASE: ${{ secrets.PG_ADMIN_DATABASE }}
PG_HOST: ${{ secrets.PG_HOST }}
PG_PORT: ${{ secrets.PG_PORT }}
120 changes: 90 additions & 30 deletions indexer-js-queue-handler/__snapshots__/hasura-client.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`HasuraClient adds a datasource 1`] = `
{
"args": {
"configuration": {
"connection_info": {
"database_url": {
"connection_parameters": {
"database": "morgs_near",
"host": "localhost",
"password": "password",
"port": 5432,
"username": "morgs_near",
},
},
},
},
"customization": {
"root_fields": {
"prefix": "morgs_near_",
},
"type_names": {
"prefix": "morgs_near_",
},
},
"name": "morgs_near",
},
"type": "pg_add_source",
}
`;

exports[`HasuraClient adds the specified permissions for the specified roles/table/schema 1`] = `
{
"args": [
Expand Down Expand Up @@ -152,51 +182,66 @@ exports[`HasuraClient adds the specified permissions for the specified roles/tab
}
`;

exports[`HasuraClient checks if a schema exists 1`] = `
exports[`HasuraClient checks if a schema exists within source 1`] = `
[
[
"mock-hasura-endpoint/v2/query",
{
"body": "{"type":"run_sql","args":{"sql":"SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'schema'","read_only":true,"source":"source"}}",
"headers": {
"X-Hasura-Admin-Secret": "mock-hasura-admin-secret",
},
"method": "POST",
},
],
]
`;

exports[`HasuraClient checks if datasource exists 1`] = `
{
"args": {
"read_only": true,
"source": "default",
"sql": "SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'name'",
},
"type": "run_sql",
"args": {},
"type": "export_metadata",
"version": 2,
}
`;

exports[`HasuraClient creates a schema 1`] = `
{
"args": {
"read_only": false,
"source": "default",
"sql": "CREATE schema name",
},
"type": "run_sql",
}
[
[
"mock-hasura-endpoint/v2/query",
{
"body": "{"type":"run_sql","args":{"sql":"CREATE schema schemaName","read_only":false,"source":"dbName"}}",
"headers": {
"X-Hasura-Admin-Secret": "mock-hasura-admin-secret",
},
"method": "POST",
},
],
]
`;

exports[`HasuraClient gets table names within a schema 1`] = `
{
"args": {
"read_only": true,
"source": "default",
"sql": "SELECT table_name FROM information_schema.tables WHERE table_schema = 'schema'",
"source": "source",
},
"type": "run_sql",
"type": "pg_get_source_tables",
}
`;

exports[`HasuraClient runs migrations for the specified schema 1`] = `
{
"args": {
"read_only": false,
"source": "default",
"sql": "
set schema 'schema';
CREATE TABLE blocks (height numeric)
",
},
"type": "run_sql",
}
[
[
"mock-hasura-endpoint/v2/query",
{
"body": "{"type":"run_sql","args":{"sql":"\\n set schema 'schemaName';\\n CREATE TABLE blocks (height numeric)\\n ","read_only":false,"source":"dbName"}}",
"headers": {
"X-Hasura-Admin-Secret": "mock-hasura-admin-secret",
},
"method": "POST",
},
],
]
`;

exports[`HasuraClient tracks foreign key relationships 1`] = `
Expand Down Expand Up @@ -352,3 +397,18 @@ exports[`HasuraClient tracks the specified tables for a specified schema 1`] = `
"type": "bulk",
}
`;

exports[`HasuraClient untracks the specified tables 1`] = `
[
[
"mock-hasura-endpoint/v1/metadata",
{
"body": "{"type":"pg_untrack_tables","args":{"tables":[{"table":{"schema":"schema","name":"height"},"source":"default","cascade":true},{"table":{"schema":"schema","name":"width"},"source":"default","cascade":true}]}}",
"headers": {
"X-Hasura-Admin-Secret": "mock-hasura-admin-secret",
},
"method": "POST",
},
],
]
`;
18 changes: 18 additions & 0 deletions indexer-js-queue-handler/__snapshots__/provisioner.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Provisioner provisionUserApi formats user input before executing the query 1`] = `
[
[
"CREATE DATABASE "databaseName UNION SELECT * FROM users --"",
],
[
"CREATE USER morgs_near WITH PASSWORD 'pass; DROP TABLE users;--'",
],
[
"GRANT ALL PRIVILEGES ON DATABASE "databaseName UNION SELECT * FROM users --" TO morgs_near",
],
[
"REVOKE CONNECT ON DATABASE "databaseName UNION SELECT * FROM users --" FROM PUBLIC",
],
]
`;
Loading