From 0fac38b62fcd24ee0a803f1af228e2e082e512b7 Mon Sep 17 00:00:00 2001 From: Martin Frohlich Date: Tue, 19 Mar 2024 17:22:54 +0100 Subject: [PATCH] Set HttpClient BaseAddress only if not default --- src/CostApi/AzureCostApiRetriever.cs | 9 ++++++--- src/CostApi/AzurePriceRetriever.cs | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/CostApi/AzureCostApiRetriever.cs b/src/CostApi/AzureCostApiRetriever.cs index f161c00..f889577 100644 --- a/src/CostApi/AzureCostApiRetriever.cs +++ b/src/CostApi/AzureCostApiRetriever.cs @@ -126,9 +126,12 @@ private async Task ExecuteCallToCostApi(bool includeDebugOu AnsiConsole.Write(new JsonText(JsonSerializer.Serialize(payload))); AnsiConsole.WriteLine(); } - - _client.BaseAddress = new Uri(CostApiAddress); - + + if (!string.Equals(_client.BaseAddress?.ToString(), CostApiAddress)) + { + _client.BaseAddress = new Uri(CostApiAddress); + } + var options = new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, diff --git a/src/CostApi/AzurePriceRetriever.cs b/src/CostApi/AzurePriceRetriever.cs index a4ac4a3..82223dd 100644 --- a/src/CostApi/AzurePriceRetriever.cs +++ b/src/CostApi/AzurePriceRetriever.cs @@ -15,8 +15,11 @@ public AzurePriceRetriever(IHttpClientFactory httpClientFactory) public async Task> GetAzurePricesAsync(string currencyCode = "USD", string? filter = null) { - _client.BaseAddress = new Uri(PriceApiAddress); - + if (!string.Equals(_client.BaseAddress?.ToString(), PriceApiAddress)) + { + _client.BaseAddress = new Uri(PriceApiAddress); + } + var prices = new List(); string? url = "api/retail/prices?api-version=2023-01-01-preview¤cyCode='" + currencyCode + "'";