Class: CloudflareClient::Zone::CustomSSL

Inherits:
Base show all
Defined in:
lib/cloudflare_client/zone/custom_ssl.rb

Constant Summary collapse

VALID_ORDERS =
%w[status issuer priority expires_on].freeze

Constants inherited from CloudflareClient::Zone

VALID_ZONE_STATUSES

Constants inherited from CloudflareClient

API_BASE, POSSIBLE_API_SETTINGS, VALID_BUNDLE_METHODS, VALID_DIRECTIONS, VALID_MATCHES, VERSION

Instance Attribute Summary

Attributes inherited from Base

#zone_id

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods inherited from CloudflareClient::Zone

#create_zone, #delete_zone, #edit_zone, #initialize, #purge_zone_cache, #update_zone_settings, #zone, #zone_activation_check, #zone_setting, #zone_settings, #zones

Methods inherited from CloudflareClient

#initialize

Constructor Details

This class inherits a constructor from CloudflareClient::Zone::Base

Instance Method Details

#create(certificate:, private_key:, bundle_method: nil) ⇒ Object

create custom ssl for a zone



9
10
11
12
13
14
15
16
17
18
# File 'lib/cloudflare_client/zone/custom_ssl.rb', line 9

def create(certificate:, private_key:, bundle_method: nil)
  id_check('certificate', certificate)
  id_check('private_key', private_key)
  bundle_method_check(bundle_method) unless bundle_method.nil?
  # TODO: validate the cert/key using openssl?  Could be difficult if they are
  # privately generated
  data = {certificate: certificate, private_key: private_key}
  data[:bundle_method] = bundle_method unless bundle_method.nil?
  cf_post(path: "/zones/#{zone_id}/custom_certificates", data: data)
end

#delete(id:) ⇒ Object

delete a custom ssl cert



58
59
60
61
# File 'lib/cloudflare_client/zone/custom_ssl.rb', line 58

def delete(id:)
  id_check('id', id)
  cf_delete(path: "/zones/#{zone_id}/custom_certificates/#{id}")
end

#list(page: 1, per_page: 50, order: 'priority', direction: 'asc', match: 'all') ⇒ Object

list custom ssl configurations



22
23
24
25
26
27
28
29
30
# File 'lib/cloudflare_client/zone/custom_ssl.rb', line 22

def list(page: 1, per_page: 50, order: 'priority', direction: 'asc', match: 'all')
  raise ("order must be one of #{VALID_ORDERS}") unless VALID_ORDERS.include?(order)
  raise ('direction must be asc || desc') unless (direction == 'asc' || direction == 'desc')
  raise ('match must be all || any') unless (match == 'any' || match == 'all')
  params = {page: page, per_page: per_page}
  params[:match] = match
  params[:direction] = direction
  cf_get(path: "/zones/#{zone_id}/custom_certficates", params: params)
end

#prioritize(data: []) ⇒ Object

re-prioritize ssl certs data = [“cert_id”, priority: 2, “cert_id”, priority: 1]



51
52
53
54
# File 'lib/cloudflare_client/zone/custom_ssl.rb', line 51

def prioritize(data: [])
  raise 'must provide an array of certifiates and priorities' unless data.is_a?(Array) && !data.empty?
  cf_put(path: "/zones/#{zone_id}/custom_certificates/prioritize", data: data)
end

#show(configuration_id:) ⇒ Object

details of a single config



34
35
36
37
# File 'lib/cloudflare_client/zone/custom_ssl.rb', line 34

def show(configuration_id:)
  raise 'ssl configuration id required' if configuration_id.nil?
  cf_get(path: "/zones/#{zone_id}/custom_certificates/#{configuration_id}")
end

#update(id:, private_key: nil, certificate: nil, bundle_method: nil) ⇒ Object

updates a custom ssl record



41
42
43
44
45
46
47
# File 'lib/cloudflare_client/zone/custom_ssl.rb', line 41

def update(id:, private_key: nil, certificate: nil, bundle_method: nil)
  id_check('id', id)
  id_check('private_key must be provided') if private_key.nil?
  bundle_method_check(bundle_method)
  data = {private_key: private_key, certificate: certificate, bundle_method: bundle_method}
  cf_patch(path: "/zones/#{zone_id}/custom_certificates/#{id}", data: data)
end