Skip to content

Commit

Permalink
add cli command for providers and provider ags listing
Browse files Browse the repository at this point in the history
  • Loading branch information
dalwar23 committed Apr 28, 2024
1 parent ee5dded commit 80c5b25
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
58 changes: 57 additions & 1 deletion src/kumaone/cli/notification_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Import custom (local) python packages
from src.kumaone.configs import check_config
from src.kumaone.connection import connect_login, disconnect
from src.kumaone.notifications import add_notification, delete_notification, list_notifications
from src.kumaone.notifications import add_notification, delete_notification, list_notifications, list_notification_providers, list_notification_provider_args
from src.kumaone.utils import log_manager, _mutual_exclusivity_check

# Source code meta data
Expand Down Expand Up @@ -125,6 +125,62 @@ def notification_show(
disconnect()


@app.command(name="providers", help="Show all supported uptime kuma notification providers.")
def notification_list_providers(
config_file: Annotated[
Optional[Path], typer.Option(..., "--config", "-c", help="Uptime kuma configuration file path.")
] = Path.home().joinpath(".config/kumaone/kuma.yaml"),
verbose: Annotated[bool, typer.Option(help="Show verbose output.")] = False,
log_level: Annotated[str, typer.Option(help="Set log level.")] = "NOTSET",
):
"""
List all uptime kuma notification provider.
:return: None
"""

if log_level:
state["log_level"] = log_level
logger = log_manager(log_level=log_level)
config_data = check_config(config_path=config_file, logger=logger)
connect_login(config_data=config_data)
list_notification_providers(verbose=verbose, logger=logger)
disconnect()


@app.command(name="provider-args", help="Show all arguments of an uptime kuma notification provider by notification type.")
def notification_show_args(
notificaton_type: Annotated[
str,
typer.Option(
..., "--type", "-t", help="Uptime kuma notification type.", callback=_mutual_exclusivity_check(size=2)
),
] = None,
config_file: Annotated[
Optional[Path], typer.Option(..., "--config", "-c", help="Uptime kuma configuration file path.")
] = Path.home().joinpath(".config/kumaone/kuma.yaml"),
verbose: Annotated[bool, typer.Option(help="Show verbose output.")] = False,
log_level: Annotated[str, typer.Option(help="Set log level.")] = "NOTSET",
):
"""
List all uptime kuma notification provider.
:return: None
"""

if log_level:
state["log_level"] = log_level
logger = log_manager(log_level=log_level)
if notificaton_type is None:
raise typer.BadParameter("Notification type '--type' / '-n' parameter is required.")
config_data = check_config(config_path=config_file, logger=logger)
connect_login(config_data=config_data)
list_notification_provider_args(
verbose=verbose, notification_type=notificaton_type, logger=logger
)
disconnect()


@app.command(name="delete", help="Delete a notification provider.")
def notification_delete(
notifications: Annotated[
Expand Down
34 changes: 34 additions & 0 deletions src/kumaone/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,40 @@ def list_notifications(verbose=None, notification_title=None, notification_id=No
console.print(f":four_leaf_clover: No data available.", style="logging.level.info")


def list_notification_providers(verbose=None, logger=None):
"""
Show list of notification processes
:param verbose: (bool) Enable verbose output.
:param logger: (object) Logging object.
:return: (dict) Dictionary of arguments for a notification provider
"""

table = Table("Supported Providers")
for key in notification_types.keys():
table.add_row(key.lower())
if table.rows:
console.print(table, style="green")


def list_notification_provider_args(verbose=None, notification_type=None, logger=None, check_existence=False):
"""
Show list of notification processes
:param verbose: (bool) Enable verbose output.
:param notification_type: (str) Uptime kuma notification process name.
:param logger: (object) Logging object.
:param check_existence: (bool) Check existence of notification provider by name.
:return: (dict) Dictionary of arguments for a notification provider
"""

table = Table("Argument Key", "Required?")
for key, val in notification_providers[notification_type.lower()].items():
table.add_row(key, str(val["required"]))
if table.rows:
console.print(table, style="green")


def delete_notification(notifications_file_path=None, notification_title=None, logger=None, verbose=None):
"""
Delete a notification provider.
Expand Down

0 comments on commit 80c5b25

Please sign in to comment.