-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into docker-build
- Loading branch information
Showing
20 changed files
with
553 additions
and
254 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
105 changes: 105 additions & 0 deletions
105
src/dispatch/database/revisions/tenant/versions/2024-09-23_32652e0360dd.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,105 @@ | ||
"""Adds dispatch-create-task slug to slack conversation plugin config. | ||
Revision ID: 32652e0360dd | ||
Revises: 1f4dc687945d | ||
Create Date: 2024-09-23 16:02:50.742796 | ||
""" | ||
|
||
from alembic import op | ||
from pydantic import SecretStr, ValidationError | ||
from pydantic.json import pydantic_encoder | ||
|
||
from sqlalchemy import Column, Integer, ForeignKey, String | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import relationship, Session | ||
from sqlalchemy.ext.hybrid import hybrid_property | ||
from sqlalchemy_utils import StringEncryptedType | ||
from sqlalchemy_utils.types.encrypted.encrypted_type import AesEngine | ||
from dispatch.config import config, DISPATCH_ENCRYPTION_KEY | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "32652e0360dd" | ||
down_revision = "1f4dc687945d" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
Base = declarative_base() | ||
|
||
|
||
def show_secrets_encoder(obj): | ||
if isinstance(obj, SecretStr): | ||
return obj.get_secret_value() | ||
else: | ||
return pydantic_encoder(obj) | ||
|
||
|
||
def migrate_config(instances, slug, config): | ||
for instance in instances: | ||
if slug == instance.plugin.slug: | ||
instance.configuration = config | ||
|
||
|
||
class Plugin(Base): | ||
__tablename__ = "plugin" | ||
__table_args__ = {"schema": "dispatch_core"} | ||
id = Column(Integer, primary_key=True) | ||
slug = Column(String, unique=True) | ||
|
||
|
||
class PluginInstance(Base): | ||
__tablename__ = "plugin_instance" | ||
id = Column(Integer, primary_key=True) | ||
_configuration = Column( | ||
StringEncryptedType(key=str(DISPATCH_ENCRYPTION_KEY), engine=AesEngine, padding="pkcs5") | ||
) | ||
plugin_id = Column(Integer, ForeignKey(Plugin.id)) | ||
plugin = relationship(Plugin, backref="instances") | ||
|
||
@hybrid_property | ||
def configuration(self): | ||
"""Property that correctly returns a plugins configuration object.""" | ||
pass | ||
|
||
@configuration.setter | ||
def configuration(self, configuration): | ||
"""Property that correctly sets a plugins configuration object.""" | ||
if configuration: | ||
self._configuration = configuration.json(encoder=show_secrets_encoder) | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
from dispatch.plugins.dispatch_slack.config import SlackConversationConfiguration | ||
|
||
bind = op.get_bind() | ||
session = Session(bind=bind) | ||
|
||
instances = session.query(PluginInstance).all() | ||
|
||
# Slash commands | ||
SLACK_COMMAND_CREATE_TASK_SLUG = config( | ||
"SLACK_COMMAND_CREATE_TASK_SLUG", default="/dispatch-create-task" | ||
) | ||
|
||
try: | ||
slack_conversation_config = SlackConversationConfiguration( | ||
slack_command_create_task=SLACK_COMMAND_CREATE_TASK_SLUG, | ||
) | ||
|
||
migrate_config(instances, "slack-conversation", slack_conversation_config) | ||
|
||
except ValidationError: | ||
print( | ||
"Skipping automatic migration of slack plugin credentials, if you are using the slack plugin manually migrate credentials." | ||
) | ||
|
||
session.commit() | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
pass | ||
# ### end Alembic commands ### |
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
Oops, something went wrong.