mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-19 21:13:46 +00:00
Replace notifications by default (#1084)
This commit is contained in:
@ -692,11 +692,17 @@ class Notifications(Endpoint):
|
||||
endpoint = "notifications"
|
||||
|
||||
def create(
|
||||
self, container: primitives.Container, config: models.NotificationConfig
|
||||
self,
|
||||
container: primitives.Container,
|
||||
config: models.NotificationConfig,
|
||||
*,
|
||||
replace_existing: bool = False,
|
||||
) -> models.Notification:
|
||||
"""Create a notification based on a config file"""
|
||||
|
||||
config = requests.NotificationCreate(container=container, config=config.config)
|
||||
config = requests.NotificationCreate(
|
||||
container=container, config=config.config, replace_existing=replace_existing
|
||||
)
|
||||
return self._req_model("POST", models.Notification, data=config)
|
||||
|
||||
def create_teams(
|
||||
@ -766,11 +772,17 @@ class Notifications(Endpoint):
|
||||
data=requests.NotificationGet(notification_id=notification_id_expanded),
|
||||
)
|
||||
|
||||
def list(self) -> List[models.Notification]:
|
||||
def list(
|
||||
self, *, container: Optional[List[primitives.Container]] = None
|
||||
) -> List[models.Notification]:
|
||||
"""List notification integrations"""
|
||||
|
||||
self.logger.debug("listing notification integrations")
|
||||
return self._req_model_list("GET", models.Notification)
|
||||
return self._req_model_list(
|
||||
"GET",
|
||||
models.Notification,
|
||||
data=requests.NotificationSearch(container=container),
|
||||
)
|
||||
|
||||
|
||||
class Tasks(Endpoint):
|
||||
|
@ -63,17 +63,16 @@ class Template(Command):
|
||||
self.onefuzz.tasks.delete(task.task_id)
|
||||
|
||||
if stop_notifications:
|
||||
notifications = self.onefuzz.notifications.list()
|
||||
for container in task.config.containers:
|
||||
for notification in notifications:
|
||||
if container.name == notification.container:
|
||||
self.logger.info(
|
||||
"removing notification: %s",
|
||||
notification.notification_id,
|
||||
)
|
||||
self.onefuzz.notifications.delete(
|
||||
notification.notification_id
|
||||
)
|
||||
container_names = [x.name for x in task.config.containers]
|
||||
notifications = self.onefuzz.notifications.list(
|
||||
container=container_names
|
||||
)
|
||||
for notification in notifications:
|
||||
self.logger.info(
|
||||
"removing notification: %s",
|
||||
notification.notification_id,
|
||||
)
|
||||
self.onefuzz.notifications.delete(notification.notification_id)
|
||||
|
||||
|
||||
Template.stop.__doc__ = "stop a template job"
|
||||
|
@ -3,7 +3,6 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
import zipfile
|
||||
@ -119,19 +118,8 @@ class JobHelper:
|
||||
else:
|
||||
container = self.containers[ContainerType.reports]
|
||||
|
||||
if not container:
|
||||
return
|
||||
|
||||
config_dict = json.loads(config.json())
|
||||
for entry in self.onefuzz.notifications.list():
|
||||
if entry.container == container and entry.config == config_dict:
|
||||
self.logger.debug(
|
||||
"notification already exists: %s", entry.notification_id
|
||||
)
|
||||
return
|
||||
|
||||
self.logger.info("creating notification config for %s", container)
|
||||
self.onefuzz.notifications.create(container, config)
|
||||
self.onefuzz.notifications.create(container, config, replace_existing=True)
|
||||
|
||||
def upload_setup(
|
||||
self,
|
||||
|
Reference in New Issue
Block a user