mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-19 04:58:09 +00:00
Interact with migrations via cli (#2816)
* Interact with migrations via cli * Move command under notifications
This commit is contained in:
@ -13,7 +13,7 @@ import time
|
||||
import uuid
|
||||
from enum import Enum
|
||||
from shutil import which
|
||||
from typing import Callable, Dict, List, Optional, Tuple, Type, TypeVar
|
||||
from typing import Callable, Dict, List, Optional, Tuple, Type, TypeVar, Union
|
||||
from urllib.parse import urlparse
|
||||
from uuid import UUID
|
||||
|
||||
@ -859,6 +859,30 @@ class Notifications(Endpoint):
|
||||
data=requests.NotificationSearch(container=container),
|
||||
)
|
||||
|
||||
def migrate_jinja_to_scriban(
|
||||
self, dry_run: bool = False
|
||||
) -> Union[
|
||||
responses.JinjaToScribanMigrationResponse,
|
||||
responses.JinjaToScribanMigrationDryRunResponse,
|
||||
]:
|
||||
"""Migrates all notification templates from jinja to scriban"""
|
||||
|
||||
migration_endpoint = "migrations/jinja_to_scriban"
|
||||
if dry_run:
|
||||
return self._req_model(
|
||||
"POST",
|
||||
responses.JinjaToScribanMigrationDryRunResponse,
|
||||
data=requests.JinjaToScribanMigrationPost(dry_run=dry_run),
|
||||
alternate_endpoint=migration_endpoint,
|
||||
)
|
||||
else:
|
||||
return self._req_model(
|
||||
"POST",
|
||||
responses.JinjaToScribanMigrationResponse,
|
||||
data=requests.JinjaToScribanMigrationPost(dry_run=dry_run),
|
||||
alternate_endpoint=migration_endpoint,
|
||||
)
|
||||
|
||||
|
||||
class Tasks(Endpoint):
|
||||
"""Interact with tasks"""
|
||||
|
@ -262,4 +262,8 @@ class TemplateValidationPost(BaseModel):
|
||||
context: Optional[TemplateRenderContext]
|
||||
|
||||
|
||||
class JinjaToScribanMigrationPost(BaseModel):
|
||||
dry_run: bool = Field(default=False)
|
||||
|
||||
|
||||
_check_hotfix()
|
||||
|
@ -89,3 +89,12 @@ class CanSchedule(BaseResponse):
|
||||
class TemplateValidationResponse(BaseResponse):
|
||||
rendered_template: str
|
||||
available_context: TemplateRenderContext
|
||||
|
||||
|
||||
class JinjaToScribanMigrationResponse(BaseResponse):
|
||||
updated_notification_ids: List[UUID]
|
||||
failed_notification_ids: List[UUID]
|
||||
|
||||
|
||||
class JinjaToScribanMigrationDryRunResponse(BaseResponse):
|
||||
notification_ids_to_update: List[UUID]
|
||||
|
Reference in New Issue
Block a user