/* Ċ Ġ* ĠCopyright ĠÂ© Ġ 2 0 2 1 ĠPaul ĠAmb rose Ġ( p amb rose @ mac . com ) Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ* Ċ Ġ*/ Ċ Ċ package Ġcom . github . reading bat . common Ċ Ċ import Ġcom . github . p amb rose . common . redis . Redis Utils Ċ import Ġcom . github . p amb rose . common . util . isNotNull Ċ import Ġcom . github . p amb rose . common . util . ob fusc ate Ċ import Ġcom . github . reading bat . common . Constants . UN ASS IGNED Ċ import Ġcom . github . reading bat . common . Property Names . AGENT Ċ import Ġcom . github . reading bat . common . Property Names . CH ALL EN GES Ċ import Ġcom . github . reading bat . common . Property Names . CLASSES Ċ import Ġcom . github . reading bat . common . Property Names . CONTENT Ċ import Ġcom . github . reading bat . common . Property Names . DB MS Ċ import Ġcom . github . reading bat . common . Property Names . READ ING B AT Ċ import Ġcom . github . reading bat . common . Property Names . SITE Ċ import Ġio . ktor . application .* Ċ import Ġio . ktor . config .* Ċ import Ġmu . K Logging Ċ import Ġjava . util . concurrent . atomic . Atomic Boolean Ċ Ċ enum Ġclass ĠProperty ( ĊĠ Ġval Ġproperty Value : ĠString , ĊĠ Ġval Ġmask Func : ĠProperty . () Ġ-> ĠString Ġ= Ġ{ ĠgetProperty ( UN ASS IGNED , Ġfalse ) Ġ} Ċ ) Ġ{ ĊĠ ĠK OT LIN _ SCRIPT _ CLAS SPATH (" kotlin . script . classpath "), ĊĊĠ ĠCONFIG _ FILENAME ("$ READ ING B AT . config Filename "), ĊĠ ĠADMIN _ USERS ("$ READ ING B AT . admin Users "), ĊĠ ĠLO GB ACK _ CONFIG _ FILE (" log back . configuration File "), ĊĠ ĠAG ENT _ LA UNCH _ ID ("$ AGENT . launch Id "), ĊĊĠ ĠAG ENT _ CONFIG (" agent . config "), ĊĊĠ Ġ// ĠThese Ġare Ġused Ġin Ġmodule () ĊĠ ĠDSL _ FILE _ NAME ("$ READ ING B AT .$ CONTENT . fileName "), ĊĠ ĠDSL _ VARIABLE _ NAME ("$ READ ING B AT .$ CONTENT . variable Name "), ĊĠ ĠPRO XY _ HOSTNAME ("$ AGENT . proxy . hostname "), ĊĠ ĠSTART UP _ DELAY _ SE CS ("$ READ ING B AT .$ SITE . startup Max Delay Secs "), ĊĊĠ Ġ// ĠThese Ġare Ġdefaults Ġfor Ġenv Ġvar Ġvalues ĊĠ ĠRED I RECT _ HOSTNAME ("$ READ ING B AT .$ SITE . redirect Hostname "), ĊĠ ĠS END GRID _ PREFIX ("$ READ ING B AT .$ SITE . send Grid Prefix "), ĊĠ ĠFOR WAR DED _ ENABLED ("$ READ ING B AT .$ SITE . for warded Header Support Enabled "), ĊĠ ĠX FOR WAR DED _ ENABLED ("$ READ ING B AT .$ SITE . x for warded Header Support Enabled "), ĊĊĠ Ġ// ĠThese Ġare Ġassigned Ġto ĠReading B at Content Ġvals ĊĠ ĠAN AL YT ICS _ ID ("$ READ ING B AT .$ SITE . google Analytics Id ", Ġ{ ĠgetProperty OrNull ( false ) Ġ?: ĠUN ASS IGNED Ġ}), ĊĠ ĠMAX _ HISTORY _ LENGTH ("$ READ ING B AT .$ CH ALL EN GES . max History Length "), ĊĠ ĠMAX _ CLASS _ COUNT ("$ READ ING B AT .$ CLASSES . max Count "), ĊĠ ĠK TOR _ PORT (" ktor . deployment . port "), ĊĠ ĠK TOR _ WATCH (" ktor . deployment . watch "), ĊĊĠ Ġ// ĠThese Ġare Ġassigned Ġin ĠReading B at Server ĊĠ ĠIS _ PRO DU CTION ("$ READ ING B AT .$ SITE . production "), ĊĠ ĠIS _ TEST ING ("$ READ ING B AT .$ SITE . testing "), ĊĠ ĠDB MS _ ENABLED ("$ READ ING B AT .$ SITE . dbms Enabled "), ĊĠ ĠRED IS _ ENABLED ("$ READ ING B AT .$ SITE . redis Enabled "), ĊĠ ĠSAVE _ REQUEST S _ ENABLED ("$ READ ING B AT .$ SITE . save Requests Enabled "), ĊĠ ĠMULTI _ SERVER _ ENABLED ("$ READ ING B AT .$ SITE . multi Server Enabled "), ĊĠ ĠCONTENT _ C ACH ING _ ENABLED ("$ READ ING B AT .$ SITE . content Caching Enabled "), ĊĠ ĠAG ENT _ ENABLED ("$ AGENT . enabled "), ĊĊĠ ĠP ING DOM _ BAN NER _ ID ("$ READ ING B AT .$ SITE . ping dom Banner Id ", Ġ{ ĠgetProperty OrNull ( false ) Ġ?: ĠUN ASS IGNED Ġ}), ĊĠ ĠP ING DOM _ URL ("$ READ ING B AT .$ SITE . ping dom Url ", Ġ{ ĠgetProperty OrNull ( false ) Ġ?: ĠUN ASS IGNED Ġ}), ĊĠ ĠSTATUS _ PAGE _ URL ("$ READ ING B AT .$ SITE . status Page Url ", Ġ{ ĠgetProperty OrNull ( false ) Ġ?: ĠUN ASS IGNED Ġ}), ĊĊĠ ĠPRO ME THE US _ URL ("$ READ ING B AT . prometheus . url "), ĊĠ ĠGR AF ANA _ URL ("$ READ ING B AT . grafana . url "), ĊĊĠ ĠJAVA _ SCRIP TS _ POOL _ SIZE ("$ READ ING B AT . scripts . java PoolSize "), ĊĠ ĠK OT LIN _ SCRIP TS _ POOL _ SIZE ("$ READ ING B AT . scripts . kotlin PoolSize "), ĊĠ ĠPYTHON _ SCRIP TS _ POOL _ SIZE ("$ READ ING B AT . scripts . python PoolSize "), ĊĊĠ ĠK OT LIN _ EVAL U ATORS _ POOL _ SIZE ("$ READ ING B AT . evalu ators . kotlin PoolSize "), ĊĠ ĠPYTHON _ EVAL U ATORS _ POOL _ SIZE ("$ READ ING B AT . evalu ators . python PoolSize "), ĊĊĠ ĠDB MS _ DRIVER _ CLASS NAME ("$ DB MS . driver ClassName "), ĊĠ ĠDB MS _ URL ("$ DB MS . jdbc Url "), ĊĠ ĠDB MS _ USERNAME ("$ DB MS . username "), ĊĠ ĠDB MS _ PASSWORD ("$ DB MS . password ", Ġ{ ĠgetProperty OrNull ( false )?. ob fusc ate ( 1 ) Ġ?: ĠUN ASS IGNED Ġ}), ĊĠ ĠDB MS _ MAX _ POOL _ SIZE ("$ DB MS . max PoolSize "), ĊĠ ĠDB MS _ MAX _ LI F ETIME _ MIN S ("$ DB MS . max Lifetime M ins "), ĊĊĠ ĠRED IS _ MAX _ POOL _ SIZE ( Redis Utils . REDIS _ MAX _ POOL _ SIZE ), ĊĠ ĠRED IS _ MAX _ IDLE _ SIZE ( Redis Utils . REDIS _ MAX _ IDLE _ SIZE ), ĊĠ ĠRED IS _ MIN _ IDLE _ SIZE ( Redis Utils . REDIS _ MIN _ IDLE _ SIZE ), ĊĠ Ġ; ĊĊĠ Ġprivate Ġfun ĠApplication . config Property ( name : ĠString , Ġdefault : ĠString Ġ= Ġ"", Ġwarn : ĠBoolean Ġ= Ġfalse ) Ġ= ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġenvironment . config . property ( name ). getString () ĊĠĠĠ Ġ} Ġcatch Ġ( e : ĠApplication ConfigurationException ) Ġ{ ĊĠĠĠĠĠ Ġif Ġ( warn ) ĊĠĠĠĠĠĠĠ Ġlogger . warn Ġ{ Ġ" Missing Ġ$ name Ġvalue Ġin Ġapplication . conf " Ġ} ĊĠĠĠĠĠ Ġdefault ĊĠĠĠ Ġ} ĊĊĠ Ġfun Ġconfig Value ( application : ĠApplication , Ġdefault : ĠString Ġ= Ġ"", Ġwarn : ĠBoolean Ġ= Ġfalse ) Ġ= ĊĠĠĠ Ġapplication . config Property ( property Value , Ġdefault , Ġwarn ) ĊĊĠ Ġfun Ġconfig Value OrNull ( application : ĠApplication ) Ġ= ĊĠĠĠ Ġapplication . environment . config . property OrNull ( property Value ) ĊĊĠ Ġfun ĠgetProperty ( default : ĠString , Ġerror On Non Init : ĠBoolean Ġ= Ġtrue ) Ġ= ĊĠĠĠ Ġ( System . getProperty ( property Value ) ĊĠĠĠĠĠ Ġ?: Ġdefault ). also Ġ{ Ġif Ġ( error On Non Init Ġ&& Ġ! initialized . get ()) Ġerror ( not Initialized ( this )) Ġ} ĊĊĠ Ġfun ĠgetProperty ( default : ĠBoolean ) Ġ= Ġ( System . getProperty ( property Value )?. to Boolean () ĊĠĠĠ Ġ?: Ġdefault ). also Ġ{ Ġif Ġ(! initialized . get ()) Ġerror ( not Initialized ( this )) Ġ} ĊĊĠ Ġfun ĠgetProperty ( default : ĠInt ) Ġ= Ġ( System . getProperty ( property Value )?. toInt OrNull () ĊĠĠĠ Ġ?: Ġdefault ). also Ġ{ Ġif Ġ(! initialized . get ()) Ġerror ( not Initialized ( this )) Ġ} ĊĊĠ Ġfun ĠgetProperty OrNull ( error On Non Init : ĠBoolean Ġ= Ġtrue ): ĠString ? Ġ= ĊĠĠĠ ĠSystem . getProperty ( property Value ). also Ġ{ Ġif Ġ( error On Non Init Ġ&& Ġ! initialized . get ()) Ġerror ( not Initialized ( this )) Ġ} ĊĊĠ Ġfun Ġget Required Property () Ġ= Ġ( getProperty OrNull () ĊĠĠĠ Ġ?: Ġerror (" Missing Ġ$ property Value Ġvalue ")). also Ġ{ Ġif Ġ(! initialized . get ()) Ġerror ( not Initialized ( this )) Ġ} ĊĊĠ Ġfun Ġset Property ( value : ĠString ) Ġ{ ĊĠĠĠ ĠSystem . setProperty ( property Value , Ġvalue ) ĊĠĠĠ Ġlogger . info Ġ{ Ġ"$ property Value : Ġ${ mask Func () }" Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġset Property From Config ( application : ĠApplication , Ġdefault : ĠString ) Ġ{ ĊĠĠĠ Ġif Ġ( isNot Defined ()) ĊĠĠĠĠĠ Ġset Property ( config Value ( application , Ġdefault )) ĊĠ Ġ} ĊĊĠ Ġfun Ġis Defined () Ġ= ĠSystem . getProperty ( property Value ). isNotNull () ĊĠ Ġfun Ġis Not Defined () Ġ= Ġ! isDefined () ĊĊĠ Ġcompanion Ġobject Ġ: ĠK Logging () Ġ{ ĊĠĠĠ Ġprivate Ġval Ġinitialized Ġ= ĠAtomic Boolean ( false ) ĊĊĠĠĠ Ġfun Ġassign Initialized () Ġ= Ġinitialized . set ( true ) ĊĊĠĠĠ Ġprivate Ġfun Ġnot Initialized ( prop : ĠProperty ) Ġ= Ġ" Property Ġ${ prop . name } Ġnot Ġinitialized " ĊĊĠĠĠ Ġinternal Ġfun ĠApplication . assign Properties () Ġ{ ĊĊĠĠĠĠĠ Ġval Ġagent Enabled Ġ= ĊĠĠĠĠĠĠĠ ĠEnv Var . AGENT _ ENABLED . get Env ( AGENT _ ENABLED . config Value ( this , Ġdefault Ġ= Ġ" false "). to Boolean ()) ĊĠĠĠĠĠ ĠAG ENT _ ENABLED . setProperty ( agent Enabled . toString ()) ĊĠĠĠĠĠ ĠPRO XY _ HOSTNAME . setProperty From Config ( this , Ġ"") ĊĊĠĠĠĠĠ ĠIS _ PRO DU CTION . also Ġ{ Ġit . setProperty ( it . config Value ( this , Ġ" false "). to Boolean (). toString ()) Ġ} ĊĊĠĠĠĠĠ ĠDB MS _ ENABLED . also Ġ{ Ġit . setProperty ( it . config Value ( this , Ġ" false "). to Boolean (). toString ()) Ġ} ĊĠĠĠĠĠ ĠRED IS _ ENABLED . also Ġ{ Ġit . setProperty ( it . config Value ( this , Ġ" false "). to Boolean (). toString ()) Ġ} ĊĊĠĠĠĠĠ ĠSAVE _ REQUEST S _ ENABLED . also Ġ{ Ġit . setProperty ( it . config Value ( this , Ġ" true "). to Boolean (). toString ()) Ġ} ĊĊĠĠĠĠĠ ĠMULTI _ SERVER _ ENABLED . also Ġ{ Ġit . setProperty ( it . config Value ( this , Ġ" false "). to Boolean (). toString ()) Ġ} ĊĊĠĠĠĠĠ ĠCONTENT _ C ACH ING _ ENABLED . also Ġ{ Ġit . setProperty ( it . config Value ( this , Ġ" false "). to Boolean (). toString ()) Ġ} ĊĊĠĠĠĠĠ ĠDSL _ FILE _ NAME . setProperty From Config ( this , Ġ" src / Content . kt ") ĊĠĠĠĠĠ ĠDSL _ VARIABLE _ NAME . setProperty From Config ( this , Ġ" content ") ĊĊĠĠĠĠĠ ĠAN AL YT ICS _ ID . setProperty From Config ( this , Ġ"") ĊĊĠĠĠĠĠ ĠP ING DOM _ BAN NER _ ID . setProperty From Config ( this , Ġ"") ĊĠĠĠĠĠ ĠP ING DOM _ URL . setProperty From Config ( this , Ġ"") ĊĠĠĠĠĠ ĠSTATUS _ PAGE _ URL . setProperty From Config ( this , Ġ"") ĊĊĠĠĠĠĠ ĠPRO ME THE US _ URL . setProperty From Config ( this , Ġ"") ĊĠĠĠĠĠ ĠGR AF ANA _ URL . setProperty From Config ( this , Ġ"") ĊĊĠĠĠĠĠ ĠJAVA _ SCRIP TS _ POOL _ SIZE . setProperty From Config ( this , Ġ" 5 ") ĊĠĠĠĠĠ ĠK OT LIN _ SCRIP TS _ POOL _ SIZE . setProperty From Config ( this , Ġ" 5 ") ĊĠĠĠĠĠ ĠPYTHON _ SCRIP TS _ POOL _ SIZE . setProperty From Config ( this , Ġ" 5 ") ĊĊĠĠĠĠĠ ĠK OT LIN _ EVAL U ATORS _ POOL _ SIZE . setProperty From Config ( this , Ġ" 5 ") ĊĠĠĠĠĠ ĠPYTHON _ EVAL U ATORS _ POOL _ SIZE . setProperty From Config ( this , Ġ" 5 ") ĊĊĠĠĠĠĠ ĠDB MS _ DRIVER _ CLASS NAME . setProperty From Config ( this , Ġ" com . imp oss ib l . postgres . jdbc . PG Driver ") ĊĠĠĠĠĠ ĠDB MS _ URL . setProperty From Config ( this , Ġ" jdbc : pgsql :// localhost : 5 4 3 2 / reading bat ") ĊĠĠĠĠĠ ĠDB MS _ USERNAME . setProperty From Config ( this , Ġ" postgres ") ĊĠĠĠĠĠ ĠDB MS _ PASSWORD . setProperty From Config ( this , Ġ"") ĊĠĠĠĠĠ ĠDB MS _ MAX _ POOL _ SIZE . setProperty From Config ( this , Ġ" 1 0 ") ĊĠĠĠĠĠ ĠDB MS _ MAX _ LI F ETIME _ MIN S . setProperty From Config ( this , Ġ" 3 0 ") ĊĊĠĠĠĠĠ ĠRED IS _ MAX _ POOL _ SIZE . setProperty From Config ( this , Ġ" 1 0 ") ĊĠĠĠĠĠ ĠRED IS _ MAX _ IDLE _ SIZE . setProperty From Config ( this , Ġ" 5 ") ĊĠĠĠĠĠ ĠRED IS _ MIN _ IDLE _ SIZE . setProperty From Config ( this , Ġ" 1 ") ĊĊĠĠĠĠĠ ĠK TOR _ PORT . setProperty From Config ( this , Ġ" 0 ") ĊĠĠĠĠĠ ĠK TOR _ WATCH . also Ġ{ Ġit . setProperty ( it . config Value OrNull ( this )?. getList ()?. toString () Ġ?: ĠUN ASS IGNED ) Ġ} ĊĊĠĠĠĠĠ ĠS END GRID _ PREFIX . also Ġ{ ĊĠĠĠĠĠĠĠ Ġit . setProperty ( ĊĠĠĠĠĠĠĠĠĠ ĠEnv Var . SEND GRID _ PREFIX . get Env ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġit . config Value ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthis , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" https :// www . reading bat . com " ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġassign Initialized () ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ }