Check config against schema when loading

Stephen Paul Weber created

So we know very quickly why it's not working.

Change summary

Makefile            |  2 ++
config-schema.dhall | 46 ++++++++++++++++++++++++++++++++++++++++++++++
config.dhall.sample |  2 +-
sgx_jmp.rb          |  5 ++++-
4 files changed, 53 insertions(+), 2 deletions(-)

Detailed changes

Makefile 🔗

@@ -0,0 +1,2 @@
+config-schema.dhall: config.dhall.sample
+	dhall type < config.dhall.sample > config-schema.dhall

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 }
+}

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",

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