wip: better config
This commit is contained in:
parent
be2e590e93
commit
aaae59ced0
6 changed files with 40 additions and 34 deletions
|
|
@ -13,16 +13,16 @@ type t =
|
||||||
| Privacy
|
| Privacy
|
||||||
|
|
||||||
let etag = function
|
let etag = function
|
||||||
| Terms -> Config.terms_etag
|
| Terms -> Config_mte.terms_etag
|
||||||
| Privacy -> Config.privacy_etag
|
| Privacy -> Config_mte.privacy_etag
|
||||||
|
|
||||||
let legal_version = function
|
let legal_version = function
|
||||||
| Terms -> Config.terms_legal_version
|
| Terms -> Config_mte.terms_legal_version
|
||||||
| Privacy -> Config.privacy_legal_version
|
| Privacy -> Config_mte.privacy_legal_version
|
||||||
|
|
||||||
let base_dir = function
|
let base_dir = function
|
||||||
| Terms -> Config.terms_dir
|
| Terms -> Config_mte.terms_dir
|
||||||
| Privacy -> Config.privacy_dir
|
| Privacy -> Config_mte.privacy_dir
|
||||||
|
|
||||||
(* TODO
|
(* TODO
|
||||||
better use of Fmt to have error prefix or smthing
|
better use of Fmt to have error prefix or smthing
|
||||||
|
|
@ -55,8 +55,9 @@ let supported_lang_arr, supported_ext_arr =
|
||||||
let () =
|
let () =
|
||||||
if List.is_empty lang_l then Fmt.failwith "no language supported";
|
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 List.is_empty ext_l then Fmt.failwith "no mimetype supported";
|
||||||
if not @@ List.mem Config.default_lang lang_l then
|
if not @@ List.mem Config_mte.default_lang lang_l then
|
||||||
Fmt.failwith "default language `%s` files not found" Config.default_lang;
|
Fmt.failwith "default language `%s` files not found"
|
||||||
|
Config_mte.default_lang;
|
||||||
if not @@ List.mem ".txt" ext_l then
|
if not @@ List.mem ".txt" ext_l then
|
||||||
Fmt.failwith "plain text file not found";
|
Fmt.failwith "plain text file not found";
|
||||||
if not @@ List.mem ".md" ext_l then Fmt.failwith "markdown file not found";
|
if not @@ List.mem ".md" ext_l then Fmt.failwith "markdown file not found";
|
||||||
|
|
|
||||||
|
|
@ -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
|
(* TODO
|
||||||
- generate `config.ml` from config file (virtual module)?
|
- generate `config.ml` from config file (virtual module)?
|
||||||
- no relative path *)
|
- parse config file format
|
||||||
|
- no relative path
|
||||||
let default_lang = "en"
|
- default config: use relevant duration, all set to 1 year for now
|
||||||
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"
|
|
||||||
|
|
||||||
(* ---- *)
|
(* ---- *)
|
||||||
let currency = `Eur
|
let currency = `Eur
|
||||||
|
|
@ -37,8 +24,7 @@ let currency_round_unit = { currency= `Eur; value= 0; fraction= 1 }
|
||||||
let value_to_string v =
|
let value_to_string v =
|
||||||
Fmt.str "%s:%d.%d" (currency_to_string v.currency) v.value v.fraction
|
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
|
module Coin = struct
|
||||||
(* How much is the coin worth, the format is CURRENCY:VALUE.FRACTION. For
|
(* How much is the coin worth, the format is CURRENCY:VALUE.FRACTION. For
|
||||||
example, a 10 cent piece is “EUR:0.10”. *)
|
example, a 10 cent piece is “EUR:0.10”. *)
|
||||||
|
|
|
||||||
19
src/config_mte.ml
Normal file
19
src/config_mte.ml
Normal file
|
|
@ -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"
|
||||||
|
|
@ -19,14 +19,14 @@ let select_language headers =
|
||||||
|> Cohttp.Accept.qsort
|
|> Cohttp.Accept.qsort
|
||||||
|> List.map (fun (_q, lang) -> lang)
|
|> List.map (fun (_q, lang) -> lang)
|
||||||
|> List.map (function
|
|> List.map (function
|
||||||
| Cohttp.Accept.AnyLanguage -> Config.default_lang
|
| Cohttp.Accept.AnyLanguage -> Config_mte.default_lang
|
||||||
| Language language_range -> (
|
| Language language_range -> (
|
||||||
(* ignore language subtags (e.g. "en-US" -> "en") *)
|
(* ignore language subtags (e.g. "en-US" -> "en") *)
|
||||||
match language_range with
|
match language_range with
|
||||||
| [] -> assert false
|
| [] -> assert false
|
||||||
| primary_tag :: _ -> primary_tag))
|
| primary_tag :: _ -> primary_tag))
|
||||||
|> List.find_opt Assets.is_supported_lang
|
|> List.find_opt Assets.is_supported_lang
|
||||||
|> Option.value ~default:Config.default_lang
|
|> Option.value ~default:Config_mte.default_lang
|
||||||
|
|
||||||
let select_encoding headers =
|
let select_encoding headers =
|
||||||
Vif.Headers.get headers "accept-encoding"
|
Vif.Headers.get headers "accept-encoding"
|
||||||
|
|
@ -37,7 +37,7 @@ let select_encoding headers =
|
||||||
| Cohttp.Accept.Identity -> Some `Identity
|
| Cohttp.Accept.Identity -> Some `Identity
|
||||||
| Deflate -> Some `DEFLATE
|
| Deflate -> Some `DEFLATE
|
||||||
| Gzip -> Some `Gzip
|
| Gzip -> Some `Gzip
|
||||||
| AnyEncoding -> Some Config.default_encoding
|
| AnyEncoding -> Some Config_mte.default_encoding
|
||||||
| Encoding _ | Compress -> (* unsupported *) None)
|
| Encoding _ | Compress -> (* unsupported *) None)
|
||||||
|> function
|
|> function
|
||||||
| [] -> assert false
|
| [] -> assert false
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ module Static = struct
|
||||||
in
|
in
|
||||||
let* () =
|
let* () =
|
||||||
(* todo: is it "taler-privacy-version" for /policy ? *)
|
(* 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
|
in
|
||||||
let* () =
|
let* () =
|
||||||
add ~field:"avail-languages" Headers.avail_languages_header_value
|
add ~field:"avail-languages" Headers.avail_languages_header_value
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ module Mimetype = struct
|
||||||
List.find_opt (( = ) (m, m_sub)) mimetype_l
|
List.find_opt (( = ) (m, m_sub)) mimetype_l
|
||||||
| AnyMediaSubtype m ->
|
| AnyMediaSubtype m ->
|
||||||
List.find_opt (fun (m', _) -> String.equal m m') mimetype_l
|
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) =
|
let to_extension (m, m_sub) =
|
||||||
assert (m <> "*");
|
assert (m <> "*");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue