Implement shared key authentication to bounces API

This commit is contained in:
Karl Erik Õunapuu 2020-09-17 16:26:50 +03:00
parent b2c5a9a5ec
commit 03182f9222
No known key found for this signature in database
GPG key ID: C9DD647298A34764
3 changed files with 11 additions and 1 deletions

View file

@ -10,6 +10,11 @@ module Api
head :unauthorized unless ip_allowed
end
def authenticate_shared_key
api_key = "Basic #{ENV['api_shared_key']}"
head(:unauthorized) unless api_key == request.authorization
end
def not_found_error
uuid = params['uuid']
json = { error: 'Not Found', uuid: uuid, message: 'Record not found' }

View file

@ -1,10 +1,12 @@
module Api
module V1
class BouncesController < BaseController
before_action :authenticate_shared_key
# POST api/v1/bounces/
def create
BouncedMailAddress.record(bounce_params)
head(:ok)
head(:created)
rescue ActionController::ParameterMissing
head(:bad_request)
end

View file

@ -87,6 +87,9 @@ sk_digi_doc_service_name: 'Testimine'
registrant_api_base_url:
registrant_api_auth_allowed_ips: '127.0.0.1, 0.0.0.0' #ips, separated with commas
# Bounces API
api_shared_key: testkey
#
# MISC