Class: SkullIsland::Resources::KeyauthCredential

Inherits:
SkullIsland::Resource show all
Defined in:
lib/skull_island/resources/keyauth_credential.rb

Overview

The KeyauthCredential resource class

Instance Attribute Summary

Attributes inherited from SkullIsland::Resource

#api_client, #entity, #errors

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SkullIsland::Resource

all, cleanup_except, find, from_hash, gen_getter_method, gen_property_methods, gen_setter_method, get, immutable, #initialize, property, 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, #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) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/skull_island/resources/keyauth_credential.rb', line 17

def self.batch_import(data, verbose: false, test: false)
  raise(Exceptions::InvalidArguments) unless data.is_a?(Array)

  known_ids = []

  data.each_with_index do |resource_data, index|
    resource = new
    resource.delayed_set(:key, resource_data)
    resource.delayed_set(:consumer, resource_data)
    resource.import_update_or_skip(index: index, verbose: verbose, test: test)
    known_ids << resource.id
  end

  known_ids
end

.relative_uriObject



33
34
35
# File 'lib/skull_island/resources/keyauth_credential.rb', line 33

def self.relative_uri
  'key-auths'
end

Instance Method Details

#consumerObject

The consumer property



11
12
13
14
# File 'lib/skull_island/resources/keyauth_credential.rb', line 11

property(
  :consumer,
  required: true, validate: true, preprocess: true, postprocess: true
)

#created_atObject

The created_at property



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

property :created_at, read_only: true, postprocess: true

#export(options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/skull_island/resources/keyauth_credential.rb', line 45

def export(options = {})
  hash = { 'key' => key }
  hash['consumer'] = "<%= lookup :consumer, '#{consumer.username}' %>" if consumer
  [*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

#keyObject

The key property



10
# File 'lib/skull_island/resources/keyauth_credential.rb', line 10

property :key, validate: true

#modified_existing?Boolean

Keys can’t be updated, only created or deleted

Returns:

  • (Boolean)


58
59
60
# File 'lib/skull_island/resources/keyauth_credential.rb', line 58

def modified_existing?
  false
end

#projectObject



62
63
64
# File 'lib/skull_island/resources/keyauth_credential.rb', line 62

def project
  consumer ? consumer.project : nil
end

#relative_uriObject



37
38
39
# File 'lib/skull_island/resources/keyauth_credential.rb', line 37

def relative_uri
  consumer ? "#{consumer.relative_uri}/key-auth/#{id}" : nil
end

#save_uriObject



41
42
43
# File 'lib/skull_island/resources/keyauth_credential.rb', line 41

def save_uri
  consumer ? "#{consumer.relative_uri}/key-auth" : nil
end