1
1
/*
2
2
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
3
+ *
4
4
* Licensed under the Apache License, Version 2.0 (the "License").
5
5
* You may not use this file except in compliance with the License.
6
6
* A copy of the License is located at
7
- *
7
+ *
8
8
* http://aws.amazon.com/apache2.0
9
- *
9
+ *
10
10
* or in the "license" file accompanying this file. This file is distributed
11
11
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
12
* express or implied. See the License for the specific language governing
@@ -25,6 +25,8 @@ namespace AWS.Lambda.Powertools.Common;
25
25
/// <seealso cref="IPowertoolsConfigurations" />
26
26
public class PowertoolsConfigurations : IPowertoolsConfigurations
27
27
{
28
+ private readonly IPowertoolsEnvironment _powertoolsEnvironment ;
29
+
28
30
/// <summary>
29
31
/// The maximum dimensions
30
32
/// </summary>
@@ -40,26 +42,21 @@ public class PowertoolsConfigurations : IPowertoolsConfigurations
40
42
/// </summary>
41
43
private static IPowertoolsConfigurations _instance ;
42
44
43
- /// <summary>
44
- /// The system wrapper
45
- /// </summary>
46
- private readonly ISystemWrapper _systemWrapper ;
47
-
48
45
/// <summary>
49
46
/// Initializes a new instance of the <see cref="PowertoolsConfigurations" /> class.
50
47
/// </summary>
51
- /// <param name="systemWrapper">The system wrapper. </param>
52
- internal PowertoolsConfigurations ( ISystemWrapper systemWrapper )
48
+ /// <param name="powertoolsEnvironment"> </param>
49
+ internal PowertoolsConfigurations ( IPowertoolsEnvironment powertoolsEnvironment )
53
50
{
54
- _systemWrapper = systemWrapper ;
51
+ _powertoolsEnvironment = powertoolsEnvironment ;
55
52
}
56
53
57
54
/// <summary>
58
55
/// Gets the instance.
59
56
/// </summary>
60
57
/// <value>The instance.</value>
61
58
public static IPowertoolsConfigurations Instance =>
62
- _instance ??= new PowertoolsConfigurations ( SystemWrapper . Instance ) ;
59
+ _instance ??= new PowertoolsConfigurations ( PowertoolsEnvironment . Instance ) ;
63
60
64
61
/// <summary>
65
62
/// Gets the environment variable.
@@ -68,7 +65,7 @@ internal PowertoolsConfigurations(ISystemWrapper systemWrapper)
68
65
/// <returns>System.String.</returns>
69
66
public string GetEnvironmentVariable ( string variable )
70
67
{
71
- return _systemWrapper . GetEnvironmentVariable ( variable ) ;
68
+ return _powertoolsEnvironment . GetEnvironmentVariable ( variable ) ;
72
69
}
73
70
74
71
/// <summary>
@@ -79,7 +76,7 @@ public string GetEnvironmentVariable(string variable)
79
76
/// <returns>System.String.</returns>
80
77
public string GetEnvironmentVariableOrDefault ( string variable , string defaultValue )
81
78
{
82
- var result = _systemWrapper . GetEnvironmentVariable ( variable ) ;
79
+ var result = _powertoolsEnvironment . GetEnvironmentVariable ( variable ) ;
83
80
return string . IsNullOrWhiteSpace ( result ) ? defaultValue : result ;
84
81
}
85
82
@@ -91,7 +88,7 @@ public string GetEnvironmentVariableOrDefault(string variable, string defaultVal
91
88
/// <returns>System.Int32.</returns>
92
89
public int GetEnvironmentVariableOrDefault ( string variable , int defaultValue )
93
90
{
94
- var result = _systemWrapper . GetEnvironmentVariable ( variable ) ;
91
+ var result = _powertoolsEnvironment . GetEnvironmentVariable ( variable ) ;
95
92
return int . TryParse ( result , out var parsedValue ) ? parsedValue : defaultValue ;
96
93
}
97
94
@@ -103,7 +100,7 @@ public int GetEnvironmentVariableOrDefault(string variable, int defaultValue)
103
100
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
104
101
public bool GetEnvironmentVariableOrDefault ( string variable , bool defaultValue )
105
102
{
106
- return bool . TryParse ( _systemWrapper . GetEnvironmentVariable ( variable ) , out var result )
103
+ return bool . TryParse ( _powertoolsEnvironment . GetEnvironmentVariable ( variable ) , out var result )
107
104
? result
108
105
: defaultValue ;
109
106
}
@@ -161,7 +158,8 @@ public bool GetEnvironmentVariableOrDefault(string variable, bool defaultValue)
161
158
/// </summary>
162
159
/// <value>The logger sample rate.</value>
163
160
public double LoggerSampleRate =>
164
- double . TryParse ( _systemWrapper . GetEnvironmentVariable ( Constants . LoggerSampleRateNameEnv ) , NumberStyles . AllowDecimalPoint , CultureInfo . InvariantCulture , out var result )
161
+ double . TryParse ( _powertoolsEnvironment . GetEnvironmentVariable ( Constants . LoggerSampleRateNameEnv ) ,
162
+ NumberStyles . AllowDecimalPoint , CultureInfo . InvariantCulture , out var result )
165
163
? result
166
164
: 0 ;
167
165
@@ -191,7 +189,7 @@ public bool GetEnvironmentVariableOrDefault(string variable, bool defaultValue)
191
189
/// </summary>
192
190
/// <value><c>true</c> if this instance is Lambda; otherwise, <c>false</c>.</value>
193
191
public bool IsLambdaEnvironment => GetEnvironmentVariable ( Constants . LambdaTaskRoot ) is not null ;
194
-
192
+
195
193
/// <summary>
196
194
/// Gets a value indicating whether [tracing is disabled].
197
195
/// </summary>
@@ -202,28 +200,32 @@ public bool GetEnvironmentVariableOrDefault(string variable, bool defaultValue)
202
200
/// <inheritdoc />
203
201
public void SetExecutionEnvironment < T > ( T type )
204
202
{
205
- _systemWrapper . SetExecutionEnvironment ( type ) ;
203
+ _powertoolsEnvironment . SetExecutionEnvironment ( type ) ;
206
204
}
207
205
208
206
/// <inheritdoc />
209
207
public bool IdempotencyDisabled =>
210
208
GetEnvironmentVariableOrDefault ( Constants . IdempotencyDisabledEnv , false ) ;
211
209
212
210
/// <inheritdoc />
213
- public string BatchProcessingErrorHandlingPolicy => GetEnvironmentVariableOrDefault ( Constants . BatchErrorHandlingPolicyEnv , "DeriveFromEvent" ) ;
211
+ public string BatchProcessingErrorHandlingPolicy =>
212
+ GetEnvironmentVariableOrDefault ( Constants . BatchErrorHandlingPolicyEnv , "DeriveFromEvent" ) ;
214
213
215
214
/// <inheritdoc />
216
- public bool BatchParallelProcessingEnabled => GetEnvironmentVariableOrDefault ( Constants . BatchParallelProcessingEnabled , false ) ;
215
+ public bool BatchParallelProcessingEnabled =>
216
+ GetEnvironmentVariableOrDefault ( Constants . BatchParallelProcessingEnabled , false ) ;
217
217
218
218
/// <inheritdoc />
219
- public int BatchProcessingMaxDegreeOfParallelism => GetEnvironmentVariableOrDefault ( Constants . BatchMaxDegreeOfParallelismEnv , 1 ) ;
219
+ public int BatchProcessingMaxDegreeOfParallelism =>
220
+ GetEnvironmentVariableOrDefault ( Constants . BatchMaxDegreeOfParallelismEnv , 1 ) ;
220
221
221
222
/// <inheritdoc />
222
- public bool BatchThrowOnFullBatchFailureEnabled => GetEnvironmentVariableOrDefault ( Constants . BatchThrowOnFullBatchFailureEnv , true ) ;
223
+ public bool BatchThrowOnFullBatchFailureEnabled =>
224
+ GetEnvironmentVariableOrDefault ( Constants . BatchThrowOnFullBatchFailureEnv , true ) ;
223
225
224
226
/// <inheritdoc />
225
227
public bool MetricsDisabled => GetEnvironmentVariableOrDefault ( Constants . PowertoolsMetricsDisabledEnv , false ) ;
226
-
228
+
227
229
/// <inheritdoc />
228
230
public bool IsColdStart => LambdaLifecycleTracker . IsColdStart ;
229
231
0 commit comments