-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathConfig.cs
More file actions
123 lines (103 loc) · 5.31 KB
/
Config.cs
File metadata and controls
123 lines (103 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Newtonsoft.Json;
namespace StackifyLib
{
/// <summary>
/// Encapsulate settings retrieval mechanism. Currently supports config file and environment variables.
/// Could be expanded to include other type of configuration servers later.
/// </summary>
public class Config
{
public static void LoadSettings()
{
try
{
CaptureErrorPostdata = Get("Stackify.CaptureErrorPostdata", "")
.Equals("true", StringComparison.CurrentCultureIgnoreCase);
CaptureServerVariables = Get("Stackify.CaptureServerVariables", "")
.Equals("true", StringComparison.CurrentCultureIgnoreCase);
CaptureSessionVariables = Get("Stackify.CaptureSessionVariables", "")
.Equals("true", StringComparison.CurrentCultureIgnoreCase);
CaptureErrorHeaders = Get("Stackify.CaptureErrorHeaders", "")
.Equals("true", StringComparison.CurrentCultureIgnoreCase);
CaptureErrorCookies = Get("Stackify.CaptureErrorCookies", "")
.Equals("true", StringComparison.CurrentCultureIgnoreCase);
CaptureErrorHeadersWhitelist = Get("Stackify.CaptureErrorHeadersWhitelist", "");
if (!string.IsNullOrEmpty(CaptureErrorHeadersWhitelist))
{
ErrorHeaderGoodKeys = CaptureErrorHeadersWhitelist.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
}
CaptureErrorHeadersBlacklist = Get("Stackify.CaptureErrorHeadersBlacklist", "");
if (!string.IsNullOrEmpty(CaptureErrorHeadersBlacklist))
{
ErrorHeaderBadKeys = CaptureErrorHeadersBlacklist.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
}
CaptureErrorCookiesWhitelist = Get("Stackify.CaptureErrorCookiesWhitelist", "");
if (!string.IsNullOrEmpty(CaptureErrorCookiesWhitelist))
{
ErrorCookiesGoodKeys = CaptureErrorCookiesWhitelist.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
}
CaptureErrorCookiesBlacklist = Get("Stackify.CaptureErrorCookiesBlacklist", "");
if (!string.IsNullOrEmpty(CaptureErrorCookiesBlacklist))
{
ErrorCookiesBadKeys = CaptureErrorCookiesBlacklist.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
}
CaptureErrorSessionWhitelist = Get("Stackify.CaptureErrorSessionWhitelist", "");
if (!string.IsNullOrEmpty(CaptureErrorSessionWhitelist))
{
ErrorSessionGoodKeys = CaptureErrorSessionWhitelist.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
public static List<string> ErrorHeaderGoodKeys = new List<string>();
public static List<string> ErrorHeaderBadKeys = new List<string>();
public static List<string> ErrorCookiesGoodKeys = new List<string>();
public static List<string> ErrorCookiesBadKeys = new List<string>();
public static List<string> ErrorSessionGoodKeys = new List<string>();
public static bool CaptureSessionVariables { get; set; } = false;
public static bool CaptureServerVariables { get; set; } = false;
public static bool CaptureErrorPostdata { get; set; } = false;
public static bool CaptureErrorHeaders { get; set; } = true;
public static bool CaptureErrorCookies { get; set; } = false;
public static string CaptureErrorSessionWhitelist { get; set; } = null;
public static string CaptureErrorHeadersWhitelist { get; set; } = null;
public static string CaptureErrorHeadersBlacklist { get; set; } = "cookie,authorization";
public static string CaptureErrorCookiesWhitelist { get; set; } = null;
public static string CaptureErrorCookiesBlacklist { get; set; } = ".ASPXAUTH";
/// <summary>
/// Attempts to fetch a setting value given the key.
/// .NET configuration file will be used first, if the key is not found, environment variable will be used next.
/// </summary>
/// <param name="key">configuration key in config file or environment variable name.</param>
/// <param name="defaultValue">If nothing is found, return optional defaultValue provided.</param>
/// <returns>string value for the requested setting key.</returns>
internal static string Get(string key, string defaultValue = null)
{
return defaultValue;
//string v = null;
//try
//{
// if (key != null)
// {
// v = ConfigurationManager.AppSettings[key];
// if (string.IsNullOrEmpty(v))
// v = Environment.GetEnvironmentVariable(key);
// }
//}
//finally
//{
// if (v == null)
// v = defaultValue;
//}
//return v;
}
}
}