From 35b9d6ebafabd42fe437654d0eaf4e39de1049e0 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Fri, 29 Apr 2022 13:40:57 +0200 Subject: [PATCH] feat(api): s3 helper detect environment feat(api): support description for dashboards --- api/chalicelib/core/dashboards.py | 7 ++++--- api/chalicelib/utils/s3.py | 13 ++++++++----- api/schemas.py | 1 + .../helm/db/init_dbs/postgresql/1.6.1/1.6.1.sql | 12 ++++++++++++ .../helm/db/init_dbs/postgresql/init_schema.sql | 1 + scripts/helm/db/init_dbs/postgresql/1.6.1/1.6.1.sql | 12 ++++++++++++ scripts/helm/db/init_dbs/postgresql/init_schema.sql | 1 + 7 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 ee/scripts/helm/db/init_dbs/postgresql/1.6.1/1.6.1.sql create mode 100644 scripts/helm/db/init_dbs/postgresql/1.6.1/1.6.1.sql diff --git a/api/chalicelib/core/dashboards.py b/api/chalicelib/core/dashboards.py index 7b7bfe252..bce5d3ad0 100644 --- a/api/chalicelib/core/dashboards.py +++ b/api/chalicelib/core/dashboards.py @@ -42,8 +42,8 @@ def get_templates(project_id, user_id): def create_dashboard(project_id, user_id, data: schemas.CreateDashboardSchema): with pg_client.PostgresClient() as cur: - pg_query = f"""INSERT INTO dashboards(project_id, user_id, name, is_public, is_pinned) - VALUES(%(projectId)s, %(userId)s, %(name)s, %(is_public)s, %(is_pinned)s) + pg_query = f"""INSERT INTO dashboards(project_id, user_id, name, is_public, is_pinned, description) + VALUES(%(projectId)s, %(userId)s, %(name)s, %(is_public)s, %(is_pinned)s, %(description)s) RETURNING *""" params = {"userId": user_id, "projectId": project_id, **data.dict()} if data.metrics is not None and len(data.metrics) > 0: @@ -134,7 +134,8 @@ def update_dashboard(project_id, user_id, dashboard_id, data: schemas.EditDashbo row = cur.fetchone() offset = row["count"] pg_query = f"""UPDATE dashboards - SET name = %(name)s + SET name = %(name)s, + description= %(description)s {", is_public = %(is_public)s" if data.is_public is not None else ""} {", is_pinned = %(is_pinned)s" if data.is_pinned is not None else ""} WHERE dashboards.project_id = %(projectId)s diff --git a/api/chalicelib/utils/s3.py b/api/chalicelib/utils/s3.py index 67e1eafd2..b6575ccb5 100644 --- a/api/chalicelib/utils/s3.py +++ b/api/chalicelib/utils/s3.py @@ -5,11 +5,14 @@ import boto3 import botocore from botocore.client import Config -client = boto3.client('s3', endpoint_url=config("S3_HOST"), - aws_access_key_id=config("S3_KEY"), - aws_secret_access_key=config("S3_SECRET"), - config=Config(signature_version='s3v4'), - region_name=config("sessions_region")) +if not config("S3_HOST", default=False): + client = boto3.client('s3') +else: + client = boto3.client('s3', endpoint_url=config("S3_HOST"), + aws_access_key_id=config("S3_KEY"), + aws_secret_access_key=config("S3_SECRET"), + config=Config(signature_version='s3v4'), + region_name=config("sessions_region")) def exists(bucket, key): diff --git a/api/schemas.py b/api/schemas.py index bb697d03f..105ead87e 100644 --- a/api/schemas.py +++ b/api/schemas.py @@ -888,6 +888,7 @@ class SavedSearchSchema(FunnelSchema): class CreateDashboardSchema(BaseModel): name: str = Field(..., min_length=1) + description: str = Field(default=None) is_public: bool = Field(default=False) is_pinned: bool = Field(default=False) metrics: Optional[List[int]] = Field(default=[]) diff --git a/ee/scripts/helm/db/init_dbs/postgresql/1.6.1/1.6.1.sql b/ee/scripts/helm/db/init_dbs/postgresql/1.6.1/1.6.1.sql new file mode 100644 index 000000000..e94ccc4e1 --- /dev/null +++ b/ee/scripts/helm/db/init_dbs/postgresql/1.6.1/1.6.1.sql @@ -0,0 +1,12 @@ +BEGIN; +CREATE OR REPLACE FUNCTION openreplay_version() + RETURNS text AS +$$ +SELECT 'v1.6.1-ee' +$$ LANGUAGE sql IMMUTABLE; + + +ALTER TABLE IF EXISTS dashboards + ADD COLUMN IF NOT EXISTS description text NOT NULL DEFAULT ''; + +COMMIT; \ No newline at end of file diff --git a/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql b/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql index 461a414fc..7d6bdece7 100644 --- a/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql +++ b/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql @@ -838,6 +838,7 @@ $$ project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, user_id integer NOT NULL REFERENCES users (user_id) ON DELETE SET NULL, name text NOT NULL, + description text NOT NULL DEFAULT '', is_public boolean NOT NULL DEFAULT TRUE, is_pinned boolean NOT NULL DEFAULT FALSE, created_at timestamp NOT NULL DEFAULT timezone('utc'::text, now()), diff --git a/scripts/helm/db/init_dbs/postgresql/1.6.1/1.6.1.sql b/scripts/helm/db/init_dbs/postgresql/1.6.1/1.6.1.sql new file mode 100644 index 000000000..c61efae19 --- /dev/null +++ b/scripts/helm/db/init_dbs/postgresql/1.6.1/1.6.1.sql @@ -0,0 +1,12 @@ +BEGIN; +CREATE OR REPLACE FUNCTION openreplay_version() + RETURNS text AS +$$ +SELECT 'v1.6.1' +$$ LANGUAGE sql IMMUTABLE; + + +ALTER TABLE IF EXISTS dashboards + ADD COLUMN IF NOT EXISTS description text NOT NULL DEFAULT ''; + +COMMIT; \ No newline at end of file diff --git a/scripts/helm/db/init_dbs/postgresql/init_schema.sql b/scripts/helm/db/init_dbs/postgresql/init_schema.sql index 5a01226f1..a4b41fefe 100644 --- a/scripts/helm/db/init_dbs/postgresql/init_schema.sql +++ b/scripts/helm/db/init_dbs/postgresql/init_schema.sql @@ -992,6 +992,7 @@ $$ project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, user_id integer NOT NULL REFERENCES users (user_id) ON DELETE SET NULL, name text NOT NULL, + description text NOT NULL DEFAULT '', is_public boolean NOT NULL DEFAULT TRUE, is_pinned boolean NOT NULL DEFAULT FALSE, created_at timestamp NOT NULL DEFAULT timezone('utc'::text, now()),