44using System . Linq ;
55using System . Reflection ;
66using Newtonsoft . Json . Linq ;
7+ using System . Text . RegularExpressions ;
78using StackifyLib . Utils ;
89
910namespace StackifyLib
@@ -117,6 +118,26 @@ public static void LoadSettings()
117118 LoggingJsonMaxFields = maxFields ;
118119 }
119120 }
121+
122+ var rumScriptUrl = Get ( "Stackify.Rum_Script_Url" , "https://stckjs.stackify.com/stckjs.js" ) ;
123+
124+ if ( Uri . IsWellFormedUriString ( rumScriptUrl , UriKind . Absolute ) )
125+ {
126+ var uri = new Uri ( rumScriptUrl ) ;
127+
128+ var scheme = uri . Scheme ;
129+
130+ if ( string . Equals ( scheme , "https" , StringComparison . OrdinalIgnoreCase ) )
131+ {
132+ RumScriptUrl = rumScriptUrl ;
133+ }
134+ }
135+
136+ var rumKey = Get ( "Stackify.Rum_Key" ) ;
137+ if ( Regex . IsMatch ( rumKey , "^[A-Za-z0-9_-]+$" ) )
138+ {
139+ RumKey = rumKey ;
140+ }
120141 }
121142 catch ( Exception ex )
122143 {
@@ -161,6 +182,10 @@ public static void LoadSettings()
161182
162183 public static bool ? IsStackifyJsonLoaded { get ; set ; } = false ;
163184
185+ public static string RumScriptUrl { get ; set ; }
186+
187+ public static string RumKey { get ; set ; }
188+
164189
165190 /// <summary>
166191 /// Attempts to fetch a setting value given the key.
@@ -189,8 +214,13 @@ internal static string Get(string key, string defaultValue = null)
189214 var key2 = key . Replace ( "Stackify." , string . Empty ) ;
190215 var stackifyJson = _configuration . GetSection ( key2 ) ;
191216 v = stackifyJson . Value ;
217+ if ( string . IsNullOrEmpty ( v ) )
218+ {
219+ // Search in Retrace, but key will likely still be Stackify.name, not Retrace.name in the code
220+ var retraceAppSettings = _configuration . GetSection ( "Retrace" ) ;
221+ v = retraceAppSettings [ key . Replace ( "Stackify." , string . Empty ) ] ;
222+ }
192223 }
193- }
194224#endif
195225
196226#if NETFULL
@@ -200,9 +230,26 @@ internal static string Get(string key, string defaultValue = null)
200230 }
201231#endif
202232
203- if ( string . IsNullOrEmpty ( v ) )
204- {
205- v = System . Environment . GetEnvironmentVariable ( key ) ;
233+ if ( string . IsNullOrEmpty ( v ) )
234+ {
235+ v = System . Environment . GetEnvironmentVariable ( key ) ;
236+ }
237+
238+ if ( string . IsNullOrEmpty ( v ) )
239+ {
240+ v = System . Environment . GetEnvironmentVariable ( key . ToUpperInvariant ( ) ) ;
241+ }
242+
243+ if ( string . IsNullOrEmpty ( v ) )
244+ {
245+ // Linux systems do not allow period in an environment variable name
246+ v = System . Environment . GetEnvironmentVariable ( key . Replace ( '.' , '_' ) . ToUpperInvariant ( ) ) ;
247+ }
248+
249+ if ( string . IsNullOrEmpty ( v ) && key . StartsWith ( "Stackify." ) )
250+ {
251+ v = System . Environment . GetEnvironmentVariable ( "RETRACE_" + key . Substring ( 9 ) . Replace ( '.' , '_' ) . ToUpperInvariant ( ) ) ;
252+ }
206253 }
207254 }
208255 }
0 commit comments