mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Remove Photon API env vars and use DawarichSettings for reverse geocoding settings
This commit is contained in:
parent
10afb3fbc2
commit
ae6dc5ac8a
13 changed files with 150 additions and 24 deletions
|
|
@ -1 +1 @@
|
||||||
0.21.4
|
0.21.5
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,6 @@ services:
|
||||||
TIME_ZONE: Europe/London
|
TIME_ZONE: Europe/London
|
||||||
APPLICATION_PROTOCOL: http
|
APPLICATION_PROTOCOL: http
|
||||||
DISTANCE_UNIT: km
|
DISTANCE_UNIT: km
|
||||||
PHOTON_API_HOST: photon.komoot.io
|
|
||||||
PHOTON_API_USE_HTTPS: true
|
|
||||||
PROMETHEUS_EXPORTER_ENABLED: false
|
PROMETHEUS_EXPORTER_ENABLED: false
|
||||||
PROMETHEUS_EXPORTER_HOST: 0.0.0.0
|
PROMETHEUS_EXPORTER_HOST: 0.0.0.0
|
||||||
PROMETHEUS_EXPORTER_PORT: 9394
|
PROMETHEUS_EXPORTER_PORT: 9394
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,4 @@ DATABASE_PASSWORD=password
|
||||||
DATABASE_NAME=dawarich_development
|
DATABASE_NAME=dawarich_development
|
||||||
DATABASE_PORT=5432
|
DATABASE_PORT=5432
|
||||||
REDIS_URL=redis://localhost:6379/1
|
REDIS_URL=redis://localhost:6379/1
|
||||||
PHOTON_API_HOST='photon.komoot.io'
|
|
||||||
DISTANCE_UNIT='km'
|
DISTANCE_UNIT='km'
|
||||||
|
|
|
||||||
12
CHANGELOG.md
12
CHANGELOG.md
|
|
@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
# 0.21.5 - 2025-01-07
|
||||||
|
|
||||||
|
You may now use Geoapify API for reverse geocoding. To obrain an API key, sign up at https://myprojects.geoapify.com/ and create a new project. Make sure you have read and understood the [pricing policy](https://www.geoapify.com/pricing) and [Terms and Conditions](https://www.geoapify.com/terms-and-conditions/).
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Geoapify API support for reverse geocoding. Provide `GEOAPIFY_API_KEY` env var to use it.
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- Photon ENV vars from the `.env.development` and docker-compose.yml files.
|
||||||
|
|
||||||
# 0.21.4 - 2025-01-05
|
# 0.21.4 - 2025-01-05
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ class ReverseGeocodingJob < ApplicationJob
|
||||||
end
|
end
|
||||||
|
|
||||||
def rate_limit_for_photon_api
|
def rate_limit_for_photon_api
|
||||||
return unless PHOTON_API_HOST == 'photon.komoot.io'
|
return unless DawarichSettings.photon_enabled?
|
||||||
|
|
||||||
sleep 1 if PHOTON_API_HOST == 'photon.komoot.io'
|
sleep 1 if DawarichSettings.photon_uses_komoot_io?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ class ReverseGeocoding::Places::FetchData
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
if ::PHOTON_API_HOST.blank?
|
unless DawarichSettings.reverse_geocoding_enabled?
|
||||||
Rails.logger.warn('PHOTON_API_HOST is not set')
|
Rails.logger.warn('Reverse geocoding is not enabled')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,19 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
MIN_MINUTES_SPENT_IN_CITY = ENV.fetch('MIN_MINUTES_SPENT_IN_CITY', 60).to_i
|
MIN_MINUTES_SPENT_IN_CITY = ENV.fetch('MIN_MINUTES_SPENT_IN_CITY', 60).to_i
|
||||||
|
DISTANCE_UNIT = ENV.fetch('DISTANCE_UNIT', 'km').to_sym
|
||||||
|
|
||||||
|
APP_VERSION = File.read('.app_version').strip
|
||||||
|
|
||||||
|
TELEMETRY_STRING = Base64.encode64('IjVFvb8j3P9-ArqhSGav9j8YcJaQiuNIzkfOPKQDk2lvKXqb8t1NSRv50oBkaKtlrB_ZRzO9NdurpMtncV_HYQ==')
|
||||||
|
TELEMETRY_URL = 'https://influxdb2.frey.today/api/v2/write'
|
||||||
|
|
||||||
|
# Reverse geocoding settings
|
||||||
REVERSE_GEOCODING_ENABLED = ENV.fetch('REVERSE_GEOCODING_ENABLED', 'true') == 'true'
|
REVERSE_GEOCODING_ENABLED = ENV.fetch('REVERSE_GEOCODING_ENABLED', 'true') == 'true'
|
||||||
|
|
||||||
PHOTON_API_HOST = ENV.fetch('PHOTON_API_HOST', nil)
|
PHOTON_API_HOST = ENV.fetch('PHOTON_API_HOST', nil)
|
||||||
PHOTON_API_KEY = ENV.fetch('PHOTON_API_KEY', nil)
|
PHOTON_API_KEY = ENV.fetch('PHOTON_API_KEY', nil)
|
||||||
PHOTON_API_USE_HTTPS = ENV.fetch('PHOTON_API_USE_HTTPS', 'true') == 'true'
|
PHOTON_API_USE_HTTPS = ENV.fetch('PHOTON_API_USE_HTTPS', 'true') == 'true'
|
||||||
DISTANCE_UNIT = ENV.fetch('DISTANCE_UNIT', 'km').to_sym
|
|
||||||
APP_VERSION = File.read('.app_version').strip
|
GEOAPIFY_API_KEY = ENV.fetch('GEOAPIFY_API_KEY', nil)
|
||||||
TELEMETRY_STRING = Base64.encode64('IjVFvb8j3P9-ArqhSGav9j8YcJaQiuNIzkfOPKQDk2lvKXqb8t1NSRv50oBkaKtlrB_ZRzO9NdurpMtncV_HYQ==')
|
# /Reverse geocoding settings
|
||||||
TELEMETRY_URL = 'https://influxdb2.frey.today/api/v2/write'
|
|
||||||
|
|
|
||||||
21
config/initializers/03_dawarich_settings.rb
Normal file
21
config/initializers/03_dawarich_settings.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class DawarichSettings
|
||||||
|
class << self
|
||||||
|
def reverse_geocoding_enabled?
|
||||||
|
photon_enabled? || geoapify_enabled?
|
||||||
|
end
|
||||||
|
|
||||||
|
def photon_enabled?
|
||||||
|
PHOTON_API_HOST.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def photon_uses_komoot_io?
|
||||||
|
PHOTON_API_HOST == 'photon.komoot.io'
|
||||||
|
end
|
||||||
|
|
||||||
|
def geoapify_enabled?
|
||||||
|
GEOAPIFY_API_KEY.present?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -12,11 +12,13 @@ settings = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if defined?(PHOTON_API_HOST)
|
if PHOTON_API_HOST.present?
|
||||||
settings[:lookup] = :photon
|
settings[:lookup] = :photon
|
||||||
settings[:photon] = { use_https: PHOTON_API_USE_HTTPS, host: PHOTON_API_HOST }
|
settings[:photon] = { use_https: PHOTON_API_USE_HTTPS, host: PHOTON_API_HOST }
|
||||||
|
settings[:http_headers] = { 'X-Api-Key' => PHOTON_API_KEY } if defined?(PHOTON_API_KEY)
|
||||||
|
elsif GEOAPIFY_API_KEY.present?
|
||||||
|
settings[:lookup] = :geoapify
|
||||||
|
settings[:api_key] = GEOAPIFY_API_KEY
|
||||||
end
|
end
|
||||||
|
|
||||||
settings[:http_headers] = { 'X-Api-Key' => PHOTON_API_KEY } if defined?(PHOTON_API_KEY)
|
|
||||||
|
|
||||||
Geocoder.configure(settings)
|
Geocoder.configure(settings)
|
||||||
|
|
|
||||||
|
|
@ -27,4 +27,4 @@ Sidekiq.configure_client do |config|
|
||||||
config.redis = { url: ENV['REDIS_URL'] }
|
config.redis = { url: ENV['REDIS_URL'] }
|
||||||
end
|
end
|
||||||
|
|
||||||
Sidekiq::Queue['reverse_geocoding'].limit = 1 if Sidekiq.server? && PHOTON_API_HOST == 'photon.komoot.io'
|
Sidekiq::Queue['reverse_geocoding'].limit = 1 if Sidekiq.server? && DawarichSettings.photon_uses_komoot_io?
|
||||||
|
|
|
||||||
|
|
@ -67,8 +67,6 @@ services:
|
||||||
TIME_ZONE: Europe/London
|
TIME_ZONE: Europe/London
|
||||||
APPLICATION_PROTOCOL: http
|
APPLICATION_PROTOCOL: http
|
||||||
DISTANCE_UNIT: km
|
DISTANCE_UNIT: km
|
||||||
PHOTON_API_HOST: photon.komoot.io
|
|
||||||
PHOTON_API_USE_HTTPS: true
|
|
||||||
PROMETHEUS_EXPORTER_ENABLED: false
|
PROMETHEUS_EXPORTER_ENABLED: false
|
||||||
PROMETHEUS_EXPORTER_HOST: 0.0.0.0
|
PROMETHEUS_EXPORTER_HOST: 0.0.0.0
|
||||||
PROMETHEUS_EXPORTER_PORT: 9394
|
PROMETHEUS_EXPORTER_PORT: 9394
|
||||||
|
|
@ -122,8 +120,6 @@ services:
|
||||||
BACKGROUND_PROCESSING_CONCURRENCY: 10
|
BACKGROUND_PROCESSING_CONCURRENCY: 10
|
||||||
APPLICATION_PROTOCOL: http
|
APPLICATION_PROTOCOL: http
|
||||||
DISTANCE_UNIT: km
|
DISTANCE_UNIT: km
|
||||||
PHOTON_API_HOST: photon.komoot.io
|
|
||||||
PHOTON_API_USE_HTTPS: true
|
|
||||||
PROMETHEUS_EXPORTER_ENABLED: false
|
PROMETHEUS_EXPORTER_ENABLED: false
|
||||||
PROMETHEUS_EXPORTER_HOST: dawarich_app
|
PROMETHEUS_EXPORTER_HOST: dawarich_app
|
||||||
PROMETHEUS_EXPORTER_PORT: 9394
|
PROMETHEUS_EXPORTER_PORT: 9394
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,6 @@ services:
|
||||||
APPLICATION_HOSTS: localhost
|
APPLICATION_HOSTS: localhost
|
||||||
APPLICATION_PROTOCOL: http
|
APPLICATION_PROTOCOL: http
|
||||||
DISTANCE_UNIT: km
|
DISTANCE_UNIT: km
|
||||||
PHOTON_API_HOST: photon.komoot.io
|
|
||||||
PHOTON_API_USE_HTTPS: true
|
|
||||||
stdin_open: true
|
stdin_open: true
|
||||||
tty: true
|
tty: true
|
||||||
entrypoint: dev-entrypoint.sh
|
entrypoint: dev-entrypoint.sh
|
||||||
|
|
@ -101,8 +99,6 @@ services:
|
||||||
BACKGROUND_PROCESSING_CONCURRENCY: 10
|
BACKGROUND_PROCESSING_CONCURRENCY: 10
|
||||||
APPLICATION_PROTOCOL: http
|
APPLICATION_PROTOCOL: http
|
||||||
DISTANCE_UNIT: km
|
DISTANCE_UNIT: km
|
||||||
PHOTON_API_HOST: photon.komoot.io
|
|
||||||
PHOTON_API_USE_HTTPS: true
|
|
||||||
stdin_open: true
|
stdin_open: true
|
||||||
tty: true
|
tty: true
|
||||||
entrypoint: dev-entrypoint.sh
|
entrypoint: dev-entrypoint.sh
|
||||||
|
|
|
||||||
94
spec/lib/dawarich_settings_spec.rb
Normal file
94
spec/lib/dawarich_settings_spec.rb
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe DawarichSettings do
|
||||||
|
describe '.reverse_geocoding_enabled?' do
|
||||||
|
context 'when photon is enabled' do
|
||||||
|
before do
|
||||||
|
allow(described_class).to receive(:photon_enabled?).and_return(true)
|
||||||
|
allow(described_class).to receive(:geoapify_enabled?).and_return(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true' do
|
||||||
|
expect(described_class.reverse_geocoding_enabled?).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when geoapify is enabled' do
|
||||||
|
before do
|
||||||
|
allow(described_class).to receive(:photon_enabled?).and_return(false)
|
||||||
|
allow(described_class).to receive(:geoapify_enabled?).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true' do
|
||||||
|
expect(described_class.reverse_geocoding_enabled?).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when neither service is enabled' do
|
||||||
|
before do
|
||||||
|
allow(described_class).to receive(:photon_enabled?).and_return(false)
|
||||||
|
allow(described_class).to receive(:geoapify_enabled?).and_return(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false' do
|
||||||
|
expect(described_class.reverse_geocoding_enabled?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.photon_enabled?' do
|
||||||
|
context 'when PHOTON_API_HOST is present' do
|
||||||
|
before { stub_const('PHOTON_API_HOST', 'photon.example.com') }
|
||||||
|
|
||||||
|
it 'returns true' do
|
||||||
|
expect(described_class.photon_enabled?).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when PHOTON_API_HOST is blank' do
|
||||||
|
before { stub_const('PHOTON_API_HOST', '') }
|
||||||
|
|
||||||
|
it 'returns false' do
|
||||||
|
expect(described_class.photon_enabled?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.photon_uses_komoot_io?' do
|
||||||
|
context 'when PHOTON_API_HOST is komoot.io' do
|
||||||
|
before { stub_const('PHOTON_API_HOST', 'photon.komoot.io') }
|
||||||
|
|
||||||
|
it 'returns true' do
|
||||||
|
expect(described_class.photon_uses_komoot_io?).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when PHOTON_API_HOST is different' do
|
||||||
|
before { stub_const('PHOTON_API_HOST', 'photon.example.com') }
|
||||||
|
|
||||||
|
it 'returns false' do
|
||||||
|
expect(described_class.photon_uses_komoot_io?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.geoapify_enabled?' do
|
||||||
|
context 'when GEOAPIFY_API_KEY is present' do
|
||||||
|
before { stub_const('GEOAPIFY_API_KEY', 'some-api-key') }
|
||||||
|
|
||||||
|
it 'returns true' do
|
||||||
|
expect(described_class.geoapify_enabled?).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when GEOAPIFY_API_KEY is blank' do
|
||||||
|
before { stub_const('GEOAPIFY_API_KEY', '') }
|
||||||
|
|
||||||
|
it 'returns false' do
|
||||||
|
expect(described_class.geoapify_enabled?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue