forked from privacera/paig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request privacera#165 from vinayakbagal7/PAIG-2210
Implemented guardrail service with APIs to effectively manage guardrails in the system privacera#160
- Loading branch information
Showing
94 changed files
with
8,083 additions
and
172 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
111 changes: 111 additions & 0 deletions
111
paig-server/backend/paig/alembic_db/versions/67a256363095_added_guardrail_service_tables.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,111 @@ | ||
"""Added Guardrail service tables | ||
Revision ID: 67a256363095 | ||
Revises: db6e7b60cb0a | ||
Create Date: 2025-01-31 16:59:29.619823 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
import core.db_models.utils | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '67a256363095' | ||
down_revision: Union[str, None] = 'db6e7b60cb0a' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('guardrail', | ||
sa.Column('name', sa.String(length=255), nullable=False), | ||
sa.Column('description', sa.String(length=4000), nullable=True), | ||
sa.Column('version', sa.Integer(), nullable=False), | ||
sa.Column('guardrail_provider', sa.Enum('AWS', name='guardrailprovider'), nullable=True), | ||
sa.Column('guardrail_connection_name', sa.String(length=255), nullable=True), | ||
sa.Column('guardrail_configs', sa.JSON(), nullable=False), | ||
sa.Column('guardrail_provider_response', sa.JSON(), nullable=True), | ||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), | ||
sa.Column('status', sa.Integer(), nullable=False), | ||
sa.Column('create_time', sa.DateTime(), nullable=False), | ||
sa.Column('update_time', sa.DateTime(), nullable=False), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_index(op.f('ix_guardrail_create_time'), 'guardrail', ['create_time'], unique=False) | ||
op.create_index(op.f('ix_guardrail_id'), 'guardrail', ['id'], unique=False) | ||
op.create_index(op.f('ix_guardrail_update_time'), 'guardrail', ['update_time'], unique=False) | ||
op.create_table('guardrail_connection', | ||
sa.Column('name', sa.String(length=255), nullable=False), | ||
sa.Column('description', sa.String(length=4000), nullable=True), | ||
sa.Column('guardrail_provider', sa.Enum('AWS', name='guardrailprovider'), nullable=False), | ||
sa.Column('connection_details', sa.JSON(), nullable=False), | ||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), | ||
sa.Column('status', sa.Integer(), nullable=False), | ||
sa.Column('create_time', sa.DateTime(), nullable=False), | ||
sa.Column('update_time', sa.DateTime(), nullable=False), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_index(op.f('ix_guardrail_connection_create_time'), 'guardrail_connection', ['create_time'], unique=False) | ||
op.create_index(op.f('ix_guardrail_connection_id'), 'guardrail_connection', ['id'], unique=False) | ||
op.create_index(op.f('ix_guardrail_connection_update_time'), 'guardrail_connection', ['update_time'], unique=False) | ||
op.create_table('response_template', | ||
sa.Column('response', sa.String(length=4000), nullable=False), | ||
sa.Column('description', sa.String(length=4000), nullable=True), | ||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), | ||
sa.Column('status', sa.Integer(), nullable=False), | ||
sa.Column('create_time', sa.DateTime(), nullable=False), | ||
sa.Column('update_time', sa.DateTime(), nullable=False), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_index(op.f('ix_response_template_create_time'), 'response_template', ['create_time'], unique=False) | ||
op.create_index(op.f('ix_response_template_id'), 'response_template', ['id'], unique=False) | ||
op.create_index(op.f('ix_response_template_update_time'), 'response_template', ['update_time'], unique=False) | ||
op.create_table('guardrail_version_history', | ||
sa.Column('guardrail_id', sa.Integer(), nullable=False), | ||
sa.Column('version', sa.Integer(), nullable=False), | ||
sa.Column('name', sa.String(length=255), nullable=False), | ||
sa.Column('description', sa.String(length=4000), nullable=True), | ||
sa.Column('guardrail_provider', sa.Enum('AWS', name='guardrailprovider'), nullable=True), | ||
sa.Column('guardrail_connection_name', sa.String(length=255), nullable=True), | ||
sa.Column('guardrail_configs', sa.JSON(), nullable=False), | ||
sa.Column('guardrail_provider_response', sa.JSON(), nullable=True), | ||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), | ||
sa.Column('status', sa.Integer(), nullable=False), | ||
sa.Column('create_time', sa.DateTime(), nullable=False), | ||
sa.Column('update_time', sa.DateTime(), nullable=False), | ||
sa.ForeignKeyConstraint(['guardrail_id'], ['guardrail.id'], name='fk_guardrail_version_history_guardrail_id', ondelete='CASCADE'), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_index(op.f('ix_guardrail_version_history_create_time'), 'guardrail_version_history', ['create_time'], unique=False) | ||
op.create_index(op.f('ix_guardrail_version_history_id'), 'guardrail_version_history', ['id'], unique=False) | ||
op.create_index(op.f('ix_guardrail_version_history_update_time'), 'guardrail_version_history', ['update_time'], unique=False) | ||
|
||
op.add_column('ai_application', sa.Column('guardrails', core.db_models.utils.CommaSeparatedList(length=255), nullable=True)) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column('ai_application', 'guardrails') | ||
|
||
op.drop_index(op.f('ix_guardrail_version_history_update_time'), table_name='guardrail_version_history') | ||
op.drop_index(op.f('ix_guardrail_version_history_id'), table_name='guardrail_version_history') | ||
op.drop_index(op.f('ix_guardrail_version_history_create_time'), table_name='guardrail_version_history') | ||
op.drop_table('guardrail_version_history') | ||
op.drop_index(op.f('ix_response_template_update_time'), table_name='response_template') | ||
op.drop_index(op.f('ix_response_template_id'), table_name='response_template') | ||
op.drop_index(op.f('ix_response_template_create_time'), table_name='response_template') | ||
op.drop_table('response_template') | ||
op.drop_index(op.f('ix_guardrail_connection_update_time'), table_name='guardrail_connection') | ||
op.drop_index(op.f('ix_guardrail_connection_id'), table_name='guardrail_connection') | ||
op.drop_index(op.f('ix_guardrail_connection_create_time'), table_name='guardrail_connection') | ||
op.drop_table('guardrail_connection') | ||
op.drop_index(op.f('ix_guardrail_update_time'), table_name='guardrail') | ||
op.drop_index(op.f('ix_guardrail_id'), table_name='guardrail') | ||
op.drop_index(op.f('ix_guardrail_create_time'), table_name='guardrail') | ||
op.drop_table('guardrail') | ||
# ### end Alembic commands ### |
53 changes: 53 additions & 0 deletions
53
...erver/backend/paig/alembic_db/versions/db6e7b60cb0a_adding_new_encryption_type_in_enum.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,53 @@ | ||
"""Adding new encryption type in enum | ||
Revision ID: db6e7b60cb0a | ||
Revises: 701ddf55a1b4 | ||
Create Date: 2024-12-17 10:59:41.630340 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from alembic.context import get_context | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = 'db6e7b60cb0a' | ||
down_revision: Union[str, None] = '701ddf55a1b4' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# Check the database dialect | ||
dialect = get_context().dialect.name | ||
|
||
if dialect == 'sqlite': | ||
# Skip execution for SQLite | ||
print("Skipping this migration for SQLite.") | ||
return | ||
|
||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('encryption_key', 'key_type', | ||
existing_type=sa.VARCHAR(length=18), | ||
type_=sa.Enum('MSG_PROTECT_SHIELD', 'MSG_PROTECT_PLUGIN', 'CRDS_PROTECT_GUARDRAIL', name='encryptionkeytype'), | ||
existing_nullable=False) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# Check the database dialect | ||
dialect = get_context().dialect.name | ||
|
||
if dialect == 'sqlite': | ||
# Skip execution for SQLite | ||
print("Skipping downgrade for SQLite.") | ||
return | ||
|
||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('encryption_key', 'key_type', | ||
existing_type=sa.Enum('MSG_PROTECT_SHIELD', 'MSG_PROTECT_PLUGIN', 'CRDS_PROTECT_GUARDRAIL', name='encryptionkeytype'), | ||
type_=sa.VARCHAR(length=18), | ||
existing_nullable=False) | ||
# ### 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
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.