fix(lib/k8s): mkSecretOption, improve errors if name or key not passed

This commit is contained in:
Jaka Hudoklin 2020-01-15 09:52:39 +00:00
parent dc200f8484
commit c8c2f69cc4
No known key found for this signature in database
GPG key ID: 11AA2A62319E4968

View file

@ -3,27 +3,29 @@
with lib; with lib;
rec { rec {
# TODO: refactor into mkOptionType
mkSecretOption = {description ? "", default ? {}, allowNull ? true}: mkOption { mkSecretOption = {description ? "", default ? {}, allowNull ? true}: mkOption {
inherit description; inherit description;
type = (if allowNull then types.nullOr else id) (types.submodule { type = (if allowNull then types.nullOr else id) (types.submodule {
options = { options = {
name = mkOption { name = mkOption ({
description = "Name of the secret where secret is stored"; description = "Name of the secret where secret is stored";
type = types.str; type = types.str;
default = default.name or null; default = default.name;
}; } // (optionalAttrs (default ? "name") {
default = default.name;
}));
key = mkOption { key = mkOption ({
description = "Name of the key where secret is stored"; description = "Name of the key where secret is stored";
type = types.str; type = types.str;
default = default.key or null; } // (optionalAttrs (default ? "key") {
}; default = default.key;
}));
}; };
}); });
default = {}; default = if default == null then null else {};
} // (optionalAttrs (default == null) { };
default = null;
}));
secretToEnv = value: { secretToEnv = value: {
valueFrom.secretKeyRef = { valueFrom.secretKeyRef = {