% ==============================
% Credentials Obfuscation schema
% ==============================

{mapping, "credentials_obfuscation.enabled", "credentials_obfuscation.enabled",
   [{datatype, {enum, [true, false]}}]}.

{mapping, "credentials_obfuscation.cipher", "credentials_obfuscation.cipher",
   [{datatype, atom}]}.

{translation, "credentials_obfuscation.cipher",
fun(Conf) ->
    case cuttlefish:conf_get("credentials_obfuscation.cipher", Conf, undefined) of
        undefined -> cuttlefish:unset();
        Setting ->
            case
                lists:member(Setting,
                             credentials_obfuscation_pbe:supported_ciphers())
            of
                true ->
                    Setting;
                false ->
                    cuttlefish:invalid("Unsupported cipher")
            end
    end
end}.


{mapping, "credentials_obfuscation.hash", "credentials_obfuscation.hash",
   [{datatype, atom}]}.

{translation, "credentials_obfuscation.hash",
fun(Conf) ->
    case cuttlefish:conf_get("credentials_obfuscation.hash", Conf, undefined) of
        undefined -> cuttlefish:unset();
        Setting ->
            case
                lists:member(Setting,
                             credentials_obfuscation_pbe:supported_hashes())
            of
                true ->
                    Setting;
                false ->
                    cuttlefish:invalid("Unsupported hash")
            end
    end
end}.

{mapping, "credentials_obfuscation.iterations", "credentials_obfuscation.iterations",
   [{datatype, integer}, {validators, ["non_zero_positive_integer"]}]}.

{validator, "non_zero_positive_integer", "number should be greater or equal to one",
fun(Int) when is_integer(Int) ->
    Int >= 1
end}.
