class Akamai::API::CPS

Constants

VERSION

Public Class Methods

new(edgerc: '~/.edgerc', section: 'default', debug: false) click to toggle source
# File lib/akamai/api/cps.rb, line 11
def initialize(edgerc: '~/.edgerc', section: 'default', debug: false)
  edgerc_path = File.expand_path(edgerc)
  @http = Akamai::Edgegrid::HTTP.new(get_host(edgerc_path, section), 443)
  @http.setup_from_edgerc(debug: debug, filename: edgerc_path, section: section)
end

Public Instance Methods

enrollments(contract_id) click to toggle source
# File lib/akamai/api/cps.rb, line 17
def enrollments(contract_id)
  response = api_get("/enrollments?contractId=#{contract_id}", 'application/vnd.akamai.cps.enrollments.v5+json')
  response.enrollments
end
production_certificate(enrollment_id) click to toggle source
# File lib/akamai/api/cps.rb, line 22
def production_certificate(enrollment_id)
  get_certificate(enrollment_id, 'production')
end
production_full_chain(enrollment_id) click to toggle source
# File lib/akamai/api/cps.rb, line 26
def production_full_chain(enrollment_id)
  get_full_chain(enrollment_id, 'production')
end
staging_certificate(enrollment_id) click to toggle source
# File lib/akamai/api/cps.rb, line 30
def staging_certificate(enrollment_id)
  get_certificate(enrollment_id, 'staging')
end
staging_full_chain(enrollment_id) click to toggle source
# File lib/akamai/api/cps.rb, line 34
def staging_full_chain(enrollment_id)
  get_full_chain(enrollment_id, 'staging')
end

Private Instance Methods

api_get(endpoint, accept) click to toggle source
# File lib/akamai/api/cps.rb, line 41
def api_get(endpoint, accept)
  baseuri = URI('https://' + @http.host)
  uri = URI.join(baseuri.to_s, '/cps/v2' + endpoint).to_s

  request = Net::HTTP::Get.new(uri)
  request['Accept'] = accept
  response = @http.request(request)

  return nil if response.code.to_i == 404
  JSON.parse(response.body, object_class: OpenStruct)
end
get_certificate(enrollment_id, environment) click to toggle source
# File lib/akamai/api/cps.rb, line 53
def get_certificate(enrollment_id, environment)
  response = get_deployment(enrollment_id, environment)
  return nil if response.nil?
  OpenSSL::X509::Certificate.new(response.certificate)
end
get_deployment(enrollment_id, environment) click to toggle source
# File lib/akamai/api/cps.rb, line 65
def get_deployment(enrollment_id, environment)
  api_get("/enrollments/#{enrollment_id}/deployments/#{environment}", 'application/vnd.akamai.cps.deployment.v3+json')
end
get_full_chain(enrollment_id, environment) click to toggle source
# File lib/akamai/api/cps.rb, line 59
def get_full_chain(enrollment_id, environment)
  response = get_deployment(enrollment_id, environment)
  return nil if response.nil?
  [response.certificate, response.trustChain].join("\n")
end