diff --git a/.gitignore b/.gitignore index dd68ef8..17b40d7 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,6 @@ # Ignore all logfiles and tempfiles. /log/*.log /tmp -config/morph.yml /coverage .vagrant /node_modules diff --git a/app/controllers/import_controller.rb b/app/controllers/import_controller.rb index 1e15da7..566f4f2 100644 --- a/app/controllers/import_controller.rb +++ b/app/controllers/import_controller.rb @@ -4,14 +4,21 @@ class ImportController < ApplicationController skip_before_action :verify_authenticity_token, only: [:new_papers_callback] def new_papers_callback + received_secret = params[:secret] + expected_secret = Rails.application.config.shared_import_secret + if received_secret != expected_secret + print("secrets not match") + return + end + require 'open-uri' #api_key = Rails.application.config_for(:morph)['key'] #uri = URI.parse("https://api.morph.io/jrlover/city_council_leipzig_recent_papers/data.json?key=#{api_key}&query=select%20*%20from%20%27data%27") print("before parse") uri = URI.parse("https://joergreichert.de/srm/input.json") print("after parse") - #Paper.import_from_json(uri.read) + Paper.import_from_json(uri.read) print("after import") - render nothing: true + head :no_content end end diff --git a/config/environments/development.rb b/config/environments/development.rb index 340b77e..116c045 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -41,4 +41,5 @@ Rails.application.configure do $stdout.sync = true config.hosts = ENV['APPLICATION_HOST'] || 'localhost' + config.shared_import_secret = ENV['SHARED_IMPORT_SECRET'] end diff --git a/config/environments/production.rb b/config/environments/production.rb index 64144c8..d69448a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -77,4 +77,5 @@ Rails.application.configure do config.active_record.dump_schema_after_migration = false config.hosts = ENV['APPLICATION_HOST'] || 'stadtratmonitor.leipzig.codefor.de' + config.shared_import_secret = ENV['SHARED_IMPORT_SECRET'] end diff --git a/config/morph.yml.example b/config/morph.yml.example deleted file mode 100644 index 6a37aa4..0000000 --- a/config/morph.yml.example +++ /dev/null @@ -1,2 +0,0 @@ -development: - key: insertyourkeyhere diff --git a/docker-compose.yml b/docker-compose.yml index 9e3afb9..02848c9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,7 @@ services: environment: - ELASTICSEARCH_URL=http://elasticsearch:9200 - APPLICATION_HOST=$APPLICATION_HOST + - SHARED_IMPORT_SECRET=$SHARED_IMPORT_SECRET command: sh -c "cd /home/srm/app && bundle exec puma -C config/puma.rb" elasticsearch: user: elasticsearch