Skip to content

Commit

Permalink
Remove APIKEY from logs
Browse files Browse the repository at this point in the history
  • Loading branch information
colinnuk committed Aug 30, 2024
1 parent db1eb80 commit 02cb1dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 6 additions & 6 deletions OpenMeteo/OpenMeteoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public OpenMeteoClient(IOpenMeteoLogger logger, string apiKey)
/// <returns>Awaitable Task containing WeatherForecast or NULL</returns>
public async Task<WeatherForecast?> QueryAsync(float latitude, float longitude)
{
WeatherForecastOptions options = new WeatherForecastOptions
WeatherForecastOptions options = new()
{
Latitude = latitude,
Longitude = longitude,
Expand Down Expand Up @@ -171,7 +171,7 @@ public OpenMeteoClient(IOpenMeteoLogger logger, string apiKey)
/// <returns></returns>
public async Task<GeocodingApiResponse?> GetLocationDataAsync(string location)
{
GeocodingOptions geocodingOptions = new GeocodingOptions(location);
GeocodingOptions geocodingOptions = new(location);

return await GetLocationDataAsync(geocodingOptions);
}
Expand Down Expand Up @@ -247,7 +247,7 @@ public OpenMeteoClient(IOpenMeteoLogger logger, string apiKey)
try
{
var url = _urlFactory.GetUrlWithOptions(options);
_logger?.Debug($"{nameof(OpenMeteoClient)}.GetAirQualityAsync(). URL: {url}");
_logger?.Debug($"{nameof(OpenMeteoClient)}.GetAirQualityAsync(). URL: {_urlFactory.SanitiseUrl(url)}");
HttpResponseMessage response = await httpController.Client.GetAsync(url);
response.EnsureSuccessStatusCode();

Expand All @@ -267,7 +267,7 @@ public OpenMeteoClient(IOpenMeteoLogger logger, string apiKey)
try
{
var url = _urlFactory.GetUrlWithOptions(options);
_logger?.Debug($"{nameof(OpenMeteoClient)}.GetElevationAsync(). URL: {url}");
_logger?.Debug($"{nameof(OpenMeteoClient)}.GetElevationAsync(). URL: {_urlFactory.SanitiseUrl(url)}");
HttpResponseMessage response = await httpController.Client.GetAsync(url);
if(response.IsSuccessStatusCode)
{
Expand Down Expand Up @@ -306,7 +306,7 @@ public OpenMeteoClient(IOpenMeteoLogger logger, string apiKey)
{

var url = _urlFactory.GetUrlWithOptions(options);
_logger?.Debug($"{nameof(OpenMeteoClient)}.GetGeocodingDataAsync(). URL: {url}");
_logger?.Debug($"{nameof(OpenMeteoClient)}.GetGeocodingDataAsync(). URL: {_urlFactory.SanitiseUrl(url)}");
HttpResponseMessage response = await httpController.Client.GetAsync(url);
response.EnsureSuccessStatusCode();

Expand All @@ -328,7 +328,7 @@ public OpenMeteoClient(IOpenMeteoLogger logger, string apiKey)
try
{
var url = _urlFactory.GetUrlWithOptions(options);
_logger?.Debug($"{nameof(OpenMeteoClient)}.GetElevationAsync(). URL: {url}");
_logger?.Debug($"{nameof(OpenMeteoClient)}.GetElevationAsync(). URL: {_urlFactory.SanitiseUrl(url)}");
HttpResponseMessage response = await httpController.Client.GetAsync(url);
response.EnsureSuccessStatusCode();

Expand Down
5 changes: 5 additions & 0 deletions OpenMeteo/UrlFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public UrlFactory(string apiKey)
_apiKey = apiKey;
}

public string SanitiseUrl(string url)
{
return url.Replace(_apiKey, "APIKEY");
}

public string GetUrlWithOptions(WeatherForecastOptions options)
{
UriBuilder uri = new(GetBaseUrl(_weatherApiUrl));
Expand Down

0 comments on commit 02cb1dd

Please sign in to comment.