class SkullIsland::Resources::CACertificate

The CA Certificate resource class

@see docs.konghq.com/1.4.x/admin-api/#ca-certificate-object CA Certificate definition

Public Class Methods

batch_import(data, verbose: false, test: false, project: nil, time: nil) click to toggle source

rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity

# File lib/skull_island/resources/ca_certificate.rb, line 19
def self.batch_import(data, verbose: false, test: false, project: nil, time: nil)
  raise(Exceptions::InvalidArguments) unless data.is_a?(Array)

  known_ids = []

  data.each_with_index do |resource_data, index|
    resource = new
    resource.delayed_set(:cert, resource_data)
    resource.tags = resource_data['tags'] if resource_data['tags']
    resource.name = resource_data['name'] if resource_data['name']
    resource.project = project if project
    resource.import_time = (time || Time.now.utc.to_i) if project
    resource.import_update_or_skip(index: index, verbose: verbose, test: test)
    known_ids << resource.id
  end

  cleanup_except(project, known_ids) if project

  known_ids
end

Public Instance Methods

export(options = {}) click to toggle source

rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity

# File lib/skull_island/resources/ca_certificate.rb, line 42
def export(options = {})
  hash = { 'cert' => cert }
  hash['tags'] = tags unless tags.empty?
  hash['name'] = name if name
  [*options[:exclude]].each do |exclude|
    hash.delete(exclude.to_s)
  end
  [*options[:include]].each do |inc|
    hash[inc.to_s] = send(inc.to_sym)
  end
  hash.reject { |_, value| value.nil? }
end
modified_existing?() click to toggle source
# File lib/skull_island/resources/ca_certificate.rb, line 55
def modified_existing?
  return false unless new?

  # Find CA certs of the same "name"
  if name
    same_name = self.class.where(:name, name)

    existing = same_name.size == 1 ? same_name.first : nil
  end

  unless existing
    # Find CA certs of the same cert
    same_cert = self.class.where(:cert, cert)

    existing = same_cert.size == 1 ? same_cert.first : nil
  end

  if existing
    @entity['id'] = existing.id
    save
  else
    false
  end
end
name() click to toggle source

Simulates retrieving a name property via a tag

# File lib/skull_island/resources/ca_certificate.rb, line 81
def name
  metatags['name']
end
name=(value) click to toggle source

Simulates setting a name property via a tag

# File lib/skull_island/resources/ca_certificate.rb, line 86
def name=(value)
  add_meta('name', value.to_s)
end

Private Instance Methods

validate_cert(value) click to toggle source

Used to validate {#cert} on set

# File lib/skull_island/resources/ca_certificate.rb, line 93
def validate_cert(value)
  # only String is allowed
  value.is_a?(String)
end