Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
guidopetri authored Feb 3, 2024
2 parents 75bd328 + b98b5f2 commit 58b7f6a
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 53 deletions.
34 changes: 30 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ on:
push:
branches:
- master
pull_request:
pull_request_target:
branches:
- master
env:
NODE_VERSION: 16.20.1
jobs:
backend-lint:
runs-on: ubuntu-22.04
steps:
- if: github.event.pull_request.mergeable == 'false'
name: Exit if PR is not mergeable
run: exit 1
- uses: actions/checkout@v3
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.merge_commit_sha }}
- uses: actions/setup-python@v4
with:
python-version: '3.8'
Expand All @@ -29,9 +35,13 @@ jobs:
COMPOSE_DOCKER_CLI_BUILD: 1
DOCKER_BUILDKIT: 1
steps:
- if: github.event.pull_request.mergeable == 'false'
name: Exit if PR is not mergeable
run: exit 1
- uses: actions/checkout@v3
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.merge_commit_sha }}
- name: Build Docker Images
run: |
set -x
Expand Down Expand Up @@ -65,9 +75,13 @@ jobs:
frontend-lint:
runs-on: ubuntu-22.04
steps:
- if: github.event.pull_request.mergeable == 'false'
name: Exit if PR is not mergeable
run: exit 1
- uses: actions/checkout@v3
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.merge_commit_sha }}
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
Expand All @@ -88,9 +102,13 @@ jobs:
runs-on: ubuntu-22.04
needs: frontend-lint
steps:
- if: github.event.pull_request.mergeable == 'false'
name: Exit if PR is not mergeable
run: exit 1
- uses: actions/checkout@v3
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.merge_commit_sha }}
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
Expand All @@ -111,15 +129,19 @@ jobs:
env:
COMPOSE_FILE: .ci/docker-compose.cypress.yml
COMPOSE_PROJECT_NAME: cypress
PERCY_TOKEN_ENCODED: ZGRiY2ZmZDQ0OTdjMzM5ZWE0ZGQzNTZiOWNkMDRjOTk4Zjg0ZjMxMWRmMDZiM2RjOTYxNDZhOGExMjI4ZDE3MA==
CYPRESS_PROJECT_ID_ENCODED: OTI0Y2th
CYPRESS_RECORD_KEY_ENCODED: YzA1OTIxMTUtYTA1Yy00NzQ2LWEyMDMtZmZjMDgwZGI2ODgx
CYPRESS_INSTALL_BINARY: 0
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 1
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
steps:
- if: github.event.pull_request.mergeable == 'false'
name: Exit if PR is not mergeable
run: exit 1
- uses: actions/checkout@v3
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.merge_commit_sha }}
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
Expand Down Expand Up @@ -183,9 +205,13 @@ jobs:
- build-skip-check
if: needs.build-skip-check.outputs.skip == 'false'
steps:
- if: github.event.pull_request.mergeable == 'false'
name: Exit if PR is not mergeable
run: exit 1
- uses: actions/checkout@v3
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.merge_commit_sha }}
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
Expand Down
13 changes: 0 additions & 13 deletions client/cypress/cypress.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable import/no-extraneous-dependencies, no-console */
const { find } = require("lodash");
const atob = require("atob");
const { execSync } = require("child_process");
const { get, post } = require("request").defaults({ jar: true });
const { seedData } = require("./seed-data");
Expand Down Expand Up @@ -60,23 +59,11 @@ function stopServer() {

function runCypressCI() {
const {
PERCY_TOKEN_ENCODED,
CYPRESS_PROJECT_ID_ENCODED,
CYPRESS_RECORD_KEY_ENCODED,
GITHUB_REPOSITORY,
CYPRESS_OPTIONS, // eslint-disable-line no-unused-vars
} = process.env;

if (GITHUB_REPOSITORY === "getredash/redash") {
if (PERCY_TOKEN_ENCODED) {
process.env.PERCY_TOKEN = atob(`${PERCY_TOKEN_ENCODED}`);
}
if (CYPRESS_PROJECT_ID_ENCODED) {
process.env.CYPRESS_PROJECT_ID = atob(`${CYPRESS_PROJECT_ID_ENCODED}`);
}
if (CYPRESS_RECORD_KEY_ENCODED) {
process.env.CYPRESS_RECORD_KEY = atob(`${CYPRESS_RECORD_KEY_ENCODED}`);
}
process.env.CYPRESS_OPTIONS = "--record";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ def upgrade():
type_=JSONB(astext_type=sa.Text()),
postgresql_using='layout::jsonb',
server_default=sa.text("'{}'::jsonb"))
op.alter_column('query_results', 'data',
existing_type=sa.Text(),
type_=JSONB(astext_type=sa.Text()),
nullable=True,
postgresql_using='data::text',
server_default=sa.text("'{}'::jsonb"))
op.alter_column('changes', 'change',
existing_type=JSON(astext_type=sa.Text()),
type_=JSONB(astext_type=sa.Text()),
Expand Down Expand Up @@ -124,11 +118,6 @@ def downgrade():
type_=sa.Text(),
postgresql_using='layout::text',
server_default=sa.text("'{}'::text"))
op.alter_column('query_results', 'data',
existing_type=JSONB(astext_type=sa.Text()),
type_=sa.Text(),
postgresql_using='data::text',
server_default=sa.text("'{}'::text"))
op.alter_column('changes', 'change',
existing_type=JSONB(astext_type=sa.Text()),
type_=JSON(astext_type=sa.Text()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from redash.utils.configuration import ConfigurationContainer
from redash.models.types import (
EncryptedConfiguration,
Configuration,
MutableDict,
MutableList,
)
Expand Down Expand Up @@ -45,7 +44,14 @@ def upgrade():
)
),
),
sa.Column("options", ConfigurationContainer.as_mutable(Configuration)),
sa.Column(
"options",
ConfigurationContainer.as_mutable(
EncryptedConfiguration(
sa.Text, settings.DATASOURCE_SECRET_KEY, FernetEngine
)
),
),
)

conn = op.get_bind()
Expand Down
14 changes: 9 additions & 5 deletions migrations/versions/d7d747033183_encrypt_alert_destinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
from redash import settings
from redash.utils.configuration import ConfigurationContainer
from redash.models.base import key_type
from redash.models.types import (
EncryptedConfiguration,
Configuration,
)
from redash.models.types import EncryptedConfiguration


# revision identifiers, used by Alembic.
Expand Down Expand Up @@ -45,7 +42,14 @@ def upgrade():
)
),
),
sa.Column("options", ConfigurationContainer.as_mutable(Configuration)),
sa.Column(
"options",
ConfigurationContainer.as_mutable(
EncryptedConfiguration(
sa.Text, settings.DATASOURCE_SECRET_KEY, FernetEngine
)
),
),
)

conn = op.get_bind()
Expand Down
4 changes: 2 additions & 2 deletions redash/destinations/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def notify(self, alert, query, user, new_state, app, host, metadata, options):
"inline": True,
},
]
if alert.options.get("custom_body"):
fields.append({"name": "Description", "value": alert.options["custom_body"]})
if alert.custom_body:
fields.append({"name": "Description", "value": alert.custom_body})
if new_state == Alert.TRIGGERED_STATE:
if alert.options.get("custom_subject"):
text = alert.options["custom_subject"]
Expand Down
2 changes: 1 addition & 1 deletion redash/destinations/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def notify(self, alert, query, user, new_state, app, host, metadata, options):
payload = {"attachments": [{"text": text, "color": color, "fields": fields}]}

try:
resp = requests.post(options.get("url"), data=json_dumps(payload), timeout=5.0)
resp = requests.post(options.get("url"), data=json_dumps(payload).encode("utf-8"), timeout=5.0)
logging.warning(resp.text)
if resp.status_code != 200:
logging.error("Slack send ERROR. status_code => {status}".format(status=resp.status_code))
Expand Down
4 changes: 2 additions & 2 deletions redash/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
QueryDetachedFromDataSourceError,
)
from redash.models.types import (
Configuration,
EncryptedConfiguration,
JSONText,
MutableDict,
MutableList,
json_cast_property,
Expand Down Expand Up @@ -315,7 +315,7 @@ class QueryResult(db.Model, BelongsToOrgMixin):
data_source = db.relationship(DataSource, backref=backref("query_results"))
query_hash = Column(db.String(32), index=True)
query_text = Column("query", db.Text)
data = Column(MutableDict.as_mutable(JSONB), nullable=True)
data = Column(JSONText, nullable=True)
runtime = Column(DOUBLE_PRECISION)
retrieved_at = Column(db.DateTime(True))

Expand Down
30 changes: 18 additions & 12 deletions redash/models/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,10 @@
from sqlalchemy.types import TypeDecorator
from sqlalchemy_utils import EncryptedType

from redash.models.base import db
from redash.utils import json_dumps, json_loads
from redash.utils.configuration import ConfigurationContainer

from .base import db


class Configuration(TypeDecorator):
impl = db.Text

def process_bind_param(self, value, dialect):
return value.to_json()

def process_result_value(self, value, dialect):
return ConfigurationContainer.from_json(value)


class EncryptedConfiguration(EncryptedType):
def process_bind_param(self, value, dialect):
Expand All @@ -28,6 +18,22 @@ def process_result_value(self, value, dialect):
)


# Utilized for cases when JSON size is bigger than JSONB (255MB) or JSON (10MB) limit
class JSONText(TypeDecorator):
impl = db.Text

def process_bind_param(self, value, dialect):
if value is None:
return value

return json_dumps(value)

def process_result_value(self, value, dialect):
if not value:
return value
return json_loads(value)


class MutableDict(Mutable, dict):
@classmethod
def coerce(cls, key, value):
Expand Down
3 changes: 2 additions & 1 deletion tests/handlers/test_destinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ def test_post(self):


def test_discord_notify_calls_requests_post():
alert = mock.Mock(spec_set=["id", "name", "options", "render_template"])
alert = mock.Mock(spec_set=["id", "name", "options", "custom_body", "render_template"])
alert.id = 1
alert.name = "Test Alert"
alert.options = {
"custom_subject": "Test custom subject",
"custom_body": "Test custom body",
}
alert.custom_body = alert.options["custom_body"]
alert.render_template = mock.Mock(return_value={"Rendered": "template"})
query = mock.Mock()
query.id = 1
Expand Down

0 comments on commit 58b7f6a

Please sign in to comment.