Replace notifications by default (#1084)

This commit is contained in:
bmc-msft
2021-07-20 18:39:31 -04:00
committed by GitHub
parent 2691d91d8f
commit 065272191e
7 changed files with 66 additions and 47 deletions

View File

@ -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):

View File

@ -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"

View File

@ -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,