[PR #1516] [MERGED] Add Locations endpoints #15487

Closed
opened 2026-08-05 03:07:46 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/1516
Author: @bcmmbaga
Created: 2/1/2024
Status: Merged
Merged: 2/7/2024
Merged by: @bcmmbaga

Base: feature/posture-checksHead: locations-endpoints


📝 Commits (10+)

  • f4dbb85 add locations endpoints
  • 81412a8 Merge branch 'feature/posture-checks' into locations-endpoints
  • ec1fc81 Add sqlite3 check and database generation in geolite script
  • d2d353a Merge branch 'feature/posture-checks' into locations-endpoints
  • 52f02b3 Add SQLite storage for geolocation data
  • dc3f2b5 Refactor file existence check into a separate function
  • 3d4c1fe Integrate geolocation services into management application
  • c9ef726 Refactoring
  • dc97dae Refactor city retrieval to include Geonames ID
  • c7479f9 Add signature verification for GeoLite2 database download

📊 Changes

9 files changed (+604 additions, -46 deletions)

View changed files

📝 infrastructure_files/download-geolite2.sh (+89 -35)
📝 management/cmd/management.go (+2 -1)
📝 management/server/geolocation/geolocation.go (+65 -1)
📝 management/server/geolocation/geolocation_test.go (+10 -2)
management/server/geolocation/store.go (+208 -0)
📝 management/server/http/api/openapi.yml (+85 -0)
📝 management/server/http/api/types.gen.go (+18 -0)
management/server/http/geolocations_handler.go (+107 -0)
📝 management/server/http/handler.go (+20 -7)

📄 Description

Describe your changes

Introduced additional endpoints for country and city locations:

  • GET /api/locations/countries: Provides a list of all countries in 2-letter ISO 3166-1 alpha-2 codes
  • GET /api/locations/countries/:country/cities: Retrieves the list of English city names corresponding to a specific country code

Extended the functionality of the ./infrastructure_files/download-geolite2.sh script to include the download of the geolite cities locations CSV database and the subsequent creation of an SQLite database from the CSV.

MM_ACCOUNT_ID=... MM_LICENSE_KEY=...  ./infrastructure_files/download-geolite2.sh

Both MM_ACCOUNT_ID and MM_LICENSE_KEY can be obtained from MaxMind.

Upon successful execution of the script, the resulting geonames.db file should be placed in the designated datadir. Clear instructions for this process are provided in the script output:

SQLite database 'geonames.db' created successfully.
Now you can place geonames.db to 'datadir' of management service.
Example:
	docker compose cp geonames.db management:/var/lib/netbird/

Note: The new API endpoints will only be accessible if the geonames.db exists in the specified data directory.

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/1516 **Author:** [@bcmmbaga](https://github.com/bcmmbaga) **Created:** 2/1/2024 **Status:** ✅ Merged **Merged:** 2/7/2024 **Merged by:** [@bcmmbaga](https://github.com/bcmmbaga) **Base:** `feature/posture-checks` ← **Head:** `locations-endpoints` --- ### 📝 Commits (10+) - [`f4dbb85`](https://github.com/netbirdio/netbird/commit/f4dbb850cf58edbd51263b7848e6a07056833ece) add locations endpoints - [`81412a8`](https://github.com/netbirdio/netbird/commit/81412a87add6270535c91af8d9bba271ef2422f8) Merge branch 'feature/posture-checks' into locations-endpoints - [`ec1fc81`](https://github.com/netbirdio/netbird/commit/ec1fc8142df01b9d4a84531a304b0dee236b67ef) Add sqlite3 check and database generation in geolite script - [`d2d353a`](https://github.com/netbirdio/netbird/commit/d2d353abcc505afafe583a3f46ae084cb510acb8) Merge branch 'feature/posture-checks' into locations-endpoints - [`52f02b3`](https://github.com/netbirdio/netbird/commit/52f02b3fe46deeec5a9c040c12c61755a419f01e) Add SQLite storage for geolocation data - [`dc3f2b5`](https://github.com/netbirdio/netbird/commit/dc3f2b5bd36d31bf9f05ea5ce7051b17d23dc185) Refactor file existence check into a separate function - [`3d4c1fe`](https://github.com/netbirdio/netbird/commit/3d4c1fed530eac599df5da8d0e7d258ea42cf5d8) Integrate geolocation services into management application - [`c9ef726`](https://github.com/netbirdio/netbird/commit/c9ef72650cbca0a69a61a271be853abf1731667a) Refactoring - [`dc97dae`](https://github.com/netbirdio/netbird/commit/dc97dae100a4c1e0efdb7236ccb49ab938bd79eb) Refactor city retrieval to include Geonames ID - [`c7479f9`](https://github.com/netbirdio/netbird/commit/c7479f9b4ea78a2c4a7eae51bdc30a9bdccfad92) Add signature verification for GeoLite2 database download ### 📊 Changes **9 files changed** (+604 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `infrastructure_files/download-geolite2.sh` (+89 -35) 📝 `management/cmd/management.go` (+2 -1) 📝 `management/server/geolocation/geolocation.go` (+65 -1) 📝 `management/server/geolocation/geolocation_test.go` (+10 -2) ➕ `management/server/geolocation/store.go` (+208 -0) 📝 `management/server/http/api/openapi.yml` (+85 -0) 📝 `management/server/http/api/types.gen.go` (+18 -0) ➕ `management/server/http/geolocations_handler.go` (+107 -0) 📝 `management/server/http/handler.go` (+20 -7) </details> ### 📄 Description ## Describe your changes Introduced additional endpoints for country and city locations: - `GET /api/locations/countries`: Provides a list of all countries in 2-letter ISO 3166-1 alpha-2 codes - `GET /api/locations/countries/:country/cities`: Retrieves the list of English city names corresponding to a specific country code Extended the functionality of the `./infrastructure_files/download-geolite2.sh` script to include the download of the geolite cities locations CSV database and the subsequent creation of an SQLite database from the CSV. ```bash MM_ACCOUNT_ID=... MM_LICENSE_KEY=... ./infrastructure_files/download-geolite2.sh ``` Both `MM_ACCOUNT_ID` and `MM_LICENSE_KEY` can be obtained from [MaxMind](https://dev.maxmind.com/geoip/geolite2-free-geolocation-data). Upon successful execution of the script, the resulting geonames.db file should be placed in the designated datadir. Clear instructions for this process are provided in the script output: ``` SQLite database 'geonames.db' created successfully. Now you can place geonames.db to 'datadir' of management service. Example: docker compose cp geonames.db management:/var/lib/netbird/ ``` Note: The new API endpoints will only be accessible if the geonames.db exists in the specified data directory. ## Issue ticket number and link ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [ ] It is a refactor - [ ] Created tests that fail without the change (if possible) - [ ] Extended the README / documentation, if necessary --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 03:07:46 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#15487