1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

alpha sort methods in interfaces, split parsers into individual files

This commit is contained in:
Wesley Beary 2009-07-11 13:41:21 -07:00
parent c256b8f388
commit 43ab80e60d
28 changed files with 1109 additions and 880 deletions

View file

@ -3,7 +3,20 @@ require 'base64'
require 'cgi'
require 'hmac-sha2'
require File.dirname(__FILE__) + '/ec2/parsers'
parsers_directory = "#{File.dirname(__FILE__)}/parsers/ec2"
require "#{parsers_directory}/allocate_address"
require "#{parsers_directory}/basic"
require "#{parsers_directory}/create_key_pair"
require "#{parsers_directory}/create_snapshot"
require "#{parsers_directory}/create_volume"
require "#{parsers_directory}/describe_addresses"
require "#{parsers_directory}/describe_images"
require "#{parsers_directory}/describe_instances"
require "#{parsers_directory}/describe_key_pairs"
require "#{parsers_directory}/describe_security_groups"
require "#{parsers_directory}/describe_snapshots"
require "#{parsers_directory}/describe_volumes"
module Fog
module AWS

View file

@ -1,449 +0,0 @@
require File.dirname(__FILE__) + '/../../parser'
module Fog
module Parsers
module AWS
module EC2
class AllocateAddress < Fog::Parsers::Base
def end_element(name)
case name
when 'requestId'
@response[:request_id] = @value
when 'publicIp'
@response[:public_ip] = @value
end
end
end
class Basic < Fog::Parsers::Base
def end_element(name)
case name
when 'requestId'
@response[:request_id] = @value
when 'return'
if @value == 'true'
@response[:return] = true
else
@response[:return] = false
end
end
end
end
class CreateKeyPair < Fog::Parsers::Base
def end_element(name)
case name
when 'keyFingerprint'
@response[:key_fingerprint] = @value
when 'keyMaterial'
@response[:key_material] = @value
when 'keyName'
@response[:key_name] = @value
when 'requestId'
@response[:request_id] = @value
end
end
end
class CreateSnapshot < Fog::Parsers::Base
def end_element(name)
case name
when 'progress'
@response[:progress] = @value
when 'snapshotId'
@response[:snapshot_id] = @value
when 'startTime'
@response[:start_time] = Time.parse(@value)
when 'status'
@response[:status] = @value
when 'volumeId'
@response[:volume_id] = @value
end
end
end
class CreateVolume < Fog::Parsers::Base
def end_element(name)
case name
when 'availabilityZone'
@response[:availability_zone] = @value
when 'createTime'
@response[:create_time] = Time.parse(@value)
when 'requestId'
@response[:request_id] = @value
when 'size'
@response[:size] = @value.to_i
when 'snapshotId'
@response[:snapshot_id] = @value
when 'status'
@response[:status] = @value
when 'volumeId'
@response[:volume_id] = @value
end
end
end
class DescribeAddresses < Fog::Parsers::Base
def reset
@address = {}
@response = { :address_set => [] }
end
def end_element(name)
case name
when 'instanceId'
@address[:instance_id] = @value
when 'item'
@response[:address_set] << @address
@address = []
when 'publicIp'
@address[:public_ip] = @value
when 'requestId'
@response[:request_id] = @value
end
end
end
class DescribeImages < Fog::Parsers::Base
def reset
@image = { :product_codes => [] }
@response = { :image_set => [] }
end
def start_element(name, attrs = [])
if name == 'productCodes'
@in_product_codes = true
end
@value = ''
end
def end_element(name)
case name
when 'architecture'
@image[:architecture] = @value
when 'imageId'
@image[:image_id] = @value
when 'imageLocation'
@image[:image_location] = @value
when 'imageOwnerId'
@image[:image_owner_id] = @value
when 'imageState'
@image[:image_state] = @value
when 'imageType'
@image[:image_type] = @value
when 'isPublic'
if @value == 'true'
@image[:is_public] = true
else
@image[:is_public] = false
end
when 'item'
unless @in_product_codes
@response[:image_set] << @image
@image = { :product_codes => [] }
end
when 'kernelId'
@image[:kernel_id] = @value
when 'platform'
@image[:platform] = @value
when 'productCode'
@image[:product_codes] << @value
when 'productCodes'
@in_product_codes = false
when 'ramdiskId'
@image[:ramdisk_id] = @value
when 'requestId'
@response[:request_id] = @value
end
end
end
class DescribeInstances < Fog::Parsers::Base
def reset
@instance = { :instance_state => {}, :placement => [], :product_code_set => [] }
@reservation = { :group_set => [], :instances_set => [] }
@response = { :reservation_set => [] }
end
def start_element(name, attrs = [])
if name == 'groupSet'
@in_subset = true
end
if name == 'productCodeSet'
@in_subset = true
end
if name == 'instanceSet'
@in_instances_set = true
end
@value = ''
end
def end_element
case name
when 'amiLaunchIndex'
@instance[:ami_launch_index] = @value
when 'availabilityZone'
@instance[:placement] << @value
when 'code'
@instance[:instance_state][:code] = @value
when 'dnsNmae'
@instance[:dns_name] = @value
when 'groupId'
@reservation[:group_set] << @value
when 'groupSet'
@in_subset = false
when 'imageId'
@instance[:image_id] = @value
when 'instanceId'
@instance[:instance_id] = @value
when 'instancesSet'
@in_instances_set = false
when 'instanceType'
@instance[:instance_type] = @value
when 'item'
if @in_instances_set
@reservation[:instances_set] << @instance
@instance = { :instance_state => {}, :placement => [], :product_code_set => [] }
elsif !@in_subset
@response[:reservation_set] << @reservation
@reservation = { :group_set => [], :instance_set => [] }
end
when 'kernelId'
@instance[:kernel_id] = @value
when 'keyName'
@instance[:key_name] = @value
when 'launchTime'
@instance[:launch_time] = Time.parse(@value)
when 'name'
@instance[:instance_state][:name] = @value
when 'ownerId'
@reservation[:owner_id] = @value
when 'requestId'
@response[:request_id] = @value
when 'reservationId'
@reservation[:reservation_id] = @value
when 'privateDnsName'
@instance[:private_dns_name] = @value
when 'productCode'
@instance[:product_code_set] << @value
when 'productCodeSet'
@in_subset = false
when 'ramdiskId'
@instance[:ramdisk_id] = @value
end
end
end
class DescribeKeyPairs < Fog::Parsers::Base
def reset
@key = {}
@response = { :key_set => [] }
end
def end_element(name)
case name
when 'item'
@response[:key_set] << @key
@key = {}
when 'keyFingerprint'
@key[:key_fingerprint] = @value
when 'keyName'
@key[:key_name] = @value
when 'requestId'
@response[:request_id] = @value
end
end
end
class DescribeSecurityGroups < Fog::Parsers::Base
def reset
@group = {}
@ip_permission = { :groups => [], :ip_ranges => []}
@ip_range = {}
@in_ip_permissions = false
@item = { :ip_permissions => [] }
@response = { :security_group_info => [] }
end
def start_element(name, attrs = [])
if name == 'ipPermissions'
@in_ip_permissions = true
end
if name == 'groups'
@in_groups = true
end
if name == 'ip_ranges'
@in_ip_ranges = true
end
@value = ''
end
def end_element(name)
if !@in_ip_permissions
case name
when 'groupName'
@item[:group_name] = @value
when 'groupDescription'
@item[:group_description] = @value
when 'item'
@response[:security_group_info] << @item
@item = { :ip_permissions => [] }
when 'ownerId'
@item[:owner_id] = @value
end
elsif @in_groups
case name
when 'groupName'
@group[:group_name] = @value
when 'groups'
@in_groups = false
when 'item'
unless @group == {}
@ip_permission[:groups] << @group
end
@group = {}
when 'userId'
@group[:user_id] = @value
end
elsif @in_ip_ranges
case name
when 'cidrIp'
@ip_range[:cidr_ip] = @value
when 'ipRanges'
@in_ip_ranges = false
when 'item'
unless @ip_range == {}
@ip_permission[:ip_ranges] << @ip_range
end
@ip_range = {}
end
elsif @in_ip_permissions
case name
when 'fromPort'
@item[:from_port] = @value
when 'item'
@item[:ip_permissions] << @ip_permission
@ip_permission = { :groups => [], :ip_ranges => []}
when 'ipProtocol'
@ip_permission[:ip_protocol] = @value
when 'ipPermissions'
@in_ip_permissions = false
when 'toPort'
@item[:to_port] = @value
end
end
end
end
class DescribeSnapshots < Fog::Parsers::Base
def reset
@response = { :snapshot_set => [] }
@snapshot = {}
end
def end_element(name)
case name
when 'item'
@response[:snapshot_set] << @snapshot
@snapshot = {}
when 'progress'
@snapshot[:progress] = @value
when 'snapshotId'
@snapshot[:snapshot_id] = @value
when 'startTime'
@snapshot[:start_time] = Time.parse(@value)
when 'status'
@snapshot[:status] = @value
when 'volumeId'
@snapshot[:volume_id] = @value
end
end
end
class DescribeVolumes < Fog::Parsers::Base
def reset
@attachment = {}
@in_attachment_set = false
@response = { :volume_set => [] }
@volume = { :attachment_set => [] }
end
def start_element(name, attrs = [])
if name == 'attachmentSet'
@in_attachment_set = true
end
@value = ''
end
def end_element(name)
if @in_attachment_set
case name
when 'attachmentSet'
@in_attachment_set = false
when 'attachTime'
@attachment[:attach_time] = Time.parse(@value)
when 'device'
@attachment[:device] = @value
when 'instanceId'
@attachment[:instance_id] = @value
when 'item'
@volume[:attachment_set] << @attachment
@attachment = {}
when 'status'
@attachment[:status] = @value
when 'volumeId'
@attachment[:volume_id] = @value
end
else
case name
when 'availabilityZone'
@volume[:availability_zone] = @value
when 'createTime'
@volume[:create_time] = Time.parse(@value)
when 'item'
@response[:volume_set] << @volume
@volume = { :attachment_set => [] }
when 'requestId'
@response[:request_id] = @value
when 'size'
@volume[:size] = @value.to_i
when 'snapshotId'
@volume[:snapshot_id] = @value
when 'status'
@volume[:status] = @value
when 'volumeId'
@volume[:volume_id] = @value
end
end
end
end
end
end
end
end

View file

@ -0,0 +1,23 @@
require File.dirname(__FILE__) + '/basic'
module Fog
module Parsers
module AWS
module EC2
class AllocateAddress < Fog::Parsers::Base
def end_element(name)
case name
when 'requestId'
@response[:request_id] = @value
when 'publicIp'
@response[:public_ip] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require File.dirname(__FILE__) + '/../../../parser'
module Fog
module Parsers
module AWS
module EC2
class Basic < Fog::Parsers::Base
def end_element(name)
case name
when 'requestId'
@response[:request_id] = @value
when 'return'
if @value == 'true'
@response[:return] = true
else
@response[:return] = false
end
end
end
end
end
end
end
end

View file

@ -0,0 +1,28 @@
require File.dirname(__FILE__) + '/basic'
module Fog
module Parsers
module AWS
module EC2
class CreateKeyPair < Fog::Parsers::Base
def end_element(name)
case name
when 'keyFingerprint'
@response[:key_fingerprint] = @value
when 'keyMaterial'
@response[:key_material] = @value
when 'keyName'
@response[:key_name] = @value
when 'requestId'
@response[:request_id] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,30 @@
require File.dirname(__FILE__) + '/basic'
module Fog
module Parsers
module AWS
module EC2
class CreateSnapshot < Fog::Parsers::Base
def end_element(name)
case name
when 'progress'
@response[:progress] = @value
when 'snapshotId'
@response[:snapshot_id] = @value
when 'startTime'
@response[:start_time] = Time.parse(@value)
when 'status'
@response[:status] = @value
when 'volumeId'
@response[:volume_id] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,34 @@
require File.dirname(__FILE__) + '/basic'
module Fog
module Parsers
module AWS
module EC2
class CreateVolume < Fog::Parsers::Base
def end_element(name)
case name
when 'availabilityZone'
@response[:availability_zone] = @value
when 'createTime'
@response[:create_time] = Time.parse(@value)
when 'requestId'
@response[:request_id] = @value
when 'size'
@response[:size] = @value.to_i
when 'snapshotId'
@response[:snapshot_id] = @value
when 'status'
@response[:status] = @value
when 'volumeId'
@response[:volume_id] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,34 @@
require File.dirname(__FILE__) + '/basic'
module Fog
module Parsers
module AWS
module EC2
class DescribeAddresses < Fog::Parsers::Base
def reset
@address = {}
@response = { :address_set => [] }
end
def end_element(name)
case name
when 'instanceId'
@address[:instance_id] = @value
when 'item'
@response[:address_set] << @address
@address = []
when 'publicIp'
@address[:public_ip] = @value
when 'requestId'
@response[:request_id] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,67 @@
require File.dirname(__FILE__) + '/basic'
module Fog
module Parsers
module AWS
module EC2
class DescribeImages < Fog::Parsers::Base
def reset
@image = { :product_codes => [] }
@response = { :image_set => [] }
end
def start_element(name, attrs = [])
if name == 'productCodes'
@in_product_codes = true
end
@value = ''
end
def end_element(name)
case name
when 'architecture'
@image[:architecture] = @value
when 'imageId'
@image[:image_id] = @value
when 'imageLocation'
@image[:image_location] = @value
when 'imageOwnerId'
@image[:image_owner_id] = @value
when 'imageState'
@image[:image_state] = @value
when 'imageType'
@image[:image_type] = @value
when 'isPublic'
if @value == 'true'
@image[:is_public] = true
else
@image[:is_public] = false
end
when 'item'
unless @in_product_codes
@response[:image_set] << @image
@image = { :product_codes => [] }
end
when 'kernelId'
@image[:kernel_id] = @value
when 'platform'
@image[:platform] = @value
when 'productCode'
@image[:product_codes] << @value
when 'productCodes'
@in_product_codes = false
when 'ramdiskId'
@image[:ramdisk_id] = @value
when 'requestId'
@response[:request_id] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,89 @@
require File.dirname(__FILE__) + '/basic'
module Fog
module Parsers
module AWS
module EC2
class DescribeInstances < Fog::Parsers::Base
def reset
@instance = { :instance_state => {}, :placement => [], :product_code_set => [] }
@reservation = { :group_set => [], :instances_set => [] }
@response = { :reservation_set => [] }
end
def start_element(name, attrs = [])
if name == 'groupSet'
@in_subset = true
end
if name == 'productCodeSet'
@in_subset = true
end
if name == 'instanceSet'
@in_instances_set = true
end
@value = ''
end
def end_element
case name
when 'amiLaunchIndex'
@instance[:ami_launch_index] = @value
when 'availabilityZone'
@instance[:placement] << @value
when 'code'
@instance[:instance_state][:code] = @value
when 'dnsNmae'
@instance[:dns_name] = @value
when 'groupId'
@reservation[:group_set] << @value
when 'groupSet'
@in_subset = false
when 'imageId'
@instance[:image_id] = @value
when 'instanceId'
@instance[:instance_id] = @value
when 'instancesSet'
@in_instances_set = false
when 'instanceType'
@instance[:instance_type] = @value
when 'item'
if @in_instances_set
@reservation[:instances_set] << @instance
@instance = { :instance_state => {}, :placement => [], :product_code_set => [] }
elsif !@in_subset
@response[:reservation_set] << @reservation
@reservation = { :group_set => [], :instance_set => [] }
end
when 'kernelId'
@instance[:kernel_id] = @value
when 'keyName'
@instance[:key_name] = @value
when 'launchTime'
@instance[:launch_time] = Time.parse(@value)
when 'name'
@instance[:instance_state][:name] = @value
when 'ownerId'
@reservation[:owner_id] = @value
when 'requestId'
@response[:request_id] = @value
when 'reservationId'
@reservation[:reservation_id] = @value
when 'privateDnsName'
@instance[:private_dns_name] = @value
when 'productCode'
@instance[:product_code_set] << @value
when 'productCodeSet'
@in_subset = false
when 'ramdiskId'
@instance[:ramdisk_id] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,34 @@
require File.dirname(__FILE__) + '/basic'
module Fog
module Parsers
module AWS
module EC2
class DescribeKeyPairs < Fog::Parsers::Base
def reset
@key = {}
@response = { :key_set => [] }
end
def end_element(name)
case name
when 'item'
@response[:key_set] << @key
@key = {}
when 'keyFingerprint'
@key[:key_fingerprint] = @value
when 'keyName'
@key[:key_name] = @value
when 'requestId'
@response[:request_id] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,93 @@
require File.dirname(__FILE__) + '/basic'
module Fog
module Parsers
module AWS
module EC2
class DescribeSecurityGroups < Fog::Parsers::Base
def reset
@group = {}
@ip_permission = { :groups => [], :ip_ranges => []}
@ip_range = {}
@in_ip_permissions = false
@item = { :ip_permissions => [] }
@response = { :security_group_info => [] }
end
def start_element(name, attrs = [])
if name == 'ipPermissions'
@in_ip_permissions = true
end
if name == 'groups'
@in_groups = true
end
if name == 'ip_ranges'
@in_ip_ranges = true
end
@value = ''
end
def end_element(name)
if !@in_ip_permissions
case name
when 'groupName'
@item[:group_name] = @value
when 'groupDescription'
@item[:group_description] = @value
when 'item'
@response[:security_group_info] << @item
@item = { :ip_permissions => [] }
when 'ownerId'
@item[:owner_id] = @value
end
elsif @in_groups
case name
when 'groupName'
@group[:group_name] = @value
when 'groups'
@in_groups = false
when 'item'
unless @group == {}
@ip_permission[:groups] << @group
end
@group = {}
when 'userId'
@group[:user_id] = @value
end
elsif @in_ip_ranges
case name
when 'cidrIp'
@ip_range[:cidr_ip] = @value
when 'ipRanges'
@in_ip_ranges = false
when 'item'
unless @ip_range == {}
@ip_permission[:ip_ranges] << @ip_range
end
@ip_range = {}
end
elsif @in_ip_permissions
case name
when 'fromPort'
@item[:from_port] = @value
when 'item'
@item[:ip_permissions] << @ip_permission
@ip_permission = { :groups => [], :ip_ranges => []}
when 'ipProtocol'
@ip_permission[:ip_protocol] = @value
when 'ipPermissions'
@in_ip_permissions = false
when 'toPort'
@item[:to_port] = @value
end
end
end
end
end
end
end
end

View file

@ -0,0 +1,38 @@
require File.dirname(__FILE__) + '/basic'
module Fog
module Parsers
module AWS
module EC2
class DescribeSnapshots < Fog::Parsers::Base
def reset
@response = { :snapshot_set => [] }
@snapshot = {}
end
def end_element(name)
case name
when 'item'
@response[:snapshot_set] << @snapshot
@snapshot = {}
when 'progress'
@snapshot[:progress] = @value
when 'snapshotId'
@snapshot[:snapshot_id] = @value
when 'startTime'
@snapshot[:start_time] = Time.parse(@value)
when 'status'
@snapshot[:status] = @value
when 'volumeId'
@snapshot[:volume_id] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,71 @@
require File.dirname(__FILE__) + '/basic'
module Fog
module Parsers
module AWS
module EC2
class DescribeVolumes < Fog::Parsers::Base
def reset
@attachment = {}
@in_attachment_set = false
@response = { :volume_set => [] }
@volume = { :attachment_set => [] }
end
def start_element(name, attrs = [])
if name == 'attachmentSet'
@in_attachment_set = true
end
@value = ''
end
def end_element(name)
if @in_attachment_set
case name
when 'attachmentSet'
@in_attachment_set = false
when 'attachTime'
@attachment[:attach_time] = Time.parse(@value)
when 'device'
@attachment[:device] = @value
when 'instanceId'
@attachment[:instance_id] = @value
when 'item'
@volume[:attachment_set] << @attachment
@attachment = {}
when 'status'
@attachment[:status] = @value
when 'volumeId'
@attachment[:volume_id] = @value
end
else
case name
when 'availabilityZone'
@volume[:availability_zone] = @value
when 'createTime'
@volume[:create_time] = Time.parse(@value)
when 'item'
@response[:volume_set] << @volume
@volume = { :attachment_set => [] }
when 'requestId'
@response[:request_id] = @value
when 'size'
@volume[:size] = @value.to_i
when 'snapshotId'
@volume[:snapshot_id] = @value
when 'status'
@volume[:status] = @value
when 'volumeId'
@volume[:volume_id] = @value
end
end
end
end
end
end
end
end

View file

@ -0,0 +1,24 @@
require File.dirname(__FILE__) + '/../../../parser'
module Fog
module Parsers
module AWS
module S3
class CopyObject < Fog::Parsers::Base
def end_element(name)
case name
when 'ETag'
@response[:etag] = @value
when 'LastModified'
@response[:last_modified] = Time.parse(@value)
end
end
end
end
end
end
end

View file

@ -0,0 +1,56 @@
require File.dirname(__FILE__) + '/../../../parser'
module Fog
module Parsers
module AWS
module S3
class GetBucket < Fog::Parsers::Base
def reset
@object = { :owner => {} }
@response = { :contents => [] }
end
def end_element(name)
case name
when 'Contents'
@response[:contents] << @object
@object = { :owner => {} }
when 'DisplayName'
@object[:owner][:display_name] = @value
when 'ETag'
@object[:etag] = @value
when 'ID'
@object[:owner][:id] = @value
when 'IsTruncated'
if @value == 'true'
@response[:is_truncated] = true
else
@response[:is_truncated] = false
end
when 'Key'
@object[:key] = @value
when 'LastModified'
@object[:last_modified] = Time.parse(@value)
when 'Marker'
@response[:marker] = @value
when 'MaxKeys'
@response[:max_keys] = @value.to_i
when 'Name'
@response[:name] = @value
when 'Prefix'
@response[:prefix] = @value
when 'Size'
@object[:size] = @value.to_i
when 'StorageClass'
@object[:storage_class] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,22 @@
require File.dirname(__FILE__) + '/../../../parser'
module Fog
module Parsers
module AWS
module S3
class GetBucketLocation < Fog::Parsers::Base
def end_element(name)
case name
when 'LocationConstraint'
@response[:location_constraint] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,22 @@
require File.dirname(__FILE__) + '/../../../parser'
module Fog
module Parsers
module AWS
module S3
class GetRequestPayment < Fog::Parsers::Base
def end_element(name)
case name
when 'Payer'
@response[:payer] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,36 @@
require File.dirname(__FILE__) + '/../../../parser'
module Fog
module Parsers
module AWS
module S3
class GetService < Fog::Parsers::Base
def reset
@bucket = {}
@response = { :owner => {}, :buckets => [] }
end
def end_element(name)
case name
when 'Bucket'
@response[:buckets] << @bucket
@bucket = {}
when 'CreationDate'
@bucket[:creation_date] = Time.parse(@value)
when 'DisplayName'
@response[:owner][:display_name] = @value
when 'ID'
@response[:owner][:id] = @value
when 'Name'
@bucket[:name] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,31 @@
require File.dirname(__FILE__) + '/../../../parser'
module Fog
module Parsers
module AWS
module SimpleDB
class Basic < Fog::Parsers::Base
def initialize(nil_string)
@nil_string = nil_string
reset
end
def end_element(name)
case(name)
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'RequestId' then response[:request_id] = @value
end
end
def sdb_decode(value)
value.eql?(@nil_string) ? nil : value
end
end
end
end
end
end

View file

@ -0,0 +1,33 @@
require File.dirname(__FILE__) + '/basic'
module Fog
module Parsers
module AWS
module SimpleDB
class DomainMetadata < Fog::Parsers::AWS::SimpleDB::Basic
def reset
@response = {}
end
def end_element(name)
case name
when 'AttributeNameCount' then response[:attribute_name_count] = @value.to_i
when 'AttributeNamesSizeBytes' then response[:attribute_names_size_bytes] = @value.to_i
when 'AttributeValueCount' then response[:attribute_value_count] = @value.to_i
when 'AttributeValuesSizeBytes' then response[:attribute_values_size_bytes] = @value.to_i
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'ItemCount' then response[:item_count] = @value.to_i
when 'ItemNamesSizeBytes' then response[:item_names_size_bytes] = @value.to_i
when 'RequestId' then response[:request_id] = @value
when 'Timestamp' then response[:timestamp] = Time.at(@value.to_i)
end
end
end
end
end
end
end

View file

@ -0,0 +1,29 @@
require File.dirname(__FILE__) + '/basic'
module Fog
module Parsers
module AWS
module SimpleDB
class GetAttributes < Fog::Parsers::AWS::SimpleDB::Basic
def reset
@attribute = nil
@response = { :attributes => {} }
end
def end_element(name)
case name
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'Name' then @attribute = @value
when 'RequestId' then response[:request_id] = @value
when 'Value' then (response[:attributes][@attribute] ||= []) << sdb_decode(@value)
end
end
end
end
end
end
end

View file

@ -0,0 +1,26 @@
module Fog
module Parsers
module AWS
module SimpleDB
class ListDomains < Fog::Parsers::AWS::SimpleDB::Basic
def reset
@response = { :domains => [] }
end
def end_element(name)
case(name)
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'DomainName' then response[:domains] << @value
when 'NextToken' then response[:next_token] = @value
when 'RequestId' then response[:request_id] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,31 @@
require File.dirname(__FILE__) + '/basic'
module Fog
module Parsers
module AWS
module SimpleDB
class Select < Fog::Parsers::AWS::SimpleDB::Basic
def reset
@item_name = @attribute_name = nil
@response = { :items => {} }
end
def end_element(name)
case name
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'Item' then @item_name = @attribute_name = nil
when 'Name' then @item_name.nil? ? @item_name = @value : @attribute_name = @value
when 'NextToken' then response[:next_token] = @value
when 'RequestId' then response[:request_id] = @value
when 'Value' then ((response[:items][@item_name] ||= {})[@attribute_name] ||= []) << sdb_decode(@value)
end
end
end
end
end
end
end

View file

@ -5,7 +5,12 @@ require 'digest/md5'
require 'hmac-sha1'
require 'mime/types'
require File.dirname(__FILE__) + '/s3/parsers'
parsers_directory = "#{File.dirname(__FILE__)}/parsers/s3"
require "#{parsers_directory}/copy_object"
require "#{parsers_directory}/get_bucket"
require "#{parsers_directory}/get_bucket_location"
require "#{parsers_directory}/get_request_payment"
require "#{parsers_directory}/get_service"
module Fog
module AWS
@ -38,6 +43,116 @@ module Fog
@connection = AWS::Connection.new("#{@scheme}://#{@host}:#{@port}")
end
# Copy an object from one S3 bucket to another
# FIXME: docs
def copy_object(source_bucket_name, source_object_name, destination_bucket_name, destination_object_name)
request({
:headers => { 'x-amz-copy-source' => "/#{source_bucket_name}/#{source_object_name}" },
:host => "#{destination_bucket_name}.#{@host}",
:method => 'PUT',
:parser => Fog::Parsers::AWS::S3::CopyObject.new,
:path => destination_object_name
})
end
# Delete an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to delete
#
# ==== Returns
# FIXME: docs
def delete_bucket(bucket_name)
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'DELETE'
})
end
# Delete an object from S3
# FIXME: docs
def delete_object(bucket_name, object_name)
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'DELETE',
:path => object_name
})
end
# List information about objects in an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to list object keys from
# * options<~Hash> - config arguments for list. Defaults to {}.
# * :prefix - limits object keys to those beginning with its value.
# * :marker - limits object keys to only those that appear
# lexicographically after its value.
# * maxkeys - limits number of object keys returned
# * :delimiter - causes keys with the same string between the prefix
# value and the first occurence of delimiter to be rolled up
def get_bucket(bucket_name, options = {})
options['max-keys'] = options.delete(:maxkeys) if options[:maxkeys]
query = '?'
for key, value in options
query << "#{key}=#{value};"
end
query.chop!
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetBucket.new,
:query => query
})
end
# Get location constraint for an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to get location constraint for
#
# ==== Returns
# FIXME: docs
def get_bucket_location(bucket_name)
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetBucketLocation.new,
:query => 'location'
})
end
# Get an object from S3
# FIXME: docs
def get_object(bucket_name, object_name)
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'GET',
:path => object_name
})
end
# Get configured payer for an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to get payer for
#
# ==== Returns
# FIXME: docs
def get_request_payment(bucket_name)
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetRequestPayment.new,
:query => 'requestPayment'
})
end
# List information about S3 buckets for authorized user
#
# ==== Parameters
@ -47,11 +162,35 @@ module Fog
:headers => {},
:host => @host,
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetServiceParser.new,
:parser => Fog::Parsers::AWS::S3::GetService.new,
:url => @host
})
end
# Get headers for an object from S3
# FIXME: docs
def head_object(bucket_name, object_name)
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'HEAD',
:path => object_name
})
end
# Create an object in an S3 bucket
# FIXME: docs
def put_object(bucket_name, object_name, object, options = {})
file = parse_file(object)
request({
:body => file[:body],
:headers => options.merge!(file[:headers]),
:host => "#{bucket_name}.#{@host}",
:method => 'PUT',
:path => object_name
})
end
# Create an S3 bucket
#
# ==== Parameters
@ -98,140 +237,6 @@ DATA
})
end
# List information about objects in an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to list object keys from
# * options<~Hash> - config arguments for list. Defaults to {}.
# * :prefix - limits object keys to those beginning with its value.
# * :marker - limits object keys to only those that appear
# lexicographically after its value.
# * maxkeys - limits number of object keys returned
# * :delimiter - causes keys with the same string between the prefix
# value and the first occurence of delimiter to be rolled up
def get_bucket(bucket_name, options = {})
options['max-keys'] = options.delete(:maxkeys) if options[:maxkeys]
query = '?'
for key, value in options
query << "#{key}=#{value};"
end
query.chop!
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetBucketParser.new,
:query => query
})
end
# Get configured payer for an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to get payer for
#
# ==== Returns
# FIXME: docs
def get_request_payment(bucket_name)
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetRequestPayment.new,
:query => 'requestPayment'
})
end
# Get location constraint for an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to get location constraint for
#
# ==== Returns
# FIXME: docs
def get_bucket_location(bucket_name)
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetBucketLocation.new,
:query => 'location'
})
end
# Delete an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to delete
#
# ==== Returns
# FIXME: docs
def delete_bucket(bucket_name)
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'DELETE'
})
end
# Create an object in an S3 bucket
# FIXME: docs
def put_object(bucket_name, object_name, object, options = {})
file = parse_file(object)
request({
:body => file[:body],
:headers => options.merge!(file[:headers]),
:host => "#{bucket_name}.#{@host}",
:method => 'PUT',
:path => object_name
})
end
# Copy an object from one S3 bucket to another
# FIXME: docs
def copy_object(source_bucket_name, source_object_name, destination_bucket_name, destination_object_name)
request({
:headers => { 'x-amz-copy-source' => "/#{source_bucket_name}/#{source_object_name}" },
:host => "#{destination_bucket_name}.#{@host}",
:method => 'PUT',
:parser => Fog::Parsers::AWS::S3::CopyObject.new,
:path => destination_object_name
})
end
# Get an object from S3
# FIXME: docs
def get_object(bucket_name, object_name)
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'GET',
:path => object_name
})
end
# Get headers for an object from S3
# FIXME: docs
def head_object(bucket_name, object_name)
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'HEAD',
:path => object_name
})
end
# Delete an object from S3
# FIXME: docs
def delete_object(bucket_name, object_name)
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'DELETE',
:path => object_name
})
end
private
def parse_file(file)

View file

@ -1,116 +0,0 @@
require File.dirname(__FILE__) + '/../../parser'
module Fog
module Parsers
module AWS
module S3
class GetServiceParser < Fog::Parsers::Base
def reset
@bucket = {}
@response = { :owner => {}, :buckets => [] }
end
def end_element(name)
case name
when 'Bucket'
@response[:buckets] << @bucket
@bucket = {}
when 'CreationDate'
@bucket[:creation_date] = Time.parse(@value)
when 'DisplayName'
@response[:owner][:display_name] = @value
when 'ID'
@response[:owner][:id] = @value
when 'Name'
@bucket[:name] = @value
end
end
end
class GetBucketParser < Fog::Parsers::Base
def reset
@object = { :owner => {} }
@response = { :contents => [] }
end
def end_element(name)
case name
when 'Contents'
@response[:contents] << @object
@object = { :owner => {} }
when 'DisplayName'
@object[:owner][:display_name] = @value
when 'ETag'
@object[:etag] = @value
when 'ID'
@object[:owner][:id] = @value
when 'IsTruncated'
if @value == 'true'
@response[:is_truncated] = true
else
@response[:is_truncated] = false
end
when 'Key'
@object[:key] = @value
when 'LastModified'
@object[:last_modified] = Time.parse(@value)
when 'Marker'
@response[:marker] = @value
when 'MaxKeys'
@response[:max_keys] = @value.to_i
when 'Name'
@response[:name] = @value
when 'Prefix'
@response[:prefix] = @value
when 'Size'
@object[:size] = @value.to_i
when 'StorageClass'
@object[:storage_class] = @value
end
end
end
class GetRequestPayment < Fog::Parsers::Base
def end_element(name)
case name
when 'Payer'
@response[:payer] = @value
end
end
end
class GetBucketLocation < Fog::Parsers::Base
def end_element(name)
case name
when 'LocationConstraint'
@response[:location_constraint] = @value
end
end
end
class CopyObject < Fog::Parsers::Base
def end_element(name)
case name
when 'ETag'
@response[:etag] = @value
when 'LastModified'
@response[:last_modified] = Time.parse(@value)
end
end
end
end
end
end
end

View file

@ -3,7 +3,12 @@ require 'base64'
require 'cgi'
require 'hmac-sha2'
require File.dirname(__FILE__) + '/simpledb/parsers'
parsers_directory = "#{File.dirname(__FILE__)}/parsers/simpledb"
require "#{parsers_directory}/basic"
require "#{parsers_directory}/domain_metadata"
require "#{parsers_directory}/get_attributes"
require "#{parsers_directory}/list_domains"
require "#{parsers_directory}/select"
module Fog
module AWS
@ -37,6 +42,30 @@ module Fog
@connection = AWS::Connection.new("#{@scheme}://#{@host}:#{@port}")
end
# Put items attributes into a SimpleDB domain
#
# ==== Parameters
# * domain_name<~String> - Name of domain. Must be between 3 and 255 of the
# following characters: a-z, A-Z, 0-9, '_', '-' and '.'.
# * items<~Hash> - Keys are the items names and may use any UTF-8
# characters valid in xml. Control characters and sequences not allowed
# in xml are not valid. Can be up to 1024 bytes long. Values are the
# attributes to add to the given item and may use any UTF-8 characters
# valid in xml. Control characters and sequences not allowed in xml are
# not valid. Each name and value can be up to 1024 bytes long.
#
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :box_usage
# * :request_id
def batch_put_attributes(domain_name, items, replace_attributes = Hash.new([]))
request({
'Action' => 'BatchPutAttributes',
'DomainName' => domain_name
}.merge!(encode_batch_attributes(items, replace_attributes)), Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string))
end
# Create a SimpleDB domain
#
# ==== Parameters
@ -52,7 +81,7 @@ module Fog
request({
'Action' => 'CreateDomain',
'DomainName' => domain_name
}, Fog::Parsers::AWS::SimpleDB::BasicParser.new(@nil_string))
}, Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string))
end
# Delete a SimpleDB domain
@ -70,30 +99,7 @@ module Fog
request({
'Action' => 'DeleteDomain',
'DomainName' => domain_name
}, Fog::Parsers::AWS::SimpleDB::BasicParser.new(@nil_string))
end
# List SimpleDB domains
#
# ==== Parameters
# * options<~Hash> - options, defaults to {}
# *max_number_of_domains<~Integer> - number of domains to return
# between 1 and 100, defaults to 100
# *next_token<~String> - Offset token to start listing, defaults to nil
#
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :box_usage
# * :request_id
# * :domains - array of domain names.
# * :next_token - offset to start with if there are are more domains to list
def list_domains(options = {})
request({
'Action' => 'ListDomains',
'MaxNumberOfDomains' => options[:max_number_of_domains],
'NextToken' => options[:next_token]
}, Fog::Parsers::AWS::SimpleDB::ListDomainsParser.new(@nil_string))
}, Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string))
end
# List metadata for SimpleDB domain
@ -116,31 +122,30 @@ module Fog
request({
'Action' => 'DomainMetadata',
'DomainName' => domain_name
}, Fog::Parsers::AWS::SimpleDB::DomainMetadataParser.new(@nil_string))
}, Fog::Parsers::AWS::SimpleDB::DomainMetadata.new(@nil_string))
end
# Put items attributes into a SimpleDB domain
# List SimpleDB domains
#
# ==== Parameters
# * domain_name<~String> - Name of domain. Must be between 3 and 255 of the
# following characters: a-z, A-Z, 0-9, '_', '-' and '.'.
# * items<~Hash> - Keys are the items names and may use any UTF-8
# characters valid in xml. Control characters and sequences not allowed
# in xml are not valid. Can be up to 1024 bytes long. Values are the
# attributes to add to the given item and may use any UTF-8 characters
# valid in xml. Control characters and sequences not allowed in xml are
# not valid. Each name and value can be up to 1024 bytes long.
# * options<~Hash> - options, defaults to {}
# *max_number_of_domains<~Integer> - number of domains to return
# between 1 and 100, defaults to 100
# *next_token<~String> - Offset token to start listing, defaults to nil
#
# ==== Returns
# * response<~Fog::AWS::Response>:
# * body<~Hash>:
# * :box_usage
# * :request_id
def batch_put_attributes(domain_name, items, replace_attributes = Hash.new([]))
# * :domains - array of domain names.
# * :next_token - offset to start with if there are are more domains to list
def list_domains(options = {})
request({
'Action' => 'BatchPutAttributes',
'DomainName' => domain_name
}.merge!(encode_batch_attributes(items, replace_attributes)), Fog::Parsers::AWS::SimpleDB::BasicParser.new(@nil_string))
'Action' => 'ListDomains',
'MaxNumberOfDomains' => options[:max_number_of_domains],
'NextToken' => options[:next_token]
}, Fog::Parsers::AWS::SimpleDB::ListDomains.new(@nil_string))
end
# Put item attributes into a SimpleDB domain
@ -189,7 +194,7 @@ module Fog
'Action' => 'DeleteAttributes',
'DomainName' => domain_name,
'ItemName' => item_name
}.merge!(encode_attributes(attributes)), Fog::Parsers::AWS::SimpleDB::BasicParser.new(@nil_string))
}.merge!(encode_attributes(attributes)), Fog::Parsers::AWS::SimpleDB::Basic.new(@nil_string))
end
# List metadata for SimpleDB domain
@ -217,7 +222,7 @@ module Fog
'Action' => 'GetAttributes',
'DomainName' => domain_name,
'ItemName' => item_name,
}.merge!(encode_attribute_names(attributes)), Fog::Parsers::AWS::SimpleDB::GetAttributesParser.new(@nil_string))
}.merge!(encode_attribute_names(attributes)), Fog::Parsers::AWS::SimpleDB::GetAttributes.new(@nil_string))
end
# Select item data from SimpleDB
@ -239,34 +244,11 @@ module Fog
'Action' => 'Select',
'NextToken' => next_token,
'SelectExpression' => select_expression
}, Fog::Parsers::AWS::SimpleDB::SelectParser.new(@nil_string))
}, Fog::Parsers::AWS::SimpleDB::Select.new(@nil_string))
end
private
def encode_batch_attributes(items, replace_attributes = Hash.new([]))
encoded_attributes = {}
if items
item_index = 0
for item_key in items.keys
encoded_attributes["Item.#{item_index}.ItemName"] = item_key.to_s
for attribute_key in items[item_key].keys
attribute_index = 0
for value in Array(items[item_key][attribute_key])
encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Name"] = attribute_key.to_s
if replace_attributes[item_key].include?(attribute_key)
encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Replace"] = 'true'
end
encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Value"] = sdb_encode(value)
attribute_index += 1
end
item_index += 1
end
end
end
encoded_attributes
end
def encode_attributes(attributes, replace_attributes = [])
encoded_attributes = {}
if attributes
@ -297,12 +279,27 @@ module Fog
encoded_attribute_names
end
def sdb_encode(value)
if value.nil?
@nil_string
else
value.to_s
def encode_batch_attributes(items, replace_attributes = Hash.new([]))
encoded_attributes = {}
if items
item_index = 0
for item_key in items.keys
encoded_attributes["Item.#{item_index}.ItemName"] = item_key.to_s
for attribute_key in items[item_key].keys
attribute_index = 0
for value in Array(items[item_key][attribute_key])
encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Name"] = attribute_key.to_s
if replace_attributes[item_key].include?(attribute_key)
encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Replace"] = 'true'
end
encoded_attributes["Item.#{item_index}.Attribute.#{attribute_index}.Value"] = sdb_encode(value)
attribute_index += 1
end
item_index += 1
end
end
end
encoded_attributes
end
def request(params, parser)
@ -336,6 +333,14 @@ module Fog
response
end
def sdb_encode(value)
if value.nil?
@nil_string
else
value.to_s
end
end
end
end
end

View file

@ -1,107 +0,0 @@
require File.dirname(__FILE__) + '/../../parser'
module Fog
module Parsers
module AWS
module SimpleDB
class BasicParser < Fog::Parsers::Base
def initialize(nil_string)
@nil_string = nil_string
reset
end
def end_element(name)
case(name)
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'RequestId' then response[:request_id] = @value
end
end
def sdb_decode(value)
value.eql?(@nil_string) ? nil : value
end
end
class ListDomainsParser < Fog::Parsers::AWS::SimpleDB::BasicParser
def reset
@response = { :domains => [] }
end
def end_element(name)
case(name)
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'DomainName' then response[:domains] << @value
when 'NextToken' then response[:next_token] = @value
when 'RequestId' then response[:request_id] = @value
end
end
end
class DomainMetadataParser < Fog::Parsers::AWS::SimpleDB::BasicParser
def reset
@response = {}
end
def end_element(name)
case name
when 'AttributeNameCount' then response[:attribute_name_count] = @value.to_i
when 'AttributeNamesSizeBytes' then response[:attribute_names_size_bytes] = @value.to_i
when 'AttributeValueCount' then response[:attribute_value_count] = @value.to_i
when 'AttributeValuesSizeBytes' then response[:attribute_values_size_bytes] = @value.to_i
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'ItemCount' then response[:item_count] = @value.to_i
when 'ItemNamesSizeBytes' then response[:item_names_size_bytes] = @value.to_i
when 'RequestId' then response[:request_id] = @value
when 'Timestamp' then response[:timestamp] = Time.at(@value.to_i)
end
end
end
class GetAttributesParser < Fog::Parsers::AWS::SimpleDB::BasicParser
def reset
@attribute = nil
@response = { :attributes => {} }
end
def end_element(name)
case name
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'Name' then @attribute = @value
when 'RequestId' then response[:request_id] = @value
when 'Value' then (response[:attributes][@attribute] ||= []) << sdb_decode(@value)
end
end
end
class SelectParser < Fog::Parsers::AWS::SimpleDB::BasicParser
def reset
@item_name = @attribute_name = nil
@response = { :items => {} }
end
def end_element(name)
case name
when 'BoxUsage' then response[:box_usage] = @value.to_f
when 'Item' then @item_name = @attribute_name = nil
when 'Name' then @item_name.nil? ? @item_name = @value : @attribute_name = @value
when 'NextToken' then response[:next_token] = @value
when 'RequestId' then response[:request_id] = @value
when 'Value' then ((response[:items][@item_name] ||= {})[@attribute_name] ||= []) << sdb_decode(@value)
end
end
end
end
end
end
end