Class: SkullIsland::Resources::Route

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

Overview

The Route 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 rubocop:disable Metrics/AbcSize



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/skull_island/resources/route.rb', line 33

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 |rdata, index|
    resource = new
    resource.name = rdata['name']
    resource.methods = rdata['methods'] if rdata['methods']
    resource.paths = rdata['paths'] if rdata['paths']
    resource.protocols = rdata['protocols'] if rdata['protocols']
    resource.delayed_set(:hosts, rdata) if rdata['hosts']
    resource.delayed_set(:headers, rdata) if rdata['headers']
    if rdata['https_redirect_status_code']
      resource.https_redirect_status_code = rdata['https_redirect_status_code']
    end
    resource.regex_priority = rdata['regex_priority'] if rdata['regex_priority']
    resource.strip_path = rdata['strip_path'] unless rdata['strip_path'].nil?
    resource.preserve_host = rdata['preserve_host'] unless rdata['preserve_host'].nil?
    resource.delayed_set(:snis, rdata) if rdata['snis']
    resource.tags = rdata['tags'] if rdata['tags']
    resource.project = project if project
    resource.import_time = (time || Time.now.utc.to_i) if project
    resource.delayed_set(:service, rdata)
    resource.import_update_or_skip(index: index, verbose: verbose, test: test)
    known_ids << resource.id
  end

  cleanup_except(project, known_ids) if project
end

Instance Method Details

#created_atObject

The created_at property



26
# File 'lib/skull_island/resources/route.rb', line 26

property :created_at, read_only: true, postprocess: true

#destinationsObject

The destinations property



24
# File 'lib/skull_island/resources/route.rb', line 24

property :destinations

#export(options = {}) ⇒ Object

rubocop:disable Metrics/AbcSize



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/skull_island/resources/route.rb', line 73

def export(options = {})
  hash = {
    'name' => name,
    'methods' => methods,
    'paths' => paths,
    'protocols' => protocols,
    'hosts' => hosts,
    'https_redirect_status_code' => https_redirect_status_code,
    'regex_priority' => regex_priority,
    'strip_path' => strip_path?,
    'preserve_host' => preserve_host?
  }
  hash['service'] = "<%= lookup :service, '#{service.name}' %>" if service
  hash['snis'] = snis if snis && !snis.empty?
  hash['headers'] = headers if headers && !headers.empty?
  hash['tags'] = tags unless tags.empty?
  [*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

#headersObject

The headers property



16
# File 'lib/skull_island/resources/route.rb', line 16

property :headers,        validate: true

#hostsObject

The hosts property



17
# File 'lib/skull_island/resources/route.rb', line 17

property :hosts,          validate: true

#https_redirect_status_codeObject

The https_redirect_status_code property



18
# File 'lib/skull_island/resources/route.rb', line 18

property :https_redirect_status_code, validate: true

#methodsObject

The methods property



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

property :methods

#modified_existing?Boolean

rubocop:enable Metrics/AbcSize

Returns:

  • (Boolean)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/skull_island/resources/route.rb', line 99

def modified_existing?
  return false unless new?

  # Find routes of the same name and service
  same_name_and_service = self.class.where(:name, name).and(:service, service)

  existing = same_name_and_service.size == 1 ? same_name_and_service.first : nil

  if existing
    @entity['id'] = existing.id
    save
  else
    false
  end
end

#nameObject

The name property



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

property :name

#pathsObject

The paths property



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

property :paths

#pluginsObject

Provides a collection of related Plugin instances



68
69
70
# File 'lib/skull_island/resources/route.rb', line 68

def plugins
  Plugin.where(:route, self, api_client: api_client)
end

#preserve_hostObject

The preserve_host property



21
# File 'lib/skull_island/resources/route.rb', line 21

property :preserve_host,  type: :boolean

#protocolsObject

The protocols property



15
# File 'lib/skull_island/resources/route.rb', line 15

property :protocols,      validate: true

#regex_priorityObject

The regex_priority property



19
# File 'lib/skull_island/resources/route.rb', line 19

property :regex_priority, validate: true

#serviceObject

The service property



25
# File 'lib/skull_island/resources/route.rb', line 25

property :service, validate: true, preprocess: true, postprocess: true

#snisObject

The snis property



22
# File 'lib/skull_island/resources/route.rb', line 22

property :snis,           validate: true

#sourcesObject

The sources property



23
# File 'lib/skull_island/resources/route.rb', line 23

property :sources

#strip_pathObject

The strip_path property



20
# File 'lib/skull_island/resources/route.rb', line 20

property :strip_path,     type: :boolean

#tagsObject

The tags property



28
# File 'lib/skull_island/resources/route.rb', line 28

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

#updated_atObject

The updated_at property



27
# File 'lib/skull_island/resources/route.rb', line 27

property :updated_at, read_only: true, postprocess: true