From 456f9239051d12e920b4ffdb3876c6a9950ab509 Mon Sep 17 00:00:00 2001 From: sinavir Date: Sun, 21 Apr 2024 11:39:10 +0200 Subject: [PATCH] feat: add host, password and username handling --- nixos/module.nix | 8 +++++++- stateless_uptime_kuma/cli.py | 29 +++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/nixos/module.nix b/nixos/module.nix index dbee0ad..ee01bea 100644 --- a/nixos/module.nix +++ b/nixos/module.nix @@ -14,6 +14,10 @@ in json = lib.mkOption { type = lib.types.package; }; script = lib.mkOption { type = lib.types.package; }; }; + host = lib.mkOption { + default = null; + type = with lib.types; nullOr str; + }; extraFlags = lib.mkOption { default = [ ]; example = [ "--scrape-http-keywords" ]; @@ -40,13 +44,15 @@ in }; config.statelessUptimeKuma = { lib = import ../lib { inherit lib; }; + extraFlags = lib.optional (cfg.host != null) "--host ${cfg.host}"; build = { json = probesFormat.generate "probes.json" cfg.probesConfig; script = pkgs.writeShellApplication { name = "deploy-uptime-kuma-probes"; runtimeInputs = [ pkgs.statelessUptimeKuma ]; text = '' - stateless-uptime-kuma apply-json -f ${cfg.build.json} ${builtins.concatStringsSep " " cfg.extraFlags} + args=("$@") + stateless-uptime-kuma apply-json -f ${cfg.build.json} ${builtins.concatStringsSep " " cfg.extraFlags} "''${args[@]}" ''; }; }; diff --git a/stateless_uptime_kuma/cli.py b/stateless_uptime_kuma/cli.py index d003740..7fb37c8 100644 --- a/stateless_uptime_kuma/cli.py +++ b/stateless_uptime_kuma/cli.py @@ -47,14 +47,35 @@ def cli(): help="Don't automatically create tags if not in tags section of input", default=False, ) -def apply_json(file, scrape_http_keywords, no_autocreate_tags, keywords_fallback): +@click.option( + "--username", + prompt=True, +) +@click.option( + "--host", + prompt=True, +) +@click.option( + "--password", + prompt=True, + hide_input=True, +) +def apply_json( + file, + scrape_http_keywords, + no_autocreate_tags, + keywords_fallback, + username, + password, + host, +): """ Apply json probes """ logger.debug( f"Flags value:\n - scrape_http_keywords: {scrape_http_keywords}\n - no_autocreate_tags: {no_autocreate_tags}\n - keywords_fallback: {keywords_fallback}" ) - with UptimeKumaApi("http://localhost:3001") as api: + with UptimeKumaApi(host) as api: logging.debug("Reading json") data = json.load(file) logging.debug("Parsing json") @@ -62,9 +83,9 @@ def apply_json(file, scrape_http_keywords, no_autocreate_tags, keywords_fallback if scrape_http_keywords: hydrate_http_probes(tree) logging.debug("Sync probes") - api.login("admin", "123456789a") + api.login(username, password) Manager(api, tree).process() if __name__ == "__main__": - cli() + cli(auto_envvar_prefix="STATELESS_UPTIME_KUMA")