@@ -20,48 +20,37 @@ public static IServiceCollection AddLocaltestValidation(this IServiceCollection
2020
2121internal sealed class LocaltestValidation : BackgroundService
2222{
23- private const string ExpectedHostname = "local.altinn.cloud" ;
24-
2523 private readonly ILogger < LocaltestValidation > _logger ;
2624 private readonly IHttpClientFactory _httpClientFactory ;
2725 private readonly IOptionsMonitor < GeneralSettings > _generalSettings ;
28- private readonly IOptionsMonitor < PlatformSettings > _platformSettings ;
26+ private readonly RuntimeEnvironment _runtimeEnvironment ;
2927 private readonly IHostApplicationLifetime _lifetime ;
3028 private readonly TimeProvider _timeProvider ;
3129 private readonly Channel < VersionResult > _resultChannel ;
3230
3331 internal IAsyncEnumerable < VersionResult > Results => _resultChannel . Reader . ReadAllAsync ( ) ;
3432
35- internal static string GetLocaltestBaseUrl ( PlatformSettings platformSettings ) =>
36- new Uri ( platformSettings . ApiStorageEndpoint ) . GetLeftPart ( UriPartial . Authority ) ;
37-
38- internal static bool IsLocaltest ( GeneralSettings generalSettings ) =>
39- generalSettings . HostName . Equals ( ExpectedHostname , StringComparison . OrdinalIgnoreCase ) ;
40-
4133 public LocaltestValidation (
4234 ILogger < LocaltestValidation > logger ,
4335 IHttpClientFactory httpClientFactory ,
4436 IOptionsMonitor < GeneralSettings > generalSettings ,
45- IOptionsMonitor < PlatformSettings > platformSettings ,
37+ RuntimeEnvironment runtimeEnvironment ,
4638 IHostApplicationLifetime lifetime ,
4739 TimeProvider ? timeProvider = null
4840 )
4941 {
5042 _logger = logger ;
5143 _httpClientFactory = httpClientFactory ;
5244 _generalSettings = generalSettings ;
53- _platformSettings = platformSettings ;
45+ _runtimeEnvironment = runtimeEnvironment ;
5446 _lifetime = lifetime ;
5547 _timeProvider = timeProvider ?? TimeProvider . System ;
5648 _resultChannel = Channel . CreateBounded < VersionResult > (
5749 new BoundedChannelOptions ( 10 ) { FullMode = BoundedChannelFullMode . DropWrite }
5850 ) ;
5951 }
6052
61- private void Exit ( )
62- {
63- _lifetime . StopApplication ( ) ;
64- }
53+ private void Exit ( ) => _lifetime . StopApplication ( ) ;
6554
6655 protected override async Task ExecuteAsync ( CancellationToken stoppingToken )
6756 {
@@ -71,9 +60,10 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
7160 if ( settings . DisableLocaltestValidation )
7261 return ;
7362
74- if ( ! IsLocaltest ( settings ) )
63+ if ( ! _runtimeEnvironment . IsLocaltestPlatform ( ) )
7564 return ;
7665
66+ var baseUrl = _runtimeEnvironment . GetPlatformBaseUrl ( ) ;
7767 while ( ! stoppingToken . IsCancellationRequested )
7868 {
7969 var result = await Version ( ) ;
@@ -99,7 +89,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
9989 _logger . LogError (
10090 "Localtest version may be outdated, as we failed to probe {HostName} API for version information."
10191 + " Is localtest running? Do you have a recent copy of localtest? Shutting down.." ,
102- ExpectedHostname
92+ baseUrl
10393 ) ;
10494 Exit ( ) ;
10595 return ;
@@ -176,7 +166,7 @@ private async Task<VersionResult> Version()
176166 {
177167 using var client = _httpClientFactory . CreateClient ( ) ;
178168
179- var baseUrl = GetLocaltestBaseUrl ( _platformSettings . CurrentValue ) ;
169+ var baseUrl = _runtimeEnvironment . GetPlatformBaseUrl ( ) ;
180170 var url = $ "{ baseUrl } /Home/Localtest/Version";
181171
182172 using var response = await client . GetAsync ( url , cancellationToken ) ;
0 commit comments