Skip to content

Commit

Permalink
fix: added path for smda http client
Browse files Browse the repository at this point in the history
  • Loading branch information
robinaasan committed Dec 22, 2024
1 parent 47945ee commit cbe8d19
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ public static class SmdaHealthChecksBuilderExtension
/// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
/// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param>
/// <param name="requestUrl">The url to be used, should include the api version </param>
/// <param name="requestHealthPath">The path to get the health data</param>
/// <param name="apiKey">Api to be set</param>
/// <param name="resourceId">Id for the resource to get an accesstoken for</param>
/// <returns>The specified <paramref name="builder"/>.</returns>
public static IHealthChecksBuilder AddSmdaHealthChecks<T>(
this IHealthChecksBuilder builder,
string requestUrl,
string requestHealthPath,
string apiKey,
string resourceId,
string cacheControlHeaderValue,
Expand All @@ -39,7 +41,7 @@ public static IHealthChecksBuilder AddSmdaHealthChecks<T>(
IEnumerable<string>? tags = default,
TimeSpan? timeout = default) where T : class, IAccessTokenService
{
return builder.AddSmdaHealthChecks<T>(_ => requestUrl, _ => apiKey, _ => resourceId,_ => cacheControlHeaderValue, name, failureStatus, tags, timeout );
return builder.AddSmdaHealthChecks<T>(_ => requestUrl, _ => requestHealthPath,_ => apiKey, _ => resourceId,_ => cacheControlHeaderValue, name, failureStatus, tags, timeout );
}


Expand All @@ -48,6 +50,7 @@ public static IHealthChecksBuilder AddSmdaHealthChecks<T>(
/// </summary>
/// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
/// <param name="requestUrlFactory"></param>
/// <param name="requestPathFactory">A Factory for setting the request path</param>
/// <param name="apiKeyFactory"></param>
/// <param name="resourceIdFactory"></param>
/// <param name="cacheControlHeaderFactory">A factory to build cache headers</param>
Expand All @@ -62,6 +65,7 @@ public static IHealthChecksBuilder AddSmdaHealthChecks<T>(
public static IHealthChecksBuilder AddSmdaHealthChecks<T>(
this IHealthChecksBuilder builder,
Func<IServiceProvider, string> requestUrlFactory,
Func<IServiceProvider, string> requestPathFactory,
Func<IServiceProvider, string> apiKeyFactory,
Func<IServiceProvider, string> resourceIdFactory,
Func<IServiceProvider, string> cacheControlHeaderFactory,
Expand Down Expand Up @@ -93,9 +97,9 @@ public static IHealthChecksBuilder AddSmdaHealthChecks<T>(
{
var tokenService = sp.GetRequiredService<IAccessTokenService>();
var client = sp.GetRequiredService<ISmdaClient>();
var requestUri = requestUrlFactory(sp);
var requestPath = requestPathFactory(sp);
var resourceId = resourceIdFactory(sp);
return new SmdaHealthCheck(client, tokenService, requestUri, resourceId);
return new SmdaHealthCheck(client, tokenService, requestPath, resourceId);
},
failureStatus,
tags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public class SmdaHealthCheck : IHealthCheck

private readonly IAccessTokenService _tokenService;

private readonly string? _requestUri;
private readonly string? _requestPath;

private readonly string? _resourceId;

public SmdaHealthCheck(ISmdaClient client, IAccessTokenService tokenService, string requestUri, string resourceId)
public SmdaHealthCheck(ISmdaClient client, IAccessTokenService tokenService, string requestPath, string resourceId)
{
_client = client;
_tokenService = tokenService;
_requestUri = Guard.Against.NullOrWhiteSpace(requestUri, nameof(requestUri), "RequestUri is required");
_requestPath = Guard.Against.NullOrWhiteSpace(requestPath, nameof(requestPath), "RequestPath is required");
_resourceId = Guard.Against.NullOrWhiteSpace(resourceId, nameof(resourceId), "ResourceId is required");
}

Expand All @@ -29,10 +29,10 @@ public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context
{
try
{
if (_requestUri is not null && _resourceId is not null)
if (_requestPath is not null && _resourceId is not null)
{
var token = await _tokenService.GetAccessTokenOnBehalfOfAsync(_resourceId).ConfigureAwait(false);
var res = await _client.GetSmdaDataAsync(_requestUri, token, HttpCompletionOption.ResponseHeadersRead,
var res = await _client.GetSmdaDataAsync(_requestPath, token, HttpCompletionOption.ResponseHeadersRead,
cancellationToken);

if (res.IsSuccessStatusCode)
Expand Down

0 comments on commit cbe8d19

Please sign in to comment.