mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
Refactor and updated api user serializer
This commit is contained in:
parent
b48c22f6f3
commit
bf3d971d7c
3 changed files with 20 additions and 15 deletions
|
@ -7,7 +7,7 @@ module Repp
|
||||||
include Shunter::Integration::Throttle
|
include Shunter::Integration::Throttle
|
||||||
|
|
||||||
api :GET, '/repp/v1/white_ips'
|
api :GET, '/repp/v1/white_ips'
|
||||||
desc 'Get all whitelisted ips'
|
desc 'Get all whitelisted IPs'
|
||||||
def index
|
def index
|
||||||
ips = current_user.registrar.white_ips
|
ips = current_user.registrar.white_ips
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ module Repp
|
||||||
end
|
end
|
||||||
|
|
||||||
api :PUT, '/repp/v1/white_ips/:id'
|
api :PUT, '/repp/v1/white_ips/:id'
|
||||||
desc 'Update whitelisted ip address'
|
desc 'Update whitelisted IP address'
|
||||||
def update
|
def update
|
||||||
unless @white_ip.update(white_ip_params)
|
unless @white_ip.update(white_ip_params)
|
||||||
handle_non_epp_errors(@white_ip)
|
handle_non_epp_errors(@white_ip)
|
||||||
|
@ -39,7 +39,7 @@ module Repp
|
||||||
end
|
end
|
||||||
|
|
||||||
api :DELETE, '/repp/v1/white_ips/:id'
|
api :DELETE, '/repp/v1/white_ips/:id'
|
||||||
desc 'Delete a specific whitelisted ip address'
|
desc 'Delete a specific whitelisted IP address'
|
||||||
def destroy
|
def destroy
|
||||||
unless @white_ip.destroy
|
unless @white_ip.destroy
|
||||||
handle_non_epp_errors(@white_ip)
|
handle_non_epp_errors(@white_ip)
|
||||||
|
|
|
@ -5,15 +5,15 @@ class Certificate < ApplicationRecord
|
||||||
|
|
||||||
belongs_to :api_user
|
belongs_to :api_user
|
||||||
|
|
||||||
SIGNED = 'signed'
|
SIGNED = 'signed'.freeze
|
||||||
UNSIGNED = 'unsigned'
|
UNSIGNED = 'unsigned'.freeze
|
||||||
EXPIRED = 'expired'
|
EXPIRED = 'expired'.freeze
|
||||||
REVOKED = 'revoked'
|
REVOKED = 'revoked'.freeze
|
||||||
VALID = 'valid'
|
VALID = 'valid'.freeze
|
||||||
|
|
||||||
API = 'api'
|
API = 'api'.freeze
|
||||||
REGISTRAR = 'registrar'
|
REGISTRAR = 'registrar'.freeze
|
||||||
INTERFACES = [API, REGISTRAR]
|
INTERFACES = [API, REGISTRAR].freeze
|
||||||
|
|
||||||
scope 'api', -> { where(interface: API) }
|
scope 'api', -> { where(interface: API) }
|
||||||
scope 'registrar', -> { where(interface: REGISTRAR) }
|
scope 'registrar', -> { where(interface: REGISTRAR) }
|
||||||
|
@ -21,6 +21,7 @@ class Certificate < ApplicationRecord
|
||||||
validate :validate_csr_and_crt_presence
|
validate :validate_csr_and_crt_presence
|
||||||
def validate_csr_and_crt_presence
|
def validate_csr_and_crt_presence
|
||||||
return if csr.try(:scrub).present? || crt.try(:scrub).present?
|
return if csr.try(:scrub).present? || crt.try(:scrub).present?
|
||||||
|
|
||||||
errors.add(:base, I18n.t(:crt_or_csr_must_be_present))
|
errors.add(:base, I18n.t(:crt_or_csr_must_be_present))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,8 +29,8 @@ class Certificate < ApplicationRecord
|
||||||
def validate_csr_and_crt
|
def validate_csr_and_crt
|
||||||
parsed_crt
|
parsed_crt
|
||||||
parsed_csr
|
parsed_csr
|
||||||
rescue OpenSSL::X509::RequestError, OpenSSL::X509::CertificateError
|
rescue OpenSSL::X509::RequestError, OpenSSL::X509::CertificateError
|
||||||
errors.add(:base, I18n.t(:invalid_csr_or_crt))
|
errors.add(:base, I18n.t(:invalid_csr_or_crt))
|
||||||
end
|
end
|
||||||
|
|
||||||
validate :assign_metadata, on: :create
|
validate :assign_metadata, on: :create
|
||||||
|
@ -67,7 +68,8 @@ class Certificate < ApplicationRecord
|
||||||
|
|
||||||
@cached_status = SIGNED
|
@cached_status = SIGNED
|
||||||
|
|
||||||
@cached_status = EXPIRED if parsed_crt.not_before > Time.zone.now.utc && parsed_crt.not_after < Time.zone.now.utc
|
expired = parsed_crt.not_before > Time.zone.now.utc && parsed_crt.not_after < Time.zone.now.utc
|
||||||
|
@cached_status = EXPIRED if expired
|
||||||
|
|
||||||
crl = OpenSSL::X509::CRL.new(File.open("#{ENV['crl_dir']}/crl.pem").read)
|
crl = OpenSSL::X509::CRL.new(File.open("#{ENV['crl_dir']}/crl.pem").read)
|
||||||
return @cached_status unless crl.revoked.map(&:serial).include?(parsed_crt.serial)
|
return @cached_status unless crl.revoked.map(&:serial).include?(parsed_crt.serial)
|
||||||
|
@ -144,7 +146,8 @@ class Certificate < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_md_from_string(crt)
|
def parse_md_from_string(crt)
|
||||||
return nil if crt.blank?
|
return if crt.blank?
|
||||||
|
|
||||||
crt = crt.split(' ').join("\n")
|
crt = crt.split(' ').join("\n")
|
||||||
crt.gsub!("-----BEGIN\nCERTIFICATE-----\n", "-----BEGIN CERTIFICATE-----\n")
|
crt.gsub!("-----BEGIN\nCERTIFICATE-----\n", "-----BEGIN CERTIFICATE-----\n")
|
||||||
crt.gsub!("\n-----END\nCERTIFICATE-----", "\n-----END CERTIFICATE-----")
|
crt.gsub!("\n-----END\nCERTIFICATE-----", "\n-----END CERTIFICATE-----")
|
||||||
|
|
|
@ -21,6 +21,8 @@ module Serializers
|
||||||
accreditation_expire_date: obj.accreditation_expire_date,
|
accreditation_expire_date: obj.accreditation_expire_date,
|
||||||
created_at: obj.created_at,
|
created_at: obj.created_at,
|
||||||
updated_at: obj.updated_at,
|
updated_at: obj.updated_at,
|
||||||
|
creator: obj.creator_str,
|
||||||
|
updator: obj.updator_str,
|
||||||
}
|
}
|
||||||
json[:certificates] = certificates
|
json[:certificates] = certificates
|
||||||
json
|
json
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue