mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 15:14:47 +02:00
Fix codeclimate issues
This commit is contained in:
parent
06f5eb10d4
commit
90b2455032
5 changed files with 13 additions and 14 deletions
|
@ -28,7 +28,7 @@ module API
|
|||
private
|
||||
|
||||
def eid_params
|
||||
required_params = [:ident, :first_name, :last_name]
|
||||
required_params = %i[ident first_name last_name]
|
||||
required_params.each_with_object(params) do |key, obj|
|
||||
obj.require(key)
|
||||
end
|
||||
|
@ -44,10 +44,9 @@ module API
|
|||
|
||||
def check_ip_whitelist
|
||||
allowed_ips = ENV['registrant_api_auth_allowed_ips'].to_s.split(',').map(&:strip)
|
||||
return if allowed_ips.include?(request.ip) || Rails.env.development?
|
||||
|
||||
unless allowed_ips.include?(request.ip) || Rails.env.development?
|
||||
render json: { error: 'Not authorized' }, status: 401
|
||||
end
|
||||
render json: { error: 'Not authorized' }, status: :unauthorized
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ module API
|
|||
def bearer_token
|
||||
pattern = /^Bearer /
|
||||
header = request.headers['Authorization']
|
||||
header.gsub(pattern, '') if header && header.match(pattern)
|
||||
header.gsub(pattern, '') if header&.match(pattern)
|
||||
end
|
||||
|
||||
def authenticate
|
||||
|
@ -29,7 +29,7 @@ module API
|
|||
if decryptor.valid?
|
||||
sign_in decryptor.user
|
||||
else
|
||||
render json: { error: 'Not authorized' }, status: 401
|
||||
render json: { error: 'Not authorized' }, status: :unauthorized
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -54,8 +54,8 @@ class RegistrantUser < User
|
|||
return false unless user_data[:first_name]
|
||||
return false unless user_data[:last_name]
|
||||
|
||||
user_data.each { |k, v| v.upcase! if v.is_a?(String) }
|
||||
user_data[:country_code] ||= "EE"
|
||||
user_data.each_value { |v| v.upcase! if v.is_a?(String) }
|
||||
user_data[:country_code] ||= 'EE'
|
||||
|
||||
find_or_create_by_user_data(user_data)
|
||||
end
|
||||
|
|
|
@ -6,20 +6,20 @@ class AuthTokenCreator
|
|||
attr_reader :expires_at
|
||||
|
||||
def self.create_with_defaults(user)
|
||||
self.new(user, Rails.application.config.secret_key_base, Time.now + DEFAULT_VALIDITY)
|
||||
new(user, Rails.application.config.secret_key_base, Time.now + DEFAULT_VALIDITY)
|
||||
end
|
||||
|
||||
def initialize(user, key, expires_at)
|
||||
@user = user
|
||||
@key = key
|
||||
@expires_at = expires_at.utc.strftime("%F %T %Z")
|
||||
@expires_at = expires_at.utc.strftime('%F %T %Z')
|
||||
end
|
||||
|
||||
def hashable
|
||||
{
|
||||
user_ident: user.registrant_ident,
|
||||
user_username: user.username,
|
||||
expires_at: expires_at
|
||||
expires_at: expires_at,
|
||||
}.to_json
|
||||
end
|
||||
|
||||
|
@ -35,7 +35,7 @@ class AuthTokenCreator
|
|||
{
|
||||
access_token: encrypted_token,
|
||||
expires_at: expires_at,
|
||||
type: 'Bearer'
|
||||
type: 'Bearer',
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ class AuthTokenDecryptor
|
|||
attr_reader :user
|
||||
|
||||
def self.create_with_defaults(token)
|
||||
self.new(token, Rails.application.config.secret_key_base)
|
||||
new(token, Rails.application.config.secret_key_base)
|
||||
end
|
||||
|
||||
def initialize(token, key)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue