@@ -30,9 +30,9 @@ public static EnvironmentDetail Get()
30
30
return _CachedCopy ?? ( _CachedCopy = new EnvironmentDetail ( ) ) ;
31
31
}
32
32
#if NETSTANDARD
33
- private static System . Net . Http . HttpClient Client => new System . Net . Http . HttpClient ( ) ;
33
+ private System . Net . Http . HttpClient Client => new System . Net . Http . HttpClient ( ) ;
34
34
#endif
35
- private static bool registryAccessFailure = false ;
35
+ private bool registryAccessFailure = false ;
36
36
37
37
/// <summary>
38
38
/// Figures out if the server is in azure and if so gets the azure instance name
@@ -110,23 +110,23 @@ private void GetAzureInfo()
110
110
#endif
111
111
}
112
112
113
- private static bool ? _isIMDSv1 ;
113
+ private bool ? _isIMDSv1 ;
114
114
// http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#d0e30002
115
115
private const string EC2InstanceIdUrl = "http://169.254.169.254/latest/meta-data/instance-id" ;
116
116
private const string IMDS_BASE_URL = "http://169.254.169.254/latest" ;
117
117
private const string IMDS_TOKEN_PATH = "/api/token" ;
118
118
private const string IMDS_INSTANCE_ID_PATH = "/meta-data/instance-id" ;
119
119
private const string IMDSV1_BASE_URL = "http://169.254.169.254/latest/meta-data/" ;
120
- public static readonly object ec2InstanceLock = new object ( ) ;
121
- private static DateTimeOffset ? ec2InstanceIdLastUpdate = null ;
122
- private static string ec2InstanceId = null ;
120
+ public static readonly object ec2InstanceLock = new object ( ) ;
121
+ private DateTimeOffset ? ec2InstanceIdLastUpdate = null ;
122
+ private string ec2InstanceId = string . Empty ;
123
123
124
124
/// <summary>
125
125
/// Get the EC2 Instance name if it exists else null
126
126
/// </summary>
127
127
#if NETFULL
128
128
129
- public static string GetDeviceName ( )
129
+ public string GetDeviceName ( )
130
130
{
131
131
var deviceName = Environment . GetEnvironmentVariable ( "STACKIFY_DEVICE_NAME" ) ;
132
132
if ( ! String . IsNullOrEmpty ( deviceName ) )
@@ -139,7 +139,7 @@ public static string GetDeviceName()
139
139
140
140
var isDefaultDeviceNameEc2 = IsEc2MachineName ( deviceName ) ;
141
141
142
- if ( Config . IsEc2 == null || Config . IsEc2 == true || isDefaultDeviceNameEc2 )
142
+ if ( ( Config . IsEc2 . HasValue && Config . IsEc2 == true ) || isDefaultDeviceNameEc2 )
143
143
{
144
144
var instanceID_task = GetEC2InstanceId ( ) ;
145
145
if ( string . IsNullOrWhiteSpace ( instanceID_task ) == false )
@@ -151,7 +151,7 @@ public static string GetDeviceName()
151
151
return deviceName . Substring ( 0 , deviceName . Length > 60 ? 60 : deviceName . Length ) ;
152
152
}
153
153
154
- public static bool IsIMDSv1 ( )
154
+ public bool IsIMDSv1 ( )
155
155
{
156
156
157
157
if ( _isIMDSv1 . HasValue )
@@ -174,7 +174,7 @@ public static bool IsIMDSv1()
174
174
}
175
175
}
176
176
177
- public static string GetAccessToken ( )
177
+ public string GetAccessToken ( )
178
178
{
179
179
var url = IMDS_BASE_URL + IMDS_TOKEN_PATH ;
180
180
var httpRequest = ( HttpWebRequest ) WebRequest . Create ( url ) ;
@@ -190,7 +190,7 @@ public static string GetAccessToken()
190
190
}
191
191
192
192
193
- public static string GetEC2InstanceId ( )
193
+ public string GetEC2InstanceId ( )
194
194
{
195
195
string r = null ;
196
196
@@ -258,7 +258,7 @@ public static string GetEC2InstanceId()
258
258
return r ;
259
259
}
260
260
#else
261
- public static string GetDeviceName ( )
261
+ public string GetDeviceName ( )
262
262
{
263
263
var deviceName = Environment . GetEnvironmentVariable ( "STACKIFY_DEVICE_NAME" ) ;
264
264
if ( ! String . IsNullOrEmpty ( deviceName ) )
@@ -271,7 +271,7 @@ public static string GetDeviceName()
271
271
272
272
var isDefaultDeviceNameEc2 = IsEc2MachineName ( deviceName ) ;
273
273
274
- if ( Config . IsEc2 == null || Config . IsEc2 == true || isDefaultDeviceNameEc2 )
274
+ if ( ( Config . IsEc2 . HasValue && Config . IsEc2 == true ) || isDefaultDeviceNameEc2 )
275
275
{
276
276
var instanceID_task = GetEC2InstanceId ( ) ;
277
277
instanceID_task . Wait ( ) ;
@@ -284,7 +284,7 @@ public static string GetDeviceName()
284
284
return deviceName . Substring ( 0 , deviceName . Length > 60 ? 60 : deviceName . Length ) ;
285
285
}
286
286
287
- public static async Task < string > GetAccessTokenAsync ( )
287
+ public async Task < string > GetAccessTokenAsync ( )
288
288
{
289
289
var url = IMDS_BASE_URL + IMDS_TOKEN_PATH ;
290
290
var request = new System . Net . Http . HttpRequestMessage ( System . Net . Http . HttpMethod . Put , url ) ;
@@ -294,7 +294,7 @@ public static async Task<string> GetAccessTokenAsync()
294
294
return await response . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
295
295
}
296
296
297
- public static async Task < bool > IsIMDSv1 ( )
297
+ public async Task < bool > IsIMDSv1 ( )
298
298
{
299
299
if ( _isIMDSv1 . HasValue )
300
300
{
@@ -314,7 +314,7 @@ public static async Task<bool> IsIMDSv1()
314
314
}
315
315
}
316
316
317
- public static async Task < string > GetEC2InstanceId ( )
317
+ public async Task < string > GetEC2InstanceId ( )
318
318
{
319
319
string r = null ;
320
320
try
@@ -345,7 +345,7 @@ public static async Task<string> GetEC2InstanceId()
345
345
}
346
346
347
347
#endif
348
- private static bool IsEc2MachineName ( string machineName )
348
+ private bool IsEc2MachineName ( string machineName )
349
349
{
350
350
if ( string . IsNullOrWhiteSpace ( machineName ) )
351
351
{
0 commit comments