forked from openreplay/openreplay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chalice): support OR scope
- Loading branch information
Showing
17 changed files
with
105 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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,27 @@ | ||
from cachetools import cached, TTLCache | ||
|
||
import schemas | ||
from chalicelib.utils import helper | ||
from chalicelib.utils import pg_client | ||
|
||
cache = TTLCache(maxsize=1, ttl=24 * 60 * 60) | ||
|
||
|
||
@cached(cache) | ||
def get_scope(tenant_id) -> schemas.ScopeType: | ||
with pg_client.PostgresClient() as cur: | ||
query = cur.mogrify(f"""SELECT scope | ||
FROM public.tenants;""") | ||
cur.execute(query) | ||
return helper.dict_to_camel_case(cur.fetchone())["scope"] | ||
|
||
|
||
def update_scope(tenant_id, scope: schemas.ScopeType): | ||
with pg_client.PostgresClient() as cur: | ||
query = cur.mogrify(f"""UPDATE public.tenants | ||
SET scope = %(scope)s;""", | ||
{"scope": scope}) | ||
cur.execute(query) | ||
if tenant_id in cache: | ||
cache.pop(tenant_id) | ||
return scope |
This file contains 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 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 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 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 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 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 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,30 @@ | ||
from cachetools import cached, TTLCache | ||
|
||
import schemas | ||
from chalicelib.utils import helper | ||
from chalicelib.utils import pg_client | ||
|
||
cache = TTLCache(maxsize=1, ttl=24 * 60 * 60) | ||
|
||
|
||
@cached(cache) | ||
def get_scope(tenant_id) -> schemas.ScopeType: | ||
with pg_client.PostgresClient() as cur: | ||
query = cur.mogrify(f"""SELECT scope | ||
FROM public.tenants | ||
WHERE tenant_id=%(tenant_id)s;""", | ||
{"tenant_id": tenant_id}) | ||
cur.execute(query) | ||
return helper.dict_to_camel_case(cur.fetchone())["scope"] | ||
|
||
|
||
def update_scope(tenant_id, scope: schemas.ScopeType): | ||
with pg_client.PostgresClient() as cur: | ||
query = cur.mogrify(f"""UPDATE public.tenants | ||
SET scope = %(scope)s | ||
WHERE tenant_id=%(tenant_id)s;""", | ||
{"scope": scope, "tenant_id": tenant_id}) | ||
cur.execute(query) | ||
if tenant_id in cache: | ||
cache.pop(tenant_id) | ||
return scope |
This file contains 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 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 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 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 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 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 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 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 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