-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change: encrypt data source options. 🔓 (#2970)
* Change: encrypt data source options * Implement migration
- Loading branch information
Showing
5 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
migrations/versions/98af61feea92_add_encrypted_options_to_data_sources.py
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,49 @@ | ||
"""add_encrypted_options_to_data_sources | ||
Revision ID: 98af61feea92 | ||
Revises: 73beceabb948 | ||
Create Date: 2019-01-31 09:21:31.517265 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
from sqlalchemy.sql import table | ||
from sqlalchemy_utils.types.encrypted.encrypted_type import FernetEngine | ||
|
||
from redash import settings | ||
from redash.utils.configuration import ConfigurationContainer | ||
from redash.models.types import EncryptedConfiguration, Configuration, MutableDict, MutableList, PseudoJSON | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '98af61feea92' | ||
down_revision = '73beceabb948' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.add_column('data_sources', sa.Column('encrypted_options', postgresql.BYTEA(), nullable=True)) | ||
|
||
# copy values | ||
data_sources = table( | ||
'data_sources', | ||
sa.Column('id', sa.Integer, primary_key=True), | ||
sa.Column('encrypted_options', ConfigurationContainer.as_mutable(EncryptedConfiguration(sa.Text, settings.SECRET_KEY, FernetEngine))), | ||
sa.Column('options', ConfigurationContainer.as_mutable(Configuration))) | ||
|
||
conn = op.get_bind() | ||
for ds in conn.execute(data_sources.select()): | ||
conn.execute( | ||
data_sources | ||
.update() | ||
.where(data_sources.c.id == ds.id) | ||
.values(encrypted_options=ds.options)) | ||
|
||
op.drop_column('data_sources', 'options') | ||
op.alter_column('data_sources', 'encrypted_options', | ||
nullable=False) | ||
|
||
|
||
def downgrade(): | ||
pass |
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