From aaae59ced0fa98752b0fac444d7223a4e5004eba Mon Sep 17 00:00:00 2001 From: swrup Date: Mon, 13 Oct 2025 00:29:33 +0200 Subject: [PATCH] wip: better config --- src/assets.ml | 17 +++++++++-------- src/config.ml | 28 +++++++--------------------- src/config_mte.ml | 19 +++++++++++++++++++ src/headers.ml | 6 +++--- src/mte.ml | 2 +- src/util.ml | 2 +- 6 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 src/config_mte.ml diff --git a/src/assets.ml b/src/assets.ml index 4ec1b634..cf1ed97b 100644 --- a/src/assets.ml +++ b/src/assets.ml @@ -13,16 +13,16 @@ type t = | Privacy let etag = function - | Terms -> Config.terms_etag - | Privacy -> Config.privacy_etag + | Terms -> Config_mte.terms_etag + | Privacy -> Config_mte.privacy_etag let legal_version = function - | Terms -> Config.terms_legal_version - | Privacy -> Config.privacy_legal_version + | Terms -> Config_mte.terms_legal_version + | Privacy -> Config_mte.privacy_legal_version let base_dir = function - | Terms -> Config.terms_dir - | Privacy -> Config.privacy_dir + | Terms -> Config_mte.terms_dir + | Privacy -> Config_mte.privacy_dir (* TODO better use of Fmt to have error prefix or smthing @@ -55,8 +55,9 @@ let supported_lang_arr, supported_ext_arr = let () = if List.is_empty lang_l then Fmt.failwith "no language supported"; if List.is_empty ext_l then Fmt.failwith "no mimetype supported"; - if not @@ List.mem Config.default_lang lang_l then - Fmt.failwith "default language `%s` files not found" Config.default_lang; + if not @@ List.mem Config_mte.default_lang lang_l then + Fmt.failwith "default language `%s` files not found" + Config_mte.default_lang; if not @@ List.mem ".txt" ext_l then Fmt.failwith "plain text file not found"; if not @@ List.mem ".md" ext_l then Fmt.failwith "markdown file not found"; diff --git a/src/config.ml b/src/config.ml index 08fff141..07fc8cca 100644 --- a/src/config.ml +++ b/src/config.ml @@ -1,24 +1,11 @@ -(* https://docs.taler.net/manpages/taler-exchange.conf.5.html#exchange-options *) +(* https://docs.taler.net/manpages/taler-exchange.conf.5.html + taler-docs/manpages/taler-exchange.conf.5.rst *) (* TODO - generate `config.ml` from config file (virtual module)? - - no relative path *) - -let default_lang = "en" -let default_encoding : [< `Identity | `DEFLATE | `Gzip ] = `Identity - -(* TODO Taler documentation markdown mimetype should be the prefered one, and be - supported, according to DD we take text/plain as default instead for now *) -let default_mimetype = ("text", "plain") -let default_extension = ".txt" -let terms_dir = Fpath.(v "terms") -let privacy_dir = Fpath.(v "privacy") - -(* ETAG is used as base filename it should be encoded in Crockford base-32 we do - not generate it and we do not verify it *) -let terms_etag = "0" |> Headers_lib.Etag.of_crockford32 |> Result.get_ok -let privacy_etag = "0" |> Headers_lib.Etag.of_crockford32 |> Result.get_ok -let terms_legal_version = "1" -let privacy_legal_version = "1" + - parse config file format + - no relative path + - default config: use relevant duration, all set to 1 year for now + *) (* ---- *) let currency = `Eur @@ -37,8 +24,7 @@ let currency_round_unit = { currency= `Eur; value= 0; fraction= 1 } let value_to_string v = Fmt.str "%s:%d.%d" (currency_to_string v.currency) v.value v.fraction -(* todo: use relevant duration, all set to 1 year for now *) - +(* https://docs.taler.net/manpages/taler-exchange.conf.5.html#exchange-coin-options *) module Coin = struct (* How much is the coin worth, the format is CURRENCY:VALUE.FRACTION. For example, a 10 cent piece is “EUR:0.10”. *) diff --git a/src/config_mte.ml b/src/config_mte.ml new file mode 100644 index 00000000..b03e00c7 --- /dev/null +++ b/src/config_mte.ml @@ -0,0 +1,19 @@ +(* config_mte.ml + config value that are not in official config options *) + +let default_lang = "en" +let default_encoding : [< `Identity | `DEFLATE | `Gzip ] = `Identity + +(* TODO Taler documentation markdown mimetype should be the prefered one, and be + supported, according to DD we take text/plain as default instead for now *) +let default_mimetype = ("text", "plain") +let default_extension = ".txt" +let terms_dir = Fpath.(v "terms") +let privacy_dir = Fpath.(v "privacy") + +(* ETAG is used as base filename it should be encoded in Crockford base-32 we do + not generate it and we do not verify it *) +let terms_etag = "0" |> Headers_lib.Etag.of_crockford32 |> Result.get_ok +let privacy_etag = "0" |> Headers_lib.Etag.of_crockford32 |> Result.get_ok +let terms_legal_version = "1" +let privacy_legal_version = "1" diff --git a/src/headers.ml b/src/headers.ml index 7c6525f0..7283a84d 100644 --- a/src/headers.ml +++ b/src/headers.ml @@ -19,14 +19,14 @@ let select_language headers = |> Cohttp.Accept.qsort |> List.map (fun (_q, lang) -> lang) |> List.map (function - | Cohttp.Accept.AnyLanguage -> Config.default_lang + | Cohttp.Accept.AnyLanguage -> Config_mte.default_lang | Language language_range -> ( (* ignore language subtags (e.g. "en-US" -> "en") *) match language_range with | [] -> assert false | primary_tag :: _ -> primary_tag)) |> List.find_opt Assets.is_supported_lang - |> Option.value ~default:Config.default_lang + |> Option.value ~default:Config_mte.default_lang let select_encoding headers = Vif.Headers.get headers "accept-encoding" @@ -37,7 +37,7 @@ let select_encoding headers = | Cohttp.Accept.Identity -> Some `Identity | Deflate -> Some `DEFLATE | Gzip -> Some `Gzip - | AnyEncoding -> Some Config.default_encoding + | AnyEncoding -> Some Config_mte.default_encoding | Encoding _ | Compress -> (* unsupported *) None) |> function | [] -> assert false diff --git a/src/mte.ml b/src/mte.ml index 8c013b47..f94ad473 100644 --- a/src/mte.ml +++ b/src/mte.ml @@ -83,7 +83,7 @@ module Static = struct in let* () = (* todo: is it "taler-privacy-version" for /policy ? *) - add ~field:"taler-terms-version" Config.terms_legal_version + add ~field:"taler-terms-version" Config_mte.terms_legal_version in let* () = add ~field:"avail-languages" Headers.avail_languages_header_value diff --git a/src/util.ml b/src/util.ml index 047ffc7e..18436a1a 100644 --- a/src/util.ml +++ b/src/util.ml @@ -24,7 +24,7 @@ module Mimetype = struct List.find_opt (( = ) (m, m_sub)) mimetype_l | AnyMediaSubtype m -> List.find_opt (fun (m', _) -> String.equal m m') mimetype_l - | AnyMedia -> Some Config.default_mimetype + | AnyMedia -> Some Config_mte.default_mimetype let to_extension (m, m_sub) = assert (m <> "*");