Permalink
Browse files

refs #7162, AWS gem monkey patches ActiveSupport methods

  • Loading branch information...
konstantin
konstantin committed Jun 28, 2010
1 parent a60b928 commit ef8af7e4e04d16d2f55531847dc0db32ba1d5fc8
View
@@ -291,4 +291,5 @@ the source key.
- RDS: API '2010-01-01' (MultiAZ support)
- Fixed:
- RDS: DB Parameter group name on instance launch
-
+ - ActiveSupport dependency removal
+
View
@@ -30,7 +30,7 @@ Hoe.new('right_aws', RightAws::VERSION::STRING) do |p|
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
p.remote_rdoc_dir = "/right_aws_gem_doc"
- p.extra_deps = [['right_http_connection','>= 1.2.1']]
+ p.extra_deps = [['right_http_connection','>= 1.2.5']]
p.test_globs = testglobs
end
@@ -121,8 +121,8 @@ def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
# Generates request hash for REST API.
def generate_request(method, path, params={}, body=nil, headers={}) # :nodoc:
# Params
- params.delete_if{ |key, val| val.blank? }
- unless params.blank?
+ params.delete_if{ |key, val| val.right_blank? }
+ unless params.right_blank?
path += "?" + params.to_a.collect{ |key,val| "#{AwsUtils::amz_escape(key)}=#{AwsUtils::amz_escape(val.to_s)}" }.join("&")
end
# Headers
@@ -133,7 +133,7 @@ def generate_request(method, path, params={}, body=nil, headers={}) # :nodoc:
headers['Authorization'] = "AWS #{@aws_access_key_id}:#{signature}"
# Request
path = "#{@params[:service]}#{@params[:api_version]}/#{path}"
- request = "Net::HTTP::#{method.capitalize}".constantize.new(path)
+ request = "Net::HTTP::#{method.capitalize}".right_constantize.new(path)
request.body = body if body
# Set request headers
headers.each { |key, value| request[key.to_s] = value }
@@ -180,26 +180,26 @@ def distribution_config_to_xml(config, xml_wrapper='DistributionConfig') # :nodo
origin_access_identity = ''
trusted_signers = ''
# CNAMES
- unless config[:cnames].blank?
+ unless config[:cnames].right_blank?
Array(config[:cnames]).each { |cname| cnames += " <CNAME>#{cname}</CNAME>\n" }
end
# Logging
- unless config[:logging].blank?
+ unless config[:logging].right_blank?
logging = " <Logging>\n" +
" <Bucket>#{config[:logging][:bucket]}</Bucket>\n" +
" <Prefix>#{config[:logging][:prefix]}</Prefix>\n" +
" </Logging>\n"
end
# Origin Access Identity
- unless config[:origin_access_identity].blank?
+ unless config[:origin_access_identity].right_blank?
origin_access_identity = config[:origin_access_identity]
unless origin_access_identity[%r{^origin-access-identity}]
origin_access_identity = "origin-access-identity/cloudfront/#{origin_access_identity}"
end
origin_access_identity = " <OriginAccessIdentity>#{origin_access_identity}</OriginAccessIdentity>\n"
end
# Trusted Signers
- unless config[:trusted_signers].blank?
+ unless config[:trusted_signers].right_blank?
trusted_signers = " <TrustedSigners>\n"
Array(config[:trusted_signers]).each do |trusted_signer|
trusted_signers += if trusted_signer.to_s[/self/i]
@@ -288,7 +288,7 @@ def incrementally_list_distributions(params={}, &block)
link = generate_request('GET', 'distribution', opts)
last_response = request_info(link, AcfDistributionListParser.new(:logger => @logger))
opts['Marker'] = last_response[:next_marker]
- break unless block && block.call(last_response) && !last_response[:next_marker].blank?
+ break unless block && block.call(last_response) && !last_response[:next_marker].right_blank?
end
last_response
end
@@ -317,7 +317,7 @@ def create_distribution(origin, comment='', enabled=true, cnames=[], caller_refe
:enabled => enabled,
:cnames => Array(cnames),
:caller_reference => caller_reference }
- config[:logging] = logging unless logging.blank?
+ config[:logging] = logging unless logging.right_blank?
create_distribution_by_config(config)
end
@@ -85,7 +85,7 @@ def incrementally_list_origin_access_identities(params={}, &block)
link = generate_request('GET', 'origin-access-identity/cloudfront', opts)
last_response = request_info(link, AcfOriginAccesIdentitiesListParser.new(:logger => @logger))
opts['Marker'] = last_response[:next_marker]
- break unless block && block.call(last_response) && !last_response[:next_marker].blank?
+ break unless block && block.call(last_response) && !last_response[:next_marker].right_blank?
end
last_response
end
@@ -101,7 +101,7 @@ def incrementally_list_streaming_distributions(params={}, &block)
link = generate_request('GET', 'streaming-distribution', opts)
last_response = request_info(link, AcfDistributionListParser.new(:logger => @logger))
opts['Marker'] = last_response[:next_marker]
- break unless block && block.call(last_response) && !last_response[:next_marker].blank?
+ break unless block && block.call(last_response) && !last_response[:next_marker].right_blank?
end
last_response
end
@@ -145,7 +145,7 @@ def get_metric_statistics(options={})
period = (options[:period] && options[:period].to_i) || 60
# Statistics ('Average' by default)
statistics = Array(options[:statistics]).flatten
- statistics = statistics.blank? ? ['Average'] : statistics.map{|statistic| statistic.to_s.capitalize }
+ statistics = statistics.right_blank? ? ['Average'] : statistics.map{|statistic| statistic.to_s.capitalize }
# Times (5.min.ago up to now by default)
start_time = options[:start_time] || (Time.now.utc - 5*60)
start_time = start_time.utc.strftime("%Y-%m-%dT%H:%M:%S+00:00") if start_time.is_a?(Time)
@@ -136,7 +136,7 @@ def describe_auto_scaling_groups(*auto_scaling_group_names)
auto_scaling_group_names = auto_scaling_group_names.flatten.compact
request_hash = amazonize_list('AutoScalingGroupNames.member', auto_scaling_group_names)
link = generate_request("DescribeAutoScalingGroups", request_hash)
- request_cache_or_info(:describe_auto_scaling_groups, link, DescribeAutoScalingGroupsParser, @@bench, auto_scaling_group_names.blank?)
+ request_cache_or_info(:describe_auto_scaling_groups, link, DescribeAutoScalingGroupsParser, @@bench, auto_scaling_group_names.right_blank?)
end
# Creates a new auto scaling group with the specified name.
@@ -302,7 +302,7 @@ def incrementally_describe_scaling_activities(auto_scaling_group_name, *activity
link = generate_request("DescribeScalingActivities", request_hash)
last_response = request_info( link, DescribeScalingActivitiesParser.new(:logger => @logger))
request_hash['NextToken'] = last_response[:next_token]
- break unless block && block.call(last_response) && !last_response[:next_token].blank?
+ break unless block && block.call(last_response) && !last_response[:next_token].right_blank?
end
last_response
end
@@ -355,10 +355,10 @@ def create_launch_configuration(launch_configuration_name, image_id, instance_ty
request_hash = { 'LaunchConfigurationName' => launch_configuration_name,
'ImageId' => image_id,
'InstanceType' => instance_type }
- request_hash.merge!(amazonize_list('SecurityGroups.member', options[:security_groups])) unless options[:security_groups].blank?
+ request_hash.merge!(amazonize_list('SecurityGroups.member', options[:security_groups])) unless options[:security_groups].right_blank?
request_hash.merge!(amazonize_block_device_mappings(options[:block_device_mappings], 'BlockDeviceMappings.member'))
request_hash['KeyName'] = options[:key_name] if options[:key_name]
- request_hash['UserData'] = Base64.encode64(options[:user_data]).delete("\n") unless options[:user_data].blank? if options[:user_data]
+ request_hash['UserData'] = Base64.encode64(options[:user_data]).delete("\n") unless options[:user_data].right_blank? if options[:user_data]
request_hash['KernelId'] = options[:kernel_id] if options[:kernel_id]
request_hash['RamdiskId'] = options[:ramdisk_id] if options[:ramdisk_id]
link = generate_request("CreateLaunchConfiguration", request_hash)
@@ -428,7 +428,7 @@ def incrementally_describe_launch_configurations(*launch_configuration_names, &b
link = generate_request("DescribeLaunchConfigurations", request_hash)
last_response = request_info( link, DescribeLaunchConfigurationsParser.new(:logger => @logger) )
request_hash['NextToken'] = last_response[:next_token]
- break unless block && block.call(last_response) && !last_response[:next_token].blank?
+ break unless block && block.call(last_response) && !last_response[:next_token].right_blank?
end
last_response
end
@@ -222,9 +222,9 @@ def init(service_info, aws_access_key_id, aws_secret_access_key, params={}) #:no
@params = params
# If one defines EC2_URL he may forget to use a single slash as an "empty service" path.
# Amazon does not like this therefore add this bad boy if he is missing...
- service_info[:default_service] = '/' if service_info[:default_service].blank?
+ service_info[:default_service] = '/' if service_info[:default_service].right_blank?
raise AwsError.new("AWS access keys are required to operate on #{service_info[:name]}") \
- if aws_access_key_id.blank? || aws_secret_access_key.blank?
+ if aws_access_key_id.right_blank? || aws_secret_access_key.right_blank?
@aws_access_key_id = aws_access_key_id
@aws_secret_access_key = aws_secret_access_key
# if the endpoint was explicitly defined - then use it
@@ -233,7 +233,7 @@ def init(service_info, aws_access_key_id, aws_secret_access_key, params={}) #:no
@params[:port] = URI.parse(@params[:endpoint_url]).port
@params[:service] = URI.parse(@params[:endpoint_url]).path
# make sure the 'service' path is not empty
- @params[:service] = service_info[:default_service] if @params[:service].blank?
+ @params[:service] = service_info[:default_service] if @params[:service].right_blank?
@params[:protocol] = URI.parse(@params[:endpoint_url]).scheme
@params[:region] = nil
else
@@ -537,7 +537,7 @@ def amazonize_list(masks, list) #:nodoc:
def amazonize_block_device_mappings(block_device_mappings, key = 'BlockDeviceMapping') # :nodoc:
result = {}
- unless block_device_mappings.blank?
+ unless block_device_mappings.right_blank?
block_device_mappings = [block_device_mappings] unless block_device_mappings.is_a?(Array)
block_device_mappings.each_with_index do |b, idx|
BLOCK_DEVICE_KEY_MAPPING.each do |local_name, remote_name|
View
@@ -1,7 +1,3 @@
-# If ActiveSupport is loaded, then great - use it. But we don't
-# want a dependency on it, so if it's not present, define the few
-# extensions that we want to use...
-unless defined? ActiveSupport::CoreExtensions
# These are ActiveSupport-;like extensions to do a few handy things in the gems
# Derived from ActiveSupport, so the AS copyright notice applies:
#
@@ -39,15 +35,14 @@ class String #:nodoc:
# Examples
# "Module".constantize #=> Module
# "Class".constantize #=> Class
- def constantize()
+ def right_constantize()
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
raise NameError, "#{self.inspect} is not a valid constant name!"
end
-
Object.module_eval("::#{$1}", __FILE__, __LINE__)
end
- def camelize()
+ def right_camelize()
self.dup.split(/_/).map{ |word| word.capitalize }.join('')
end
@@ -56,7 +51,7 @@ def camelize()
class Object #:nodoc:
# "", " ", nil, [], and {} are blank
- def blank?
+ def right_blank?
if respond_to?(:empty?) && respond_to?(:strip)
empty? or strip.empty?
elsif respond_to?(:empty?)
@@ -68,32 +63,32 @@ def blank?
end
class NilClass #:nodoc:
- def blank?
+ def right_blank?
true
end
end
class FalseClass #:nodoc:
- def blank?
+ def right_blank?
true
end
end
class TrueClass #:nodoc:
- def blank?
+ def right_blank?
false
end
end
class Array #:nodoc:
- alias_method :blank?, :empty?
+ alias_method :right_blank?, :empty?
end
class Hash #:nodoc:
- alias_method :blank?, :empty?
-
+ alias_method :right_blank?, :empty?
+
# Return a new hash with all keys converted to symbols.
- def symbolize_keys
+ def right_symbolize_keys
inject({}) do |options, (key, value)|
options[key.to_sym] = value
options
@@ -102,14 +97,13 @@ def symbolize_keys
end
class String #:nodoc:
- def blank?
+ def right_blank?
empty? || strip.empty?
end
end
class Numeric #:nodoc:
- def blank?
+ def right_blank?
false
end
end
-end
View
@@ -154,7 +154,7 @@ def request_info(request, parser) #:nodoc:
def describe_key_pairs(*key_pairs)
key_pairs = key_pairs.flatten
link = generate_request("DescribeKeyPairs", amazonize_list('KeyName', key_pairs))
- request_cache_or_info :describe_key_pairs, link, QEc2DescribeKeyPairParser, @@bench, key_pairs.blank?
+ request_cache_or_info :describe_key_pairs, link, QEc2DescribeKeyPairParser, @@bench, key_pairs.right_blank?
rescue Exception
on_exception
end
@@ -227,7 +227,7 @@ def associate_address(instance_id, public_ip)
def describe_addresses(*addresses)
addresses = addresses.flatten
link = generate_request("DescribeAddresses", amazonize_list('PublicIp', addresses))
- request_cache_or_info :describe_addresses, link, QEc2DescribeAddressesParser, @@bench, addresses.blank?
+ request_cache_or_info :describe_addresses, link, QEc2DescribeAddressesParser, @@bench, addresses.right_blank?
rescue Exception
on_exception
end
@@ -276,7 +276,7 @@ def release_address(public_ip)
def describe_availability_zones(*availability_zones)
availability_zones = availability_zones.flatten
link = generate_request("DescribeAvailabilityZones", amazonize_list('ZoneName', availability_zones))
- request_cache_or_info :describe_availability_zones, link, QEc2DescribeAvailabilityZonesParser, @@bench, availability_zones.blank?
+ request_cache_or_info :describe_availability_zones, link, QEc2DescribeAvailabilityZonesParser, @@bench, availability_zones.right_blank?
rescue Exception
on_exception
end
@@ -292,7 +292,7 @@ def describe_availability_zones(*availability_zones)
def describe_regions(*regions)
regions = regions.flatten
link = generate_request("DescribeRegions", amazonize_list('RegionName', regions))
- request_cache_or_info :describe_regions, link, QEc2DescribeRegionsParser, @@bench, regions.blank?
+ request_cache_or_info :describe_regions, link, QEc2DescribeRegionsParser, @@bench, regions.right_blank?
rescue Exception
on_exception
end
@@ -346,7 +346,7 @@ def tagstart(name, attributes)
end
def tagend(name)
case name
- when 'instanceId' then @address[:instance_id] = @text.blank? ? nil : @text
+ when 'instanceId' then @address[:instance_id] = @text.right_blank? ? nil : @text
when 'publicIp' then @address[:public_ip] = @text
when 'item' then @result << @address
end
View
@@ -52,7 +52,7 @@ class Ec2
def describe_volumes(*volumes)
volumes = volumes.flatten
link = generate_request("DescribeVolumes", amazonize_list('VolumeId', volumes))
- request_cache_or_info :describe_volumes, link, QEc2DescribeVolumesParser, @@bench, volumes.blank?
+ request_cache_or_info :describe_volumes, link, QEc2DescribeVolumesParser, @@bench, volumes.right_blank?
rescue Exception
on_exception
end
@@ -72,7 +72,7 @@ def create_volume(snapshot_id, size, zone)
hash = { "Size" => size.to_s,
"AvailabilityZone" => zone.to_s }
# Get rig of empty snapshot: e8s guys do not like it
- hash["SnapshotId"] = snapshot_id.to_s unless snapshot_id.blank?
+ hash["SnapshotId"] = snapshot_id.to_s unless snapshot_id.right_blank?
link = generate_request("CreateVolume", hash )
request_info(link, QEc2CreateVolumeParser.new(:logger => @logger))
rescue Exception
@@ -123,8 +123,8 @@ def attach_volume(volume_id, instance_id, device)
#
def detach_volume(volume_id, instance_id=nil, device=nil, force=nil)
hash = { "VolumeId" => volume_id.to_s }
- hash["InstanceId"] = instance_id.to_s unless instance_id.blank?
- hash["Device"] = device.to_s unless device.blank?
+ hash["InstanceId"] = instance_id.to_s unless instance_id.right_blank?
+ hash["Device"] = device.to_s unless device.right_blank?
hash["Force"] = 'true' if force
#
link = generate_request("DetachVolume", hash)
@@ -161,7 +161,7 @@ def detach_volume(volume_id, instance_id=nil, device=nil, force=nil)
def describe_snapshots(*snapshots)
snapshots = snapshots.flatten
link = generate_request("DescribeSnapshots", amazonize_list('SnapshotId', snapshots))
- request_cache_or_info :describe_snapshots, link, QEc2DescribeSnapshotsParser, @@bench, snapshots.blank?
+ request_cache_or_info :describe_snapshots, link, QEc2DescribeSnapshotsParser, @@bench, snapshots.right_blank?
rescue Exception
on_exception
end
@@ -300,7 +300,7 @@ def modify_snapshot_attribute_create_volume_permission_remove_users(snapshot_id,
#
def modify_snapshot_attribute_create_volume_permission_add_groups(snapshot_id, *user_group)
user_group.flatten!
- user_group = ['all'] if user_group.blank?
+ user_group = ['all'] if user_group.right_blank?
modify_snapshot_attribute(snapshot_id, 'createVolumePermission', 'add', :user_group => user_group )
end
@@ -310,7 +310,7 @@ def modify_snapshot_attribute_create_volume_permission_add_groups(snapshot_id, *
#
def modify_snapshot_attribute_create_volume_permission_remove_groups(snapshot_id, *user_group)
user_group.flatten!
- user_group = ['all'] if user_group.blank?
+ user_group = ['all'] if user_group.right_blank?
modify_snapshot_attribute(snapshot_id, 'createVolumePermission', 'remove', :user_group => user_group )
end
@@ -337,7 +337,7 @@ def tagend(name)
when 'status' then @result[:aws_status] = @text
when 'createTime' then @result[:aws_created_at] = @text
when 'size' then @result[:aws_size] = @text.to_i ###
- when 'snapshotId' then @result[:snapshot_id] = @text.blank? ? nil : @text ###
+ when 'snapshotId' then @result[:snapshot_id] = @text.right_blank? ? nil : @text ###
when 'availabilityZone' then @result[:zone] = @text ###
end
end
@@ -386,7 +386,7 @@ def tagend(name)
when 'instanceId' then @volume[:aws_instance_id] = @text
when 'device' then @volume[:aws_device] = @text
when 'attachTime' then @volume[:aws_attached_at] = @text
- when 'snapshotId' then @volume[:snapshot_id] = @text.blank? ? nil : @text
+ when 'snapshotId' then @volume[:snapshot_id] = @text.right_blank? ? nil : @text
when 'availabilityZone' then @volume[:zone] = @text
when 'deleteOnTermination' then @volume[:delete_on_termination] = (@text == 'true')
when 'item'
Oops, something went wrong.

0 comments on commit ef8af7e

Please sign in to comment.