Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HttpClient BaseAddress setting #125

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/CostApi/AzureCostApiRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// Add more dimension names as needed
}

public AzureCostApiRetriever(IHttpClientFactory httpClientFactory)

Check warning on line 41 in src/CostApi/AzureCostApiRetriever.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'CostApiAddress' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
{
_client = httpClientFactory.CreateClient("CostApi");
}
Expand Down Expand Up @@ -126,9 +126,12 @@
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,
Expand Down Expand Up @@ -1023,23 +1026,23 @@

public class UsageDetailsResponse
{
public UsageDetails[] value { get; set; }

Check warning on line 1029 in src/CostApi/AzureCostApiRetriever.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'value' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string? nextLink { get; set; }
}

public class UsageDetails
{
public string kind { get; set; }

Check warning on line 1035 in src/CostApi/AzureCostApiRetriever.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'kind' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string id { get; set; }

Check warning on line 1036 in src/CostApi/AzureCostApiRetriever.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'id' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string name { get; set; }

Check warning on line 1037 in src/CostApi/AzureCostApiRetriever.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string type { get; set; }

Check warning on line 1038 in src/CostApi/AzureCostApiRetriever.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'type' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public Dictionary<string, string> tags { get; set; }

Check warning on line 1039 in src/CostApi/AzureCostApiRetriever.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'tags' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public UsageProperties properties { get; set; }

Check warning on line 1040 in src/CostApi/AzureCostApiRetriever.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'properties' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}

public class UsageProperties
{
public string billingPeriodStartDate { get; set; }

Check warning on line 1045 in src/CostApi/AzureCostApiRetriever.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'billingPeriodStartDate' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
public string billingPeriodEndDate { get; set; }
public string billingProfileId { get; set; }
public string billingProfileName { get; set; }
Expand Down
9 changes: 6 additions & 3 deletions src/CostApi/AzurePriceRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ public AzurePriceRetriever(IHttpClientFactory httpClientFactory)

public async Task<IEnumerable<PriceRecord>> 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<PriceRecord>();
string? url = "https://prices.azure.com/api/retail/prices?api-version=2023-01-01-preview&currencyCode='" + currencyCode + "'";
string? url = "api/retail/prices?api-version=2023-01-01-preview&currencyCode='" + currencyCode + "'";

// Append the filter to the URL if it's provided
if (!string.IsNullOrWhiteSpace(filter))
Expand Down
Loading