feat: add host, password and username handling

This commit is contained in:
sinavir 2024-04-21 11:39:10 +02:00
parent ae50084fcb
commit 456f923905
2 changed files with 32 additions and 5 deletions

View file

@ -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[@]}"
'';
};
};

View file

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