-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b2afdd
commit 94d2d18
Showing
14 changed files
with
160 additions
and
74 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
31 changes: 0 additions & 31 deletions
31
paig-server/backend/paig/alembic_db/versions/02c1e28adc51_application_api_key_added.py
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
paig-server/backend/paig/api/governance/controllers/ai_app_apikey_controller.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,30 @@ | ||
from typing import List | ||
|
||
from api.user.utils.acc_service_validation_util import AccServiceValidationUtil | ||
from core.controllers.paginated_response import Pageable | ||
from core.db_session import Transactional, Propagation | ||
from api.governance.api_schemas.ai_app_policy import AIApplicationPolicyView, AIApplicationPolicyFilter | ||
from api.governance.services.ai_app_policy_service import AIAppPolicyService | ||
from api.governance.utils.gov_service_validation_util import GovServiceValidationUtil | ||
from core.utils import SingletonDepends | ||
|
||
|
||
class AIAppAPIKeyController: | ||
""" | ||
Controller class specifically for handling AI application policies. | ||
Args: | ||
ai_app_policy_service (AIAppPolicyService): The service class for AI application policies. | ||
""" | ||
|
||
def __init__(self, | ||
ai_app_policy_service: AIAppPolicyService = SingletonDepends(AIAppPolicyService), | ||
gov_service_validation_util: GovServiceValidationUtil = SingletonDepends(GovServiceValidationUtil), | ||
acc_service_validation_util: AccServiceValidationUtil = SingletonDepends(AccServiceValidationUtil)): | ||
self.ai_app_policy_service = ai_app_policy_service | ||
self.gov_service_validation_util = gov_service_validation_util | ||
self.acc_service_validation_util = acc_service_validation_util | ||
|
||
|
||
def generate_api_key(self): | ||
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
37 changes: 37 additions & 0 deletions
37
paig-server/backend/paig/api/governance/database/db_models/ai_app_apikey_model.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,37 @@ | ||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime | ||
from sqlalchemy.orm import relationship | ||
|
||
from core.db_models.BaseSQLModel import BaseSQLModel | ||
|
||
|
||
class AIApplicationEncryptionKeyModel(BaseSQLModel): | ||
""" | ||
SQLAlchemy model representing AI application encryption keys. | ||
Attributes: | ||
__tablename__ (str): Name of the database table. | ||
key (str): Encryption key | ||
application_id (int): The application ID. | ||
""" | ||
|
||
__tablename__ = "ai_application_encryption_key" | ||
|
||
key = Column(String(255), nullable=False) | ||
application_id = Column(Integer, ForeignKey('ai_application.id', ondelete='CASCADE', name='fk_ai_application_policy_application_id'), nullable=False) | ||
ai_app = relationship("AIApplicationModel", back_populates="app_encryption_keys") | ||
|
||
|
||
class AIApplicationAPIKeyModel(BaseSQLModel): | ||
""" | ||
SQLAlchemy model representing AI application API keys. | ||
scope: 1 - All access, 0 - No access | ||
api_key: API key | ||
expiry_time: Expiry time of the API key | ||
application_id: The AI application ID. | ||
""" | ||
__tablename__ = "ai_application_api_key" | ||
scope = Column(Integer, nullable=False, default=1) | ||
api_key = Column(String(255), nullable=False) | ||
expiry_time = Column(DateTime, index=True, nullable=True) | ||
application_id = Column(Integer, ForeignKey('ai_application.id', ondelete='CASCADE', name='fk_ai_application_policy_application_id'), nullable=False) | ||
|
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
45 changes: 45 additions & 0 deletions
45
paig-server/backend/paig/api/governance/database/db_operations/ai_app_apikey_repository.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,45 @@ | ||
import os | ||
|
||
from core.factory.database_initiator import BaseOperations | ||
from api.governance.database.db_models.ai_app_apikey_model import AIApplicationEncryptionKeyModel, AIApplicationAPIKeyModel | ||
|
||
|
||
class AIAppEncryptionKeyRepository(BaseOperations[AIApplicationEncryptionKeyModel]): | ||
""" | ||
Repository class for handling database operations related to AI application encryption key models. | ||
Inherits from BaseOperations[AIAppEncryptionKeyRepository], providing generic CRUD operations. | ||
This class inherits all methods from BaseOperations[AIAppEncryptionKeyRepository]. | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
Initialize the AIAppEncryptionKeyRepository. | ||
Args: | ||
db_session (Session): The database session to use for operations. | ||
""" | ||
super().__init__(AIApplicationEncryptionKeyModel) | ||
|
||
def create_encryption_key(self, app_id): | ||
key = os.urandom(32) | ||
self.create_record(AIApplicationEncryptionKeyModel(application_id=app_id, key=key)) | ||
|
||
class AIAppAPIKeyRepository(BaseOperations[AIApplicationAPIKeyModel]): | ||
""" | ||
Repository class for handling database operations related to AI application api key models. | ||
Inherits from BaseOperations[AIApplicationAPIKeyModel], providing generic CRUD operations. | ||
This class inherits all methods from BaseOperations[AIApplicationAPIKeyModel]. | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
Initialize the AIAppRepository. | ||
Args: | ||
db_session (Session): The database session to use for operations. | ||
""" | ||
super().__init__(AIApplicationAPIKeyModel) |
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
19 changes: 19 additions & 0 deletions
19
paig-server/backend/paig/api/governance/routes/ai_app_apikey_router.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,19 @@ | ||
from fastapi import APIRouter, Depends | ||
|
||
from api.governance.controllers.ai_app_apikey_controller import AIAPPAPIKeyController | ||
from core.utils import SingletonDepends | ||
|
||
ai_app_apikey_router = APIRouter() | ||
|
||
ai_app_apikey_controller_instance = Depends(SingletonDepends(AIAPPAPIKeyController, called_inside_fastapi_depends=True)) | ||
|
||
|
||
@ai_app_apikey_router.post("generate") | ||
async def generate_api_key( | ||
app_id: int, | ||
ai_app_apikey_controller: AIAPPAPIKeyController = ai_app_apikey_controller_instance | ||
): | ||
""" | ||
Generated Application API Key | ||
""" | ||
return await ai_app_apikey_controller.generate_api_key(app_id) |
16 changes: 16 additions & 0 deletions
16
paig-server/backend/paig/api/governance/services/ai_app_apikey_service.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,16 @@ | ||
from api.governance.database.db_operations.ai_app_apikey_repository import AIAppAPIKeyRepository, \ | ||
AIAppEncryptionKeyRepository | ||
from core.utils import SingletonDepends | ||
|
||
|
||
class AIAppAPIKeyService: | ||
|
||
def __init__(self, ai_app_apikey_repository: AIAppAPIKeyRepository = SingletonDepends(AIAppAPIKeyRepository), | ||
ai_app_encryptionkey_repository: AIAppEncryptionKeyRepository = SingletonDepends( | ||
AIAppEncryptionKeyRepository) | ||
): | ||
self.ai_app_apikey_repository = ai_app_apikey_repository | ||
self.ai_app_encryptionkey_repository = ai_app_encryptionkey_repository | ||
|
||
def create_app_encryption_key(self, app_id): | ||
return self.ai_app_encryptionkey_repository.create_encryption_key(app_id) |
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