Skip to content

Commit

Permalink
Make city name optional (#1575)
Browse files Browse the repository at this point in the history
  • Loading branch information
surik authored Feb 13, 2024
1 parent 6792b50 commit 0bdf533
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 0 additions & 1 deletion management/server/http/api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,6 @@ components:
example: "Berlin"
required:
- country_code
- city_name
Country:
description: Describe country geographical location information
type: object
Expand Down
2 changes: 1 addition & 1 deletion management/server/http/api/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions management/server/http/posture_checks_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,9 @@ func toPostureChecksResponse(postureChecks *posture.Checks) *api.PostureCheck {
func toGeoLocationCheckResponse(geoLocationCheck *posture.GeoLocationCheck) *api.GeoLocationCheck {
locations := make([]api.Location, 0, len(geoLocationCheck.Locations))
for _, loc := range geoLocationCheck.Locations {
l := loc // make G601 happy
locations = append(locations, api.Location{
CityName: loc.CityName,
CityName: &l.CityName,
CountryCode: loc.CountryCode,
})
}
Expand All @@ -317,9 +318,13 @@ func toGeoLocationCheckResponse(geoLocationCheck *posture.GeoLocationCheck) *api
func toPostureGeoLocationCheck(apiGeoLocationCheck *api.GeoLocationCheck) *posture.GeoLocationCheck {
locations := make([]posture.Location, 0, len(apiGeoLocationCheck.Locations))
for _, loc := range apiGeoLocationCheck.Locations {
cityName := ""
if loc.CityName != nil {
cityName = *loc.CityName
}
locations = append(locations, posture.Location{
CountryCode: loc.CountryCode,
CityName: loc.CityName,
CityName: cityName,
})
}

Expand Down
7 changes: 5 additions & 2 deletions management/server/http/posture_checks_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"github.com/netbirdio/netbird/management/server/status"
)

var berlin = "Berlin"
var losAngeles = "Los Angeles"

func initPostureChecksTestData(postureChecks ...*posture.Checks) *PostureChecksHandler {
testPostureChecks := make(map[string]*posture.Checks, len(postureChecks))
for _, postureCheck := range postureChecks {
Expand Down Expand Up @@ -342,7 +345,7 @@ func TestPostureCheckUpdate(t *testing.T) {
GeoLocationCheck: &api.GeoLocationCheck{
Locations: []api.Location{
{
CityName: "Berlin",
CityName: &berlin,
CountryCode: "DE",
},
},
Expand Down Expand Up @@ -554,7 +557,7 @@ func TestPostureCheckUpdate(t *testing.T) {
GeoLocationCheck: &api.GeoLocationCheck{
Locations: []api.Location{
{
CityName: "Los Angeles",
CityName: &losAngeles,
CountryCode: "US",
},
},
Expand Down

0 comments on commit 0bdf533

Please sign in to comment.