@@ -30,9 +30,9 @@ public static EnvironmentDetail Get()
3030 return _CachedCopy ?? ( _CachedCopy = new EnvironmentDetail ( ) ) ;
3131 }
3232#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 ( ) ;
3434#endif
35- private static bool registryAccessFailure = false ;
35+ private bool registryAccessFailure = false ;
3636
3737 /// <summary>
3838 /// Figures out if the server is in azure and if so gets the azure instance name
@@ -110,23 +110,23 @@ private void GetAzureInfo()
110110#endif
111111 }
112112
113- private static bool ? _isIMDSv1 ;
113+ private bool ? _isIMDSv1 ;
114114 // http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#d0e30002
115115 private const string EC2InstanceIdUrl = "http://169.254.169.254/latest/meta-data/instance-id" ;
116116 private const string IMDS_BASE_URL = "http://169.254.169.254/latest" ;
117117 private const string IMDS_TOKEN_PATH = "/api/token" ;
118118 private const string IMDS_INSTANCE_ID_PATH = "/meta-data/instance-id" ;
119119 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 ;
123123
124124 /// <summary>
125125 /// Get the EC2 Instance name if it exists else null
126126 /// </summary>
127127#if NETFULL
128128
129- public static string GetDeviceName ( )
129+ public string GetDeviceName ( )
130130 {
131131 var deviceName = Environment . GetEnvironmentVariable ( "STACKIFY_DEVICE_NAME" ) ;
132132 if ( ! String . IsNullOrEmpty ( deviceName ) )
@@ -139,7 +139,7 @@ public static string GetDeviceName()
139139
140140 var isDefaultDeviceNameEc2 = IsEc2MachineName ( deviceName ) ;
141141
142- if ( Config . IsEc2 == null || Config . IsEc2 == true || isDefaultDeviceNameEc2 )
142+ if ( ( Config . IsEc2 . HasValue && Config . IsEc2 == true ) || isDefaultDeviceNameEc2 )
143143 {
144144 var instanceID_task = GetEC2InstanceId ( ) ;
145145 if ( string . IsNullOrWhiteSpace ( instanceID_task ) == false )
@@ -151,7 +151,7 @@ public static string GetDeviceName()
151151 return deviceName . Substring ( 0 , deviceName . Length > 60 ? 60 : deviceName . Length ) ;
152152 }
153153
154- public static bool IsIMDSv1 ( )
154+ public bool IsIMDSv1 ( )
155155 {
156156
157157 if ( _isIMDSv1 . HasValue )
@@ -174,7 +174,7 @@ public static bool IsIMDSv1()
174174 }
175175 }
176176
177- public static string GetAccessToken ( )
177+ public string GetAccessToken ( )
178178 {
179179 var url = IMDS_BASE_URL + IMDS_TOKEN_PATH ;
180180 var httpRequest = ( HttpWebRequest ) WebRequest . Create ( url ) ;
@@ -190,7 +190,7 @@ public static string GetAccessToken()
190190 }
191191
192192
193- public static string GetEC2InstanceId ( )
193+ public string GetEC2InstanceId ( )
194194 {
195195 string r = null ;
196196
@@ -258,7 +258,7 @@ public static string GetEC2InstanceId()
258258 return r ;
259259 }
260260#else
261- public static string GetDeviceName ( )
261+ public string GetDeviceName ( )
262262 {
263263 var deviceName = Environment . GetEnvironmentVariable ( "STACKIFY_DEVICE_NAME" ) ;
264264 if ( ! String . IsNullOrEmpty ( deviceName ) )
@@ -271,7 +271,7 @@ public static string GetDeviceName()
271271
272272 var isDefaultDeviceNameEc2 = IsEc2MachineName ( deviceName ) ;
273273
274- if ( Config . IsEc2 == null || Config . IsEc2 == true || isDefaultDeviceNameEc2 )
274+ if ( ( Config . IsEc2 . HasValue && Config . IsEc2 == true ) || isDefaultDeviceNameEc2 )
275275 {
276276 var instanceID_task = GetEC2InstanceId ( ) ;
277277 instanceID_task . Wait ( ) ;
@@ -284,7 +284,7 @@ public static string GetDeviceName()
284284 return deviceName . Substring ( 0 , deviceName . Length > 60 ? 60 : deviceName . Length ) ;
285285 }
286286
287- public static async Task < string > GetAccessTokenAsync ( )
287+ public async Task < string > GetAccessTokenAsync ( )
288288 {
289289 var url = IMDS_BASE_URL + IMDS_TOKEN_PATH ;
290290 var request = new System . Net . Http . HttpRequestMessage ( System . Net . Http . HttpMethod . Put , url ) ;
@@ -294,7 +294,7 @@ public static async Task<string> GetAccessTokenAsync()
294294 return await response . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
295295 }
296296
297- public static async Task < bool > IsIMDSv1 ( )
297+ public async Task < bool > IsIMDSv1 ( )
298298 {
299299 if ( _isIMDSv1 . HasValue )
300300 {
@@ -314,7 +314,7 @@ public static async Task<bool> IsIMDSv1()
314314 }
315315 }
316316
317- public static async Task < string > GetEC2InstanceId ( )
317+ public async Task < string > GetEC2InstanceId ( )
318318 {
319319 string r = null ;
320320 try
@@ -345,7 +345,7 @@ public static async Task<string> GetEC2InstanceId()
345345 }
346346
347347#endif
348- private static bool IsEc2MachineName ( string machineName )
348+ private bool IsEc2MachineName ( string machineName )
349349 {
350350 if ( string . IsNullOrWhiteSpace ( machineName ) )
351351 {
0 commit comments