-
Notifications
You must be signed in to change notification settings - Fork 4
FEAT: Multi tenant feature #80
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
Open
bharathkeyvalue
wants to merge
23
commits into
KeyValueSoftwareSystems:development
Choose a base branch
from
bharathkeyvalue:multi-tenant-feature
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
36c2e08
FEAT: Multi-tenancy support
bharathkeyvalue 66d5966
TEST: multi-tenent test fixes
bharathkeyvalue 1e4d149
FEAT: save tenantId in execution context
bharathkeyvalue 2900db2
FEAT: add postgres rls for tenant isolation
sru-thy 67f6134
FIX: make execution context binder injectable
sru-thy 65513d8
FEAT: use new database connection per tenant
sru-thy 7572a60
FEAT: add tenant creation api
bharathkeyvalue 5e0b2a6
REFACTOR: remove tenantId in response
bharathkeyvalue 9d10fea
FEAT: modified usages of db queries to use tenant specific connection
sru-thy 001b8bb
FIX: add configurable max connection limit per tenant if needed
sru-thy ea0526f
REFACTOR: rename executionId.middleware.ts to executionContext.middle…
sru-thy 93da280
FEAT: use sepearate db users for migrations and tenant operations
sru-thy 29168b2
FIX: use dynamic connection for user permission updation
sru-thy f9c3033
FIX: use admin user for db connection setup
sru-thy f0c0d75
FEAT: add env validations for new postgres user variables
sru-thy c0ec4c5
DOCS: update README with PostgresSQL admin and tenant user setup
sru-thy d0f032c
FEAT: add tenant module
bharathkeyvalue c985e37
REFACTOR: use NestJS dependency injection in the request scope to obt…
sru-thy 12e0a8e
REFACTOR: add util function for extracting token
bharathkeyvalue 1e7837b
BLD: Add db init script for creation of tenant user and db
sru-thy cf1df66
DOC: Added description for multi tenancy support
sru-thy 6fef4da
FEAT: Handle login for multi-tenancy
bharathkeyvalue 28d64e2
DOC: Add description for env variables used for handling multi-tenanc…
bharathkeyvalue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common'; | ||
| import { ConfigService } from '@nestjs/config'; | ||
| import { GqlExecutionContext } from '@nestjs/graphql'; | ||
|
|
||
| @Injectable() | ||
| export class AuthKeyGuard implements CanActivate { | ||
| constructor(private configService: ConfigService) {} | ||
|
|
||
| canActivate(context: ExecutionContext): boolean { | ||
| const ctx = GqlExecutionContext.create(context).getContext(); | ||
| if (ctx) { | ||
| const authKeyInHeader = ctx.headers['x-api-key']; | ||
| if (authKeyInHeader) { | ||
| const secretKey = this.configService.get('AUTH_KEY') as string; | ||
| return secretKey === authKeyInHeader; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { Column } from 'typeorm'; | ||
| import BaseEntity from './base.entity'; | ||
|
|
||
| class AbstractTenantEntity extends BaseEntity { | ||
| @Column({ | ||
| type: 'uuid', | ||
| default: () => "current_setting('app.tenant_id')::uuid", | ||
| }) | ||
| public tenantId!: string; | ||
| } | ||
|
|
||
| export default AbstractTenantEntity; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a snippet in the readme how multi-tenancy is handled? And also the ways to create a tenant Postgres user.
Let's add a DB Init script in the
docker-compose.ymlfile as wellThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated in commit here