Class: SkullIsland::Resources::CACertificate

Inherits:
SkullIsland::Resource show all
Includes:
Helpers::Meta
Defined in:
lib/skull_island/resources/ca_certificate.rb

Overview

The CA Certificate resource class

Instance Attribute Summary

Attributes inherited from SkullIsland::Resource

#api_client, #entity, #errors

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Meta

#add_meta, #import_time, #import_time=, #metatags, #postprocess_tags, #preprocess_tags, #project, #project=, #raw_tags, #remove_meta, #supports_meta?

Methods inherited from SkullIsland::Resource

all, cleanup_except, find, from_hash, gen_getter_method, gen_property_methods, gen_setter_method, get, immutable, #initialize, property, relative_uri, #relative_uri, where

Methods included from Helpers::ResourceClass

#determine_getter_names, #determine_setter_names, #human, #i18n_key, #immutable?, #param_key, #properties, #route_key

Methods included from Helpers::Resource

#<=>, #datetime_from_params, #delayed_set, #destroy, #digest, #digest_properties, #find_by_digest, #fresh?, #host_regex, #id, #id_property, #immutable?, #import_update_or_skip, #lookup, #model_name, #new?, #persisted?, #postprocess_created_at, #postprocess_updated_at, #properties, #prune_for_save, #recursive_erubi, #reload, #required_properties, #save, #save_uri, #supports_meta?, #tainted?, #to_param, #to_s, #update

Methods included from Validations::Resource

#validate_id, #validate_mutability, #validate_required_properties, #validate_tags

Constructor Details

This class inherits a constructor from SkullIsland::Resource

Class Method Details

.batch_import(data, verbose: false, test: false, project: nil, time: nil) ⇒ Object

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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

Instance Method Details

#certObject

The cert property



12
# File 'lib/skull_island/resources/ca_certificate.rb', line 12

property :cert, required: true, validate: true

#created_atObject

The created_at property



13
# File 'lib/skull_island/resources/ca_certificate.rb', line 13

property :created_at, read_only: true, postprocess: true

#export(options = {}) ⇒ Object

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



42
43
44
45
46
47
48
49
50
51
52
53
# 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?Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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

#nameObject

Simulates retrieving a #name property via a tag



81
82
83
# File 'lib/skull_island/resources/ca_certificate.rb', line 81

def name
  metatags['name']
end

#name=(value) ⇒ Object

Simulates setting a #name property via a tag



86
87
88
# File 'lib/skull_island/resources/ca_certificate.rb', line 86

def name=(value)
  add_meta('name', value.to_s)
end

#tagsObject

The tags property



14
# File 'lib/skull_island/resources/ca_certificate.rb', line 14

property :tags, validate: true, preprocess: true, postprocess: true