aws 2.4.5 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/README.markdown +9 -75
  2. data/lib/acf/acf_interface.rb +6 -4
  3. data/lib/aws.rb +2 -1
  4. data/lib/awsbase/awsbase.rb +98 -65
  5. data/lib/awsbase/errors.rb +9 -5
  6. data/lib/awsbase/parsers.rb +226 -226
  7. data/lib/awsbase/utils.rb +255 -207
  8. data/lib/ec2/ec2.rb +243 -105
  9. data/lib/ec2/mon_interface.rb +2 -1
  10. data/lib/iam/iam.rb +31 -25
  11. data/lib/right_aws.rb +1 -1
  12. data/lib/s3/bucket.rb +7 -8
  13. data/lib/s3/grantee.rb +238 -238
  14. data/lib/s3/key.rb +281 -281
  15. data/lib/s3/s3.rb +2 -1
  16. data/lib/s3/s3_interface.rb +45 -35
  17. data/lib/sdb/active_sdb.rb +19 -22
  18. data/lib/sdb/sdb_interface.rb +4 -5
  19. data/lib/ses/ses.rb +123 -0
  20. data/lib/sqs/sqs.rb +5 -0
  21. data/lib/sqs/sqs_interface.rb +3 -3
  22. metadata +53 -104
  23. data/lib/awsbase/support.rb +0 -142
  24. data/test/acf/test_acf.rb +0 -148
  25. data/test/acf/test_helper.rb +0 -2
  26. data/test/ec2/test_ec2.rb +0 -205
  27. data/test/ec2/test_helper.rb +0 -2
  28. data/test/ec2/test_mon.rb +0 -17
  29. data/test/elb/test_elb.rb +0 -51
  30. data/test/http_connection.rb +0 -87
  31. data/test/iam/test_iam.rb +0 -36
  32. data/test/rds/test_rds.rb +0 -181
  33. data/test/s3/s3_test_base.rb +0 -23
  34. data/test/s3/test_helper.rb +0 -3
  35. data/test/s3/test_s3.rb +0 -162
  36. data/test/s3/test_s3_class.rb +0 -179
  37. data/test/s3/test_s3_rights.rb +0 -139
  38. data/test/s3/test_s3_stubbed.rb +0 -97
  39. data/test/sdb/test_active_sdb.rb +0 -338
  40. data/test/sdb/test_helper.rb +0 -3
  41. data/test/sdb/test_sdb.rb +0 -220
  42. data/test/sqs/test_helper.rb +0 -2
  43. data/test/sqs/test_sqs.rb +0 -232
  44. data/test/test_credentials.rb +0 -54
  45. data/test/ts_right_aws.rb +0 -13
@@ -80,6 +80,7 @@ module Aws
80
80
  # {:server => 's3.amazonaws.com' # Amazon service host: 's3.amazonaws.com'(default)
81
81
  # :port => 443 # Amazon service port: 80 or 443(default)
82
82
  # :protocol => 'https' # Amazon service protocol: 'http' or 'https'(default)
83
+ # :virtual_hosting => false # Force using bucket virtual hosting: https://s3.amazonaws.com/my-bucket vs. https://my-bucket.s3.amazonaws.com
83
84
  # :connection_mode => :default # options are
84
85
  # :default (will use best known safe (as in won't need explicit close) option, may change in the future)
85
86
  # :per_request (opens and closes a connection on every request)
@@ -306,7 +307,7 @@ module Aws
306
307
  @bucket = bucket
307
308
  @name = name.to_s
308
309
  @meta_headers = meta_headers
309
- raise 'Key name can not be empty.' if @name.blank?
310
+ raise 'Key name can not be empty.' if Aws::Utils.blank?(@name)
310
311
  end
311
312
 
312
313
  # Generate link to PUT key data.
@@ -50,10 +50,6 @@ module Aws
50
50
  @@bench
51
51
  end
52
52
 
53
- def self.bench
54
- @@bench
55
- end
56
-
57
53
  def self.bench_xml
58
54
  @@bench.xml
59
55
  end
@@ -135,13 +131,18 @@ module Aws
135
131
  server = @params[:server]
136
132
  service = @params[:service].to_s
137
133
  service.chop! if service[%r{/$}] # remove trailing '/' from service
138
- # extract bucket name and check it's dns compartibility
134
+ # extract bucket name and check it's dns compatibility
139
135
  headers[:url].to_s[%r{^([a-z0-9._-]*)(/[^?]*)?(\?.+)?}i]
140
136
  bucket_name, key_path, params_list = $1, $2, $3
141
137
  # select request model
142
- #if is_dns_bucket?(bucket_name)
143
- # is_dns_bucket isn't called since naming a bucket using URL's path always works (naming using dns cname may have an issue with Eucalyptus)
144
- path = "#{service}/#{bucket_name}#{key_path}#{params_list}"
138
+ if is_dns_bucket?(bucket_name) and !@params[:virtual_hosting]
139
+ # fix a path
140
+ server = "#{bucket_name}.#{server}"
141
+ key_path ||= '/'
142
+ path = "#{service}#{key_path}#{params_list}"
143
+ else
144
+ path = "#{service}/#{bucket_name}#{key_path}#{params_list}"
145
+ end
145
146
  path_to_sign = "#{service}/#{bucket_name}#{key_path}#{params_list}"
146
147
  [server, path, path_to_sign]
147
148
  end
@@ -158,13 +159,13 @@ module Aws
158
159
  headers['content-type'] ||= ''
159
160
  headers['date'] = Time.now.httpdate
160
161
  # create request
161
- request = "Net::HTTP::#{method.capitalize}".constantize.new(path)
162
+ request = Net::HTTP.const_get(method.capitalize).new(path)
162
163
  request.body = data if data
163
164
  # set request headers and meta headers
164
165
  headers.each { |key, value| request[key.to_s] = value }
165
166
  #generate auth strings
166
167
  auth_string = canonical_string(request.method, path_to_sign, request.to_hash)
167
- signature = AwsUtils::sign(@aws_secret_access_key, auth_string)
168
+ signature = Utils::sign(@aws_secret_access_key, auth_string)
168
169
  # set other headers
169
170
  request['Authorization'] = "AWS #{@aws_access_key_id}:#{signature}"
170
171
  # prepare output hash
@@ -206,7 +207,7 @@ module Aws
206
207
  #
207
208
  def create_bucket(bucket, headers={})
208
209
  data = nil
209
- unless headers[:location].blank?
210
+ unless Aws::Utils.blank?(headers[:location])
210
211
  # data = "<CreateBucketConfiguration><LocationConstraint>#{headers[:location].to_s.upcase}</LocationConstraint></CreateBucketConfiguration>"
211
212
  location = headers[:location].to_s
212
213
  location.upcase! if location == 'eu'
@@ -242,8 +243,8 @@ module Aws
242
243
  #
243
244
  #
244
245
  def get_logging_parse(params)
245
- AwsUtils.mandatory_arguments([:bucket], params)
246
- AwsUtils.allow_only([:bucket, :headers], params)
246
+ Utils.mandatory_arguments([:bucket], params)
247
+ Utils.allow_only([:bucket, :headers], params)
247
248
  params[:headers] = {} unless params[:headers]
248
249
  req_hash = generate_rest_request('GET', params[:headers].merge(:url=>"#{params[:bucket]}?logging"))
249
250
  request_info(req_hash, S3LoggingParser.new)
@@ -256,8 +257,8 @@ module Aws
256
257
  # :bucket
257
258
  # :xmldoc
258
259
  def put_logging(params)
259
- AwsUtils.mandatory_arguments([:bucket, :xmldoc], params)
260
- AwsUtils.allow_only([:bucket, :xmldoc, :headers], params)
260
+ Utils.mandatory_arguments([:bucket, :xmldoc], params)
261
+ Utils.allow_only([:bucket, :xmldoc, :headers], params)
261
262
  params[:headers] = {} unless params[:headers]
262
263
  req_hash = generate_rest_request('PUT', params[:headers].merge(:url=>"#{params[:bucket]}?logging", :data => params[:xmldoc]))
263
264
  request_info(req_hash, S3TrueParser.new)
@@ -295,7 +296,10 @@ module Aws
295
296
  # 'max-keys' => "5"}, ..., {...}]
296
297
  #
297
298
  def list_bucket(bucket, options={}, headers={})
298
- bucket += '?'+options.map { |k, v| "#{k.to_s}=#{CGI::escape v.to_s}" }.join('&') unless options.blank?
299
+ unless options.nil? || options.empty?
300
+ bucket << '?'
301
+ bucket << options.map { |k, v| "#{k.to_s}=#{CGI::escape v.to_s}" }.join('&')
302
+ end
299
303
  req_hash = generate_rest_request('GET', headers.merge(:url=>bucket))
300
304
  request_info(req_hash, S3ListBucketParser.new(:logger => @logger))
301
305
  rescue
@@ -330,10 +334,13 @@ module Aws
330
334
  # ]
331
335
  # }
332
336
  def incrementally_list_bucket(bucket, options={}, headers={}, &block)
333
- internal_options = options.symbolize_keys
337
+ internal_options = Hash[ options.map {|k,v| [k.to_sym, v] } ]
334
338
  begin
335
339
  internal_bucket = bucket.dup
336
- internal_bucket += '?'+internal_options.map { |k, v| "#{k.to_s}=#{CGI::escape v.to_s}" }.join('&') unless internal_options.blank?
340
+ unless internal_options.nil? || internal_options.empty?
341
+ internal_bucket << '?'
342
+ internal_bucket << internal_options.map { |k, v| "#{k.to_s}=#{CGI::escape v.to_s}" }.join('&')
343
+ end
337
344
  req_hash = generate_rest_request('GET', headers.merge(:url=>internal_bucket))
338
345
  response = request_info(req_hash, S3ImprovedListBucketParser.new(:logger => @logger))
339
346
  there_are_more_keys = response[:is_truncated]
@@ -462,8 +469,8 @@ module Aws
462
469
  # "content-length"=>"0"}
463
470
 
464
471
  def store_object(params)
465
- AwsUtils.allow_only([:bucket, :key, :data, :headers, :md5], params)
466
- AwsUtils.mandatory_arguments([:bucket, :key, :data], params)
472
+ Utils.allow_only([:bucket, :key, :data, :headers, :md5], params)
473
+ Utils.mandatory_arguments([:bucket, :key, :data], params)
467
474
  params[:headers] = {} unless params[:headers]
468
475
 
469
476
  params[:data].binmode if (params[:data].respond_to?(:binmode)) # On Windows, if someone opens a file in text mode, we must reset it to binary mode for streaming to work properly
@@ -506,7 +513,7 @@ module Aws
506
513
  # "server"=>"AmazonS3",
507
514
  # "content-length"=>"0"}
508
515
  def store_object_and_verify(params)
509
- AwsUtils.mandatory_arguments([:md5], params)
516
+ Utils.mandatory_arguments([:md5], params)
510
517
  r = store_object(params)
511
518
  r[:verified_md5] ? (return r) : (raise AwsError.new("Uploaded object failed MD5 checksum verification: #{r.inspect}"))
512
519
  end
@@ -587,8 +594,8 @@ module Aws
587
594
  # the response can be 'streamed'. The hash containing header fields is
588
595
  # still returned.
589
596
  def retrieve_object(params, &block)
590
- AwsUtils.mandatory_arguments([:bucket, :key], params)
591
- AwsUtils.allow_only([:bucket, :key, :headers, :md5], params)
597
+ Utils.mandatory_arguments([:bucket, :key], params)
598
+ Utils.allow_only([:bucket, :key, :headers, :md5], params)
592
599
  params[:headers] = {} unless params[:headers]
593
600
  req_hash = generate_rest_request('GET', params[:headers].merge(:url=>"#{params[:bucket]}/#{CGI::escape params[:key]}"))
594
601
  resp = request_info(req_hash, S3HttpResponseBodyParser.new, &block)
@@ -605,7 +612,7 @@ module Aws
605
612
  # If the check passes, returns the response metadata with the "verified_md5" field set true. Raises an exception if the checksums conflict.
606
613
  # This call is implemented as a wrapper around retrieve_object and the user may gain different semantics by creating a custom wrapper.
607
614
  def retrieve_object_and_verify(params, &block)
608
- AwsUtils.mandatory_arguments([:md5], params)
615
+ Utils.mandatory_arguments([:md5], params)
609
616
  resp = retrieve_object(params, &block)
610
617
  return resp if resp[:verified_md5]
611
618
  raise AwsError.new("Retrieved object failed MD5 checksum verification: #{resp.inspect}")
@@ -707,7 +714,7 @@ module Aws
707
714
  # <Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>" }
708
715
  #
709
716
  def get_acl(bucket, key='', headers={})
710
- key = key.blank? ? '' : "/#{CGI::escape key}"
717
+ key = Aws::Utils.blank?(key) ? '' : "/#{CGI::escape key}"
711
718
  req_hash = generate_rest_request('GET', headers.merge(:url=>"#{bucket}#{key}?acl"))
712
719
  request_info(req_hash, S3HttpResponseBodyParser.new)
713
720
  rescue
@@ -737,7 +744,7 @@ module Aws
737
744
  # :display_name=>"root"}}
738
745
  #
739
746
  def get_acl_parse(bucket, key='', headers={})
740
- key = key.blank? ? '' : "/#{CGI::escape key}"
747
+ key = Aws::Utils.blank?(key) ? '' : "/#{CGI::escape key}"
741
748
  req_hash = generate_rest_request('GET', headers.merge(:url=>"#{bucket}#{key}?acl"))
742
749
  acl = request_info(req_hash, S3AclParser.new(:logger => @logger))
743
750
  result = {}
@@ -761,7 +768,7 @@ module Aws
761
768
 
762
769
  # Sets the ACL on a bucket or object.
763
770
  def put_acl(bucket, key, acl_xml_doc, headers={})
764
- key = key.blank? ? '' : "/#{CGI::escape key}"
771
+ key = Aws::Utils.blank?(key) ? '' : "/#{CGI::escape key}"
765
772
  req_hash = generate_rest_request('PUT', headers.merge(:url=>"#{bucket}#{key}?acl", :data=>acl_xml_doc))
766
773
  request_info(req_hash, S3HttpResponseBodyParser.new)
767
774
  rescue
@@ -790,7 +797,7 @@ module Aws
790
797
  end
791
798
 
792
799
  def put_bucket_policy(bucket, policy)
793
- key = key.blank? ? '' : "/#{CGI::escape key}"
800
+ key = Aws::Utils.blank?(key) ? '' : "/#{CGI::escape key}"
794
801
  req_hash = generate_rest_request('PUT', {:url=>"#{bucket}?policy", :data=>policy})
795
802
  request_info(req_hash, S3HttpResponseBodyParser.new)
796
803
  rescue
@@ -910,7 +917,10 @@ module Aws
910
917
  # s3.list_bucket_link('my_awesome_bucket') #=> url string
911
918
  #
912
919
  def list_bucket_link(bucket, options=nil, expires=nil, headers={})
913
- bucket += '?' + options.map { |k, v| "#{k.to_s}=#{CGI::escape v.to_s}" }.join('&') unless options.blank?
920
+ unless options.nil? || options.empty?
921
+ bucket << '?'
922
+ bucket << options.map { |k, v| "#{k.to_s}=#{CGI::escape v.to_s}" }.join('&')
923
+ end
914
924
  generate_link('GET', headers.merge(:url=>bucket), expires)
915
925
  rescue
916
926
  on_exception
@@ -921,7 +931,7 @@ module Aws
921
931
  # s3.put_link('my_awesome_bucket',key, object) #=> url string
922
932
  #
923
933
  def put_link(bucket, key, data=nil, expires=nil, headers={})
924
- generate_link('PUT', headers.merge(:url=>"#{bucket}/#{AwsUtils::URLencode key}", :data=>data), expires)
934
+ generate_link('PUT', headers.merge(:url=>"#{bucket}/#{Utils::URLencode key}", :data=>data), expires)
925
935
  rescue
926
936
  on_exception
927
937
  end
@@ -939,7 +949,7 @@ module Aws
939
949
  #
940
950
  # see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/VirtualHosting.html
941
951
  def get_link(bucket, key, expires=nil, headers={})
942
- generate_link('GET', headers.merge(:url=>"#{bucket}/#{AwsUtils::URLencode key}"), expires)
952
+ generate_link('GET', headers.merge(:url=>"#{bucket}/#{Utils::URLencode key.to_s}"), expires)
943
953
  rescue
944
954
  on_exception
945
955
  end
@@ -949,7 +959,7 @@ module Aws
949
959
  # s3.head_link('my_awesome_bucket',key) #=> url string
950
960
  #
951
961
  def head_link(bucket, key, expires=nil, headers={})
952
- generate_link('HEAD', headers.merge(:url=>"#{bucket}/#{AwsUtils::URLencode key}"), expires)
962
+ generate_link('HEAD', headers.merge(:url=>"#{bucket}/#{Utils::URLencode key}"), expires)
953
963
  rescue
954
964
  on_exception
955
965
  end
@@ -959,7 +969,7 @@ module Aws
959
969
  # s3.delete_link('my_awesome_bucket',key) #=> url string
960
970
  #
961
971
  def delete_link(bucket, key, expires=nil, headers={})
962
- generate_link('DELETE', headers.merge(:url=>"#{bucket}/#{AwsUtils::URLencode key}"), expires)
972
+ generate_link('DELETE', headers.merge(:url=>"#{bucket}/#{Utils::URLencode key}"), expires)
963
973
  rescue
964
974
  on_exception
965
975
  end
@@ -970,7 +980,7 @@ module Aws
970
980
  # s3.get_acl_link('my_awesome_bucket',key) #=> url string
971
981
  #
972
982
  def get_acl_link(bucket, key='', headers={})
973
- return generate_link('GET', headers.merge(:url=>"#{bucket}/#{AwsUtils::URLencode key}?acl"))
983
+ return generate_link('GET', headers.merge(:url=>"#{bucket}/#{Utils::URLencode key}?acl"))
974
984
  rescue
975
985
  on_exception
976
986
  end
@@ -980,7 +990,7 @@ module Aws
980
990
  # s3.put_acl_link('my_awesome_bucket',key) #=> url string
981
991
  #
982
992
  def put_acl_link(bucket, key='', headers={})
983
- return generate_link('PUT', headers.merge(:url=>"#{bucket}/#{AwsUtils::URLencode key}?acl"))
993
+ return generate_link('PUT', headers.merge(:url=>"#{bucket}/#{Utils::URLencode key}?acl"))
984
994
  rescue
985
995
  on_exception
986
996
  end
@@ -1,7 +1,4 @@
1
- # THIS IS DEPRECATED NOW, PLEASE USE SimpleRecord instead:
2
- # http://github.com/appoxy/simple_record
3
-
4
-
1
+ puts 'WARNING: ActiveSdb is deprecated, please use SimpleRecord at https://github.com/appoxy/simple_record/ instead.'
5
2
 
6
3
  # Copyright (c) 2008 RightScale Inc
7
4
  #
@@ -32,8 +29,6 @@ rescue LoadError => e
32
29
  exit
33
30
  end
34
31
 
35
- puts 'WARNING: ActiveSdb is deprecated, please use SimpleRecord at https://github.com/appoxy/simple_record/ instead.'
36
-
37
32
  module Aws
38
33
 
39
34
  # = Aws::ActiveSdb -- RightScale SDB interface (alpha release)
@@ -375,7 +370,7 @@ module Aws
375
370
  # user defined :conditions to string (if it was defined)
376
371
  options[:conditions] = build_conditions(options[:conditions])
377
372
  # join ids condition and user defined conditions
378
- options[:conditions] = options[:conditions].blank? ? ids_cond : "(#{options[:conditions]}) AND #{ids_cond}"
373
+ options[:conditions] = Aws::Utils.blank?(options[:conditions]) ? ids_cond : "(#{options[:conditions]}) AND #{ids_cond}"
379
374
  #puts 'options=' + options.inspect
380
375
  result = sql_select(options)
381
376
  #puts 'select_from_ids result=' + result.inspect
@@ -482,7 +477,7 @@ module Aws
482
477
  query_expression = query_expression.to_s
483
478
  # quote from Amazon:
484
479
  # The sort attribute must be present in at least one of the predicates of the query expression.
485
- if query_expression.blank?
480
+ if Aws::Utils.blank?(query_expression)
486
481
  query_expression = sort_query_expression
487
482
  elsif !query_attributes(query_expression).include?(sort_by)
488
483
  query_expression += " intersection #{sort_query_expression}"
@@ -536,7 +531,7 @@ module Aws
536
531
  # user defined :conditions to string (if it was defined)
537
532
  options[:conditions] = build_conditions(options[:conditions])
538
533
  # join ids condition and user defined conditions
539
- options[:conditions] = options[:conditions].blank? ? ids_cond : "#{options[:conditions]} intersection #{ids_cond}"
534
+ options[:conditions] = Aws::Utils.blank?(options[:conditions]) ? ids_cond : "#{options[:conditions]} intersection #{ids_cond}"
540
535
  result = find_every(options)
541
536
  # if one record was requested then return it
542
537
  unless bunch_of_records_requested
@@ -598,9 +593,9 @@ module Aws
598
593
  order = options[:order] ? " ORDER BY #{options[:order]}" : ''
599
594
  limit = options[:limit] ? " LIMIT #{options[:limit]}" : ''
600
595
  # mix sort by argument (it must present in response)
601
- unless order.blank?
596
+ unless Aws::Utils.blank?(order)
602
597
  sort_by, sort_order = sort_options(options[:order])
603
- conditions << (conditions.blank? ? " WHERE " : " AND ") << "(#{sort_by} IS NOT NULL)"
598
+ conditions << (Aws::Utils.blank?(conditions) ? " WHERE " : " AND ") << "(#{sort_by} IS NOT NULL)"
604
599
  end
605
600
  "SELECT #{select} FROM `#{from}`#{conditions}#{order}#{limit}"
606
601
  end
@@ -688,7 +683,9 @@ module Aws
688
683
  def attributes=(attrs)
689
684
  old_id = @attributes['id']
690
685
  @attributes = uniq_values(attrs)
691
- @attributes['id'] = old_id if @attributes['id'].blank? && !old_id.blank?
686
+ if Aws::Utils.blank?(@attributes['id']) && !Aws::Utils.blank?(old_id)
687
+ @attributes['id'] = old_id
688
+ end
692
689
  self.attributes
693
690
  end
694
691
 
@@ -731,7 +728,7 @@ module Aws
731
728
  old_id = id
732
729
  attrs = connection.get_attributes(domain, id)[:attributes]
733
730
  @attributes = {}
734
- unless attrs.blank?
731
+ unless attrs.nil? || attrs.empty?
735
732
  attrs.each { |attribute, values| @attributes[attribute] = values }
736
733
  @attributes['id'] = old_id
737
734
  end
@@ -757,7 +754,7 @@ module Aws
757
754
  attrs_list.flatten.uniq.each do |attribute|
758
755
  attribute = attribute.to_s
759
756
  values = connection.get_attributes(domain, id, attribute)[:attributes][attribute]
760
- unless values.blank?
757
+ unless Aws::Utils.blank?(values)
761
758
  @attributes[attribute] = result[attribute] = values
762
759
  else
763
760
  @attributes.delete(attribute)
@@ -787,7 +784,7 @@ module Aws
787
784
  prepare_for_update
788
785
  attrs = @attributes.dup
789
786
  attrs.delete('id')
790
- connection.put_attributes(domain, id, attrs) unless attrs.blank?
787
+ connection.put_attributes(domain, id, attrs) unless Aws::Utils.blank?(attrs)
791
788
  connection.put_attributes(domain, id, { 'id' => id }, :replace)
792
789
  mark_as_old
793
790
  @attributes
@@ -803,10 +800,10 @@ module Aws
803
800
  prepare_for_update
804
801
  # if 'id' is present in attrs hash:
805
802
  # replace internal 'id' attribute and remove it from the attributes to be sent
806
- @attributes['id'] = attrs['id'] unless attrs['id'].blank?
803
+ @attributes['id'] = attrs['id'] unless Aws::Utils.blank?(attrs['id'])
807
804
  attrs.delete('id')
808
805
  # add new values to all attributes from list
809
- connection.put_attributes(domain, id, attrs) unless attrs.blank?
806
+ connection.put_attributes(domain, id, attrs) unless Aws::Utils.blank?(attrs)
810
807
  connection.put_attributes(domain, id, { 'id' => id }, :replace)
811
808
  attrs.each do |attribute, values|
812
809
  @attributes[attribute] ||= []
@@ -875,7 +872,7 @@ module Aws
875
872
  prepare_for_update
876
873
  attrs = uniq_values(attrs)
877
874
  # if 'id' is present in attrs hash then replace internal 'id' attribute
878
- unless attrs['id'].blank?
875
+ unless Aws::Utils.blank?(attrs['id'])
879
876
  @attributes['id'] = attrs['id']
880
877
  else
881
878
  attrs['id'] = id
@@ -899,7 +896,7 @@ module Aws
899
896
  raise_on_id_absence
900
897
  attrs = uniq_values(attrs)
901
898
  attrs.delete('id')
902
- unless attrs.blank?
899
+ unless attrs.nil? || attrs.empty?
903
900
  connection.delete_attributes(domain, id, attrs)
904
901
  attrs.each do |attribute, values|
905
902
  # remove the values from the attribute
@@ -928,7 +925,7 @@ module Aws
928
925
  raise_on_id_absence
929
926
  attrs_list = attrs_list.flatten.map{ |attribute| attribute.to_s }
930
927
  attrs_list.delete('id')
931
- unless attrs_list.blank?
928
+ unless attrs_list.empty?
932
929
  connection.delete_attributes(domain, id, attrs_list)
933
930
  attrs_list.each { |attribute| @attributes.delete(attribute) }
934
931
  end
@@ -970,7 +967,7 @@ module Aws
970
967
  end
971
968
 
972
969
  def prepare_for_update
973
- @attributes['id'] = self.class.generate_id if @attributes['id'].blank?
970
+ @attributes['id'] = self.class.generate_id if Aws::Utils.blank?(@attributes['id'])
974
971
  end
975
972
 
976
973
  def uniq_values(attributes=nil) # :nodoc:
@@ -979,7 +976,7 @@ module Aws
979
976
  attribute = attribute.to_s
980
977
  newval = attribute == 'id' ? values.to_s : values.is_a?(Array) ? values.uniq : [values]
981
978
  attrs[attribute] = newval
982
- if newval.blank?
979
+ if Aws::Utils.blank?(newval)
983
980
  # puts "VALUE IS BLANK " + attribute.to_s + " val=" + values.inspect
984
981
  attrs.delete(attribute)
985
982
  end
@@ -21,8 +21,6 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #
23
23
 
24
- require "aws"
25
-
26
24
  module Aws
27
25
 
28
26
  class SdbInterface < AwsBase
@@ -143,7 +141,8 @@ module Aws
143
141
  # see: http://docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API.html
144
142
  #
145
143
  def escape(value)
146
- %Q{'#{value.to_s.gsub(/(['\\])/) { "\\#{$1}" }}'} if value
144
+ # %Q{'#{value.to_s.gsub(/(['\\])/) { "\\#{$1}" }}'} if value
145
+ %{'#{value.to_s.gsub(/(['\\])/){"#{$1}#{$1}"}}'} if value
147
146
  end
148
147
 
149
148
  # Convert a Ruby language value to a SDB value by replacing Ruby nil with the user's chosen string representation of nil.
@@ -177,7 +176,7 @@ module Aws
177
176
  # (similar to ActiveRecord::Base#find using :conditions => ['query', param1, .., paramN])
178
177
  #
179
178
  def query_expression_from_array(params) #:nodoc:
180
- return '' if params.blank?
179
+ return '' if Aws::Utils.blank?(params)
181
180
  query = params[0].to_s
182
181
  i = 1
183
182
  query.gsub(/(\\)?(\?)/) do
@@ -192,7 +191,7 @@ module Aws
192
191
  end
193
192
 
194
193
  def query_expression_from_hash(hash)
195
- return '' if hash.blank?
194
+ return '' if Aws::Utils.blank?(hash)
196
195
  expression = []
197
196
  hash.each do |key, value|
198
197
  expression << "#{key}=#{escape(value)}"
@@ -0,0 +1,123 @@
1
+ require_relative "../awsbase/awsbase"
2
+ module Aws
3
+
4
+ require 'xmlsimple'
5
+
6
+ class Ses < AwsBase
7
+
8
+ include AwsBaseInterface
9
+
10
+ API_VERSION = "2010-12-01"
11
+ DEFAULT_HOST = "email.us-east-1.amazonaws.com"
12
+ DEFAULT_PATH = '/'
13
+ DEFAULT_PROTOCOL = 'https'
14
+ DEFAULT_PORT = 443
15
+
16
+ def self.connection_name
17
+ :ses_connection
18
+ end
19
+
20
+ @@bench = AwsBenchmarkingBlock.new
21
+
22
+ def self.bench
23
+ @@bench
24
+ end
25
+
26
+ def self.bench_xml
27
+ @@bench.xml
28
+ end
29
+
30
+ def self.bench_ec2
31
+ @@bench.service
32
+ end
33
+
34
+ # Current API version (sometimes we have to check it outside the GEM).
35
+ @@api = ENV['SES_API_VERSION'] || API_VERSION
36
+
37
+ def self.api
38
+ @@api
39
+ end
40
+
41
+
42
+ def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
43
+ init({:name => 'SES',
44
+ :default_host => ENV['SES_URL'] ? URI.parse(ENV['SES_URL']).host : DEFAULT_HOST,
45
+ :default_port => ENV['SES_URL'] ? URI.parse(ENV['SES_URL']).port : DEFAULT_PORT,
46
+ :default_service => ENV['SES_URL'] ? URI.parse(ENV['SES_URL']).path : DEFAULT_PATH,
47
+ :default_protocol => ENV['SES_URL'] ? URI.parse(ENV['SES_URL']).scheme : DEFAULT_PROTOCOL,
48
+ :api_version => API_VERSION,
49
+ :signature_version=>'3'},
50
+ aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'],
51
+ aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
52
+ params)
53
+ end
54
+
55
+ def do_request(action, params, options={})
56
+ link = generate_request(action, params)
57
+ puts "request=" + link[:request].inspect
58
+ resp = request_info_xml_simple3(self, link,
59
+ :group_tags =>{"LoadBalancersDescriptions"=>"LoadBalancersDescription",
60
+ "DBParameterGroups" =>"DBParameterGroup",
61
+ "DBSecurityGroups" =>"DBSecurityGroup",
62
+ "EC2SecurityGroups" =>"EC2SecurityGroup",
63
+ "IPRanges" =>"IPRange"},
64
+ :force_array =>["DBInstances",
65
+ "DBParameterGroups",
66
+ "DBSecurityGroups",
67
+ "EC2SecurityGroups",
68
+ "IPRanges"],
69
+ :pull_out_array =>options[:pull_out_array],
70
+ :pull_out_single=>options[:pull_out_single],
71
+ :wrapper =>options[:wrapper])
72
+ end
73
+
74
+
75
+ #-----------------------------------------------------------------
76
+ # REQUESTS
77
+ #-----------------------------------------------------------------
78
+
79
+
80
+ # options:
81
+ # :marker => value received from previous response if IsTruncated = true
82
+ # :max_items => number of items you want returned
83
+ # :path_previx => for filtering results, default is /
84
+ def get_send_quota(options={})
85
+ @logger.info("get_send_quota")
86
+
87
+ resp = do_request("GetSendQuota", options)
88
+
89
+
90
+ rescue Exception
91
+ on_exception
92
+ end
93
+
94
+ #
95
+ # name: name of certificate
96
+ # public_key: public key certificate in PEM-encoded format
97
+ # private_key: private key in PEM-encoded format
98
+ # options:
99
+ # :path => specify a path you want it stored in
100
+ # :certificate_chain => contents of certificate chain
101
+ def upload_server_certificate(name, public_key, private_key, options={})
102
+ params = {}
103
+ params['ServerCertificateName'] = name
104
+ params['PrivateKey'] = private_key
105
+ params['CertificateBody'] = public_key
106
+
107
+ params['CertificateChain'] = options[:certificate_chain] if options[:certificate_chain]
108
+ params['Path'] = options[:path] if options[:path]
109
+
110
+ p params
111
+
112
+ resp = do_request("UploadServerCertificate", params, :pull_out_array=>[:list_server_certificates_result, :server_certificate_metadata_list])
113
+
114
+
115
+ rescue Exception
116
+ on_exception
117
+ end
118
+
119
+
120
+ end
121
+
122
+
123
+ end