Add alertmanager as supported sender and update deps
This commit is contained in:
parent
05ffc640ed
commit
973e1fd789
18 changed files with 1682 additions and 1155 deletions
|
|
@ -4,7 +4,7 @@ from typing import Any
|
|||
|
||||
import click
|
||||
|
||||
from ops_bot.config import RoutingKey, load_config, save_config
|
||||
from ops_bot.config import RoutingKey, hook_types, load_config, save_config
|
||||
|
||||
|
||||
@click.group()
|
||||
|
|
@ -28,20 +28,23 @@ def cli(ctx: Any, config_file: str) -> None:
|
|||
)
|
||||
@click.option("--room-id", help="The room ID to send the messages to")
|
||||
@click.pass_obj
|
||||
def add_hook(config_file: str, name: str, hook_type: str, room_id: str) -> None:
|
||||
def add_hook(config_file: str, name: str, maybe_hook_type: str, room_id: str) -> None:
|
||||
settings = load_config(config_file)
|
||||
path_key = secrets.token_urlsafe(30)
|
||||
secret_token = secrets.token_urlsafe(30)
|
||||
if name in set([key.name for key in settings.routing_keys]):
|
||||
print("Error: A hook with that name already exists")
|
||||
sys.exit(1)
|
||||
if maybe_hook_type not in hook_types:
|
||||
print(f"Invalid hook type {maybe_hook_type}")
|
||||
print("Must be one of ", ", ".join(hook_types))
|
||||
settings.routing_keys.append(
|
||||
RoutingKey(
|
||||
name=name,
|
||||
path_key=path_key,
|
||||
secret_token=secret_token,
|
||||
room_id=room_id,
|
||||
hook_type=hook_type,
|
||||
hook_type=maybe_hook_type, # type: ignore[arg-type]
|
||||
)
|
||||
)
|
||||
save_config(settings)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue