From 853355ea70a4d7a9b8d98050b150b65506c547cc Mon Sep 17 00:00:00 2001 From: Brian P Becker Date: Sat, 6 Apr 2019 02:45:11 -0400 Subject: [PATCH] Allow environment variables in config files --- Core/Boot.dyalog | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Core/Boot.dyalog b/Core/Boot.dyalog index b1937204..0a4700db 100644 --- a/Core/Boot.dyalog +++ b/Core/Boot.dyalog @@ -246,6 +246,35 @@ :If 0=⍴⍴r ⋄ r←⊃r ⋄ :EndIf ∇ + ∇ SubstEnv config;getEnv;subst;n;v + ⍝ substitute environment variables for items with values im the form $envName$ + ⍝ config is a configuration result from ReadConfiguration + ⍝ it should be either a namespace reference, or a vector of namespace references + getEnv←{2 ⎕NQ'.' 'GetEnvironment'⍵} + subst←{ + 0∊⍴⍵:⍵ ⋄ + '$'∧.=(⊣/,⊢/)(2⌈≢⍵)↑⍵:getEnv 1↓¯1↓⍵ ⋄ + ⍵} + :Select ⊃⎕NC'config' + :Case 2 + :If 9.1∧.={⎕NC⊂,'⍵'}¨config + SubstEnv¨config + :EndIf + :Case 9 + :For n :In config.⎕NL ¯2 + :Select ≡v←config⍎n + :Case 1 + v←subst v + :Case 2 + v←subst¨v + :Else + ∘∘∘ + :EndSelect + ⍎'config.',n,'←v' + :EndFor + :EndSelect + ∇ + ∇ config←{element}ReadConfiguration type;serverconfig;file;siteconfig;thing;ind;mask ⍝ Attempt to read configuration file ⍝ 1) from server root MSRoot @@ -278,6 +307,7 @@ config←serverconfig :EndIf :EndIf + :If config≢'' ⋄ SubstEnv config ⋄ :EndIf ∇ ∇ Config←ConfigureServer AppRoot;file