~singpolyma/sgx-jmp

c407d89ceb9ad384a34af3bbd09170adbbdcf496 — Stephen Paul Weber 3 years ago 39131ba
Check config against schema when loading

So we know very quickly why it's not working.
4 files changed, 53 insertions(+), 2 deletions(-)

A Makefile
A config-schema.dhall
M config.dhall.sample
M sgx_jmp.rb
A Makefile => Makefile +2 -0
@@ 0,0 1,2 @@
config-schema.dhall: config.dhall.sample
	dhall type < config.dhall.sample > config-schema.dhall

A config-schema.dhall => config-schema.dhall +46 -0
@@ 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 }
}

M config.dhall.sample => config.dhall.sample +1 -1
@@ 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",

M sgx_jmp.rb => sgx_jmp.rb +4 -1
@@ 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