From c407d89ceb9ad384a34af3bbd09170adbbdcf496 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 11 Aug 2021 14:35:28 -0500 Subject: [PATCH] Check config against schema when loading So we know very quickly why it's not working. --- Makefile | 2 ++ config-schema.dhall | 46 +++++++++++++++++++++++++++++++++++++++++++++ config.dhall.sample | 2 +- sgx_jmp.rb | 5 ++++- 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 Makefile create mode 100644 config-schema.dhall diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..577624e --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +config-schema.dhall: config.dhall.sample + dhall type < config.dhall.sample > config-schema.dhall diff --git a/config-schema.dhall b/config-schema.dhall new file mode 100644 index 0000000..08696aa --- /dev/null +++ b/config-schema.dhall @@ -0,0 +1,46 @@ +{ activation_amount : Natural +, adr : Text +, bandwidth_peer : Text +, bandwidth_site : Text +, braintree : + { environment : Text + , merchant_accounts : { CAD : Text, USD : Text } + , merchant_id : Text + , private_key : Text + , public_key : Text + } +, catapult : + { application_id : Text + , domain : Text + , secret : Text + , sip_host : Text + , token : Text + , user : Text + } +, component : { jid : Text, secret : Text } +, credit_card_url : forall (jid : Text) -> forall (customer_id : Text) -> Text +, creds : { account : Text, password : Text, username : Text } +, electrum : { rpc_password : Text, rpc_uri : Text, rpc_username : Text } +, electrum_notify_url : + forall (address : Text) -> forall (customer_id : Text) -> Text +, interac : Text +, notify_admin : Text +, notify_from : Text +, oxr_app_id : Text +, payable : Text +, plans : + List + { currency : < CAD | USD > + , messages : + < limited : { included : Natural, price : Natural } | unlimited > + , minutes : + < limited : { included : Natural, price : Natural } | unlimited > + , monthly_price : Natural + , name : Text + } +, server : { host : Text, port : Natural } +, sgx : Text +, sip_host : Text +, web_register : { from : Text, to : Text } +, xep0157 : List { label : Text, value : Text, var : Text } +} diff --git a/config.dhall.sample b/config.dhall.sample index 421a1ae..149e619 100644 --- a/config.dhall.sample +++ b/config.dhall.sample @@ -38,7 +38,7 @@ } }, xep0157 = [ - { var = "support-addresses", value = "xmpp:+14169938000@cheogram.com" } + { var = "support-addresses", value = "xmpp:+14169938000@cheogram.com", label = "Support" } ], notify_admin = "muc@example.com", sip_host = "sip.jmp.chat", diff --git a/sgx_jmp.rb b/sgx_jmp.rb index 43ece2f..20f0543 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -48,7 +48,10 @@ LOG.extend SentryOugai CONFIG = Dhall::Coder .new(safe: Dhall::Coder::JSON_LIKE + [Symbol, Proc]) - .load(ARGV[0], transform_keys: ->(k) { k&.to_sym }) + .load( + "(#{ARGV[0]}) : #{__dir__}/config-schema.dhall", + transform_keys: ->(k) { k&.to_sym } + ) singleton_class.class_eval do include Blather::DSL -- 2.38.5