class OpenDelivery::Domain

Public Class Methods

new(region=nil, key_path=nil) click to toggle source
# File lib/opendelivery/domain.rb, line 29
def initialize(region=nil, key_path=nil)
  @key_path = File.read(key_path) unless key_path.nil?

  if region.nil?
    @sdb = Aws::SimpleDB::Client.new
  else
    @sdb = Aws::SimpleDB::Client.new(:region => region)
  end
end

Public Instance Methods

create(domain) click to toggle source
# File lib/opendelivery/domain.rb, line 39
def create(domain)
  @sdb.create_domain(domain_name: domain)
end
destroy(domain) click to toggle source
# File lib/opendelivery/domain.rb, line 43
def destroy(domain)
  @sdb.delete_domain(domain_name: domain)
end
destroy_item(domain, item_name) click to toggle source
# File lib/opendelivery/domain.rb, line 47
def destroy_item(domain, item_name)
  @sdb.delete_attributes(domain_name: domain,
                         item_name: item_name)
end
get_encrypted_property(domain, item_name, key) click to toggle source
# File lib/opendelivery/domain.rb, line 61
def get_encrypted_property(domain, item_name, key)
  value = get_property(domain, item_name, key)
  EncryptoSigno.decrypt(@key_path, value.chomp)
end
get_item_attributes_json(domain, item_name) click to toggle source
# File lib/opendelivery/domain.rb, line 79
def get_item_attributes_json(domain, item_name)
  get_attributes_response = @sdb.get_attributes(domain_name: domain,
                                                item_name: item_name,
                                                consistent_read: true)

  if get_attributes_response.attributes.empty?
    nil
  else
    JSON.generate(get_attributes_response.attributes.map { |attribute|
      { name: attribute.name, value: attribute.value }
    })
  end
end
get_property(domain, item_name, key) click to toggle source
# File lib/opendelivery/domain.rb, line 66
def get_property(domain, item_name, key)
  get_attributes_response = @sdb.get_attributes(domain_name: domain,
                                                item_name: item_name,
                                                attribute_names: [key],
                                                consistent_read: true)

  if get_attributes_response.attributes.empty?
    nil
  else
    get_attributes_response.attributes.first.value.chomp
  end
end
load_domain(domain, json_file) click to toggle source
# File lib/opendelivery/domain.rb, line 110
def load_domain(domain, json_file)
  json = File.read(json_file)
  obj = JSON.parse(json)

  obj.each do |item, attributes|
    attributes.each do |key,value|
      set_property(domain, item, key, value)
    end
  end
end
load_stack_properties(domain, stack) click to toggle source
# File lib/opendelivery/domain.rb, line 52
def load_stack_properties(domain, stack)
  stack.resources.each do |resource|
    set_property(domain,
                 stack.name,
                 resource.resource_type,
                 resource.physical_resource_id)
  end
end
set_encrypted_property(domain, item_name, key, value) click to toggle source
# File lib/opendelivery/domain.rb, line 93
def set_encrypted_property(domain, item_name, key, value)
  encrypted_value = EncryptoSigno.encrypt(@key_path, value.chomp)
  set_property(domain, item_name, key, encrypted_value)
end
set_property(domain, item_name, key, value) click to toggle source
# File lib/opendelivery/domain.rb, line 98
def set_property(domain, item_name, key, value)
  @sdb.put_attributes(domain_name: domain,
                      item_name: item_name,
                      attributes: [
                        {
                          name: key,
                          value: value,
                          replace: true,
                        }
                      ])
end