prometheus-exporter-nextcloud: require either tokenFile or passwordFile

follow-up on 28b3156bc6774f11e203151094bade34cba11fef which broke
when tokenFile was left empty.

Making both options nullable also allows us to provide a more meaningful
error message when neither authentication method is configured.
This commit is contained in:
Arnout Engelen 2023-09-11 16:00:51 +02:00
parent 3a2786eea0
commit 1bf360af28
No known key found for this signature in database
GPG key ID: 061107B0F74A6DAA
2 changed files with 17 additions and 6 deletions

View file

@ -303,6 +303,14 @@ in
The exporter is configured to run as 'services.mysql.user', but
'services.mysql.enable' is set to false.
'';
} {
assertion = cfg.nextcloud.enable -> (
(cfg.nextcloud.passwordFile == null) != (cfg.nextcloud.tokenFile == null)
);
message = ''
Please specify either 'services.prometheus.exporters.nextcloud.passwordFile' or
'services.prometheus.exporters.nextcloud.tokenFile'
'';
} {
assertion = cfg.sql.enable -> (
(cfg.sql.configFile == null) != (cfg.sql.configuration == null)

View file

@ -23,10 +23,12 @@ in
description = lib.mdDoc ''
Username for connecting to Nextcloud.
Note that this account needs to have admin privileges in Nextcloud.
Unused when using token authentication.
'';
};
passwordFile = mkOption {
type = types.path;
type = types.nullOr types.path;
default = null;
example = "/path/to/password-file";
description = lib.mdDoc ''
File containing the password for connecting to Nextcloud.
@ -34,9 +36,9 @@ in
'';
};
tokenFile = mkOption {
type = types.path;
type = types.nullOr types.path;
default = null;
example = "/path/to/token-file";
default = "";
description = lib.mdDoc ''
File containing the token for connecting to Nextcloud.
Make sure that this file is readable by the exporter user.
@ -58,12 +60,13 @@ in
--addr ${cfg.listenAddress}:${toString cfg.port} \
--timeout ${cfg.timeout} \
--server ${cfg.url} \
${if cfg.tokenFile == "" then ''
${if cfg.passwordFile != null then ''
--username ${cfg.username} \
--password ${escapeShellArg "@${cfg.passwordFile}"} \
'' else ''
'' else ''
--auth-token ${escapeShellArg "@${cfg.tokenFile}"} \
''} ${concatStringsSep " \\\n " cfg.extraFlags}'';
''} \
${concatStringsSep " \\\n " cfg.extraFlags}'';
};
};
}