-
Notifications
You must be signed in to change notification settings - Fork 504
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 bugfix/use-service-id-for-service-feedback
- Loading branch information
Showing
29 changed files
with
633 additions
and
243 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
99 changes: 99 additions & 0 deletions
99
src/dispatch/database/revisions/tenant/versions/2024-10-25_24322617ce9a.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,99 @@ | ||
"""Adds configuration to the Dispatch Ticket PluginInstance | ||
Revision ID: 24322617ce9a | ||
Revises: 3c49f62d7914 | ||
Create Date: 2024-10-25 15:15:38.078421 | ||
""" | ||
|
||
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 DISPATCH_ENCRYPTION_KEY | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "24322617ce9a" | ||
down_revision = "3c49f62d7914" | ||
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_core.config import DispatchTicketConfiguration | ||
|
||
bind = op.get_bind() | ||
session = Session(bind=bind) | ||
|
||
instances = session.query(PluginInstance).all() | ||
|
||
try: | ||
dispatch_ticket_config = DispatchTicketConfiguration( | ||
use_incident_name=False, | ||
) | ||
|
||
migrate_config(instances, "dispatch-ticket", dispatch_ticket_config) | ||
|
||
except ValidationError: | ||
print( | ||
"Skipping automatic migration of Dispatch ticket plugin, if you are using the Dispatch ticket plugin, please manually migrate." | ||
) | ||
|
||
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
Oops, something went wrong.