feat(chalice): fixed SSO

This commit is contained in:
Taha Yassine Kraiem 2022-11-07 13:10:23 +01:00
parent 1c21e01a0f
commit 197997e3d4
10 changed files with 17 additions and 14 deletions

View file

@ -1,7 +1,6 @@
# from elasticsearch import Elasticsearch, RequestsHttpConnection
from elasticsearch import Elasticsearch
from chalicelib.core import log_tools
import base64
import logging
logging.getLogger('elasticsearch').level = logging.ERROR

View file

@ -1,7 +1,7 @@
import re
from chalicelib.core import projects
from chalicelib.utils import pg_client, dev
from chalicelib.utils import pg_client
MAX_INDEXES = 10

View file

@ -23,7 +23,8 @@ def __get_saved_data(project_id, session_id, issue_id, tool):
return helper.dict_to_camel_case(cur.fetchone())
def create_new_assignment(tenant_id, project_id, session_id, creator_id, assignee, description, title, issue_type, integration_project_id):
def create_new_assignment(tenant_id, project_id, session_id, creator_id, assignee, description, title, issue_type,
integration_project_id):
error, integration = integrations_manager.get_integration(tenant_id=tenant_id, user_id=creator_id)
if error is not None:
return error
@ -40,7 +41,7 @@ def create_new_assignment(tenant_id, project_id, session_id, creator_id, assigne
integration_project_id=integration_project_id)
except integration_base_issue.RequestException as e:
return integration_base_issue.proxy_issues_handler(e)
if issue is not None and "id" not in issue:
if issue is None or "id" not in issue:
return {"errors": ["something went wrong while creating the issue"]}
with pg_client.PostgresClient() as cur:
query = cur.mogrify("""\

View file

@ -1,3 +0,0 @@
BEGIN;
CREATE INDEX pages_ttfb_idx ON events.pages (ttfb) WHERE ttfb > 0;
COMMIT;

View file

@ -38,12 +38,13 @@ def jwt_context(context):
}
def generate_jwt(id, tenant_id, iat, aud):
def generate_jwt(id, tenant_id, iat, aud, exp=None):
token = jwt.encode(
payload={
"userId": id,
"tenantId": tenant_id,
"exp": iat // 1000 + config("JWT_EXPIRATION", cast=int) + TimeUTC.get_utc_offset() // 1000,
"exp": exp + TimeUTC.get_utc_offset() // 1000 if exp is not None \
else iat // 1000 + config("JWT_EXPIRATION", cast=int) + TimeUTC.get_utc_offset() // 1000,
"iss": config("JWT_ISSUER"),
"iat": iat // 1000,
"aud": aud

View file

@ -1,7 +1,7 @@
import math
import schemas
from chalicelib.utils import pg_client, exp_ch_helper
from chalicelib.utils import exp_ch_helper
from chalicelib.utils import args_transformer
from chalicelib.utils import helper
from chalicelib.utils.TimeUTC import TimeUTC

View file

@ -101,7 +101,7 @@ def get_by_id2_pg(project_id, session_id, context: schemas_ee.CurrentContext, fu
data['crashes'] = events_ios.get_crashes_by_session_id(session_id=session_id)
data['userEvents'] = events_ios.get_customs_by_sessionId(project_id=project_id,
session_id=session_id)
data['mobsUrl'] = sessions_mobs.get_ios(sessionId=session_id)
data['mobsUrl'] = sessions_mobs.get_ios(session_id=session_id)
else:
data['events'] = events.get_by_sessionId2_pg(project_id=project_id, session_id=session_id,
group_clickrage=True)

View file

@ -6,7 +6,7 @@ from time import time
from decouple import config
from chalicelib.core import assist
from chalicelib.utils import helper
from chalicelib.utils import helper_ee
def __get_secret():
@ -18,7 +18,7 @@ def get_temporary_credentials():
secret = __get_secret()
if secret is None:
return {"errors": ["secret not defined"]}
user = helper.generate_salt()
user = helper_ee.generate_salt()
ttl = config("assist_ttl", cast=int, default=48) * 3600
timestamp = int(time()) + ttl
username = str(timestamp) + ':' + user

View file

@ -0,0 +1,6 @@
import random
import string
def generate_salt():
return "".join(random.choices(string.hexdigits, k=36))

View file

@ -12,7 +12,6 @@ from starlette.responses import Response, JSONResponse
import schemas_ee
from chalicelib.core import traces
from chalicelib.core import permissions
async def OR_context(request: Request) -> schemas_ee.CurrentContext: