fog-aws 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +51 -2
  3. data/lib/fog/aws.rb +29 -27
  4. data/lib/fog/aws/elb.rb +0 -1
  5. data/lib/fog/aws/iam.rb +4 -2
  6. data/lib/fog/aws/kms.rb +180 -0
  7. data/lib/fog/aws/mock.rb +13 -1
  8. data/lib/fog/aws/models/compute/flavors.rb +40 -0
  9. data/lib/fog/aws/models/elasticache/cluster.rb +1 -0
  10. data/lib/fog/aws/models/kms/key.rb +34 -0
  11. data/lib/fog/aws/models/kms/keys.rb +29 -0
  12. data/lib/fog/aws/models/rds/server.rb +33 -26
  13. data/lib/fog/aws/parsers/compute/describe_reserved_instances.rb +1 -1
  14. data/lib/fog/aws/parsers/elasticache/cache_cluster_parser.rb +15 -3
  15. data/lib/fog/aws/parsers/kms/describe_key.rb +34 -0
  16. data/lib/fog/aws/parsers/kms/list_keys.rb +38 -0
  17. data/lib/fog/aws/parsers/rds/db_parser.rb +7 -14
  18. data/lib/fog/aws/rds.rb +1 -1
  19. data/lib/fog/aws/requests/compute/describe_spot_price_history.rb +59 -0
  20. data/lib/fog/aws/requests/compute/request_spot_instances.rb +80 -0
  21. data/lib/fog/aws/requests/dns/change_resource_record_sets.rb +36 -5
  22. data/lib/fog/aws/requests/dns/list_resource_record_sets.rb +33 -5
  23. data/lib/fog/aws/requests/elb/create_load_balancer.rb +15 -2
  24. data/lib/fog/aws/requests/iam/create_role.rb +5 -5
  25. data/lib/fog/aws/requests/kms/create_key.rb +62 -0
  26. data/lib/fog/aws/requests/kms/describe_key.rb +27 -0
  27. data/lib/fog/aws/requests/kms/list_keys.rb +82 -0
  28. data/lib/fog/aws/requests/rds/create_db_instance.rb +33 -38
  29. data/lib/fog/aws/requests/rds/create_db_instance_read_replica.rb +7 -2
  30. data/lib/fog/aws/requests/rds/promote_read_replica.rb +7 -6
  31. data/lib/fog/aws/requests/sns/subscribe.rb +1 -1
  32. data/lib/fog/aws/storage.rb +6 -3
  33. data/lib/fog/aws/version.rb +1 -1
  34. data/tests/helper.rb +2 -2
  35. data/tests/models/rds/helper.rb +10 -3
  36. data/tests/models/rds/server_tests.rb +7 -4
  37. data/tests/requests/compute/spot_instance_tests.rb +2 -2
  38. data/tests/requests/compute/spot_price_history_tests.rb +0 -2
  39. data/tests/requests/kms/helper.rb +27 -0
  40. data/tests/requests/kms/key_tests.rb +23 -0
  41. data/tests/requests/rds/helper.rb +52 -46
  42. data/tests/requests/rds/instance_tests.rb +16 -12
  43. metadata +12 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73747ec0175ac8091923c4376ba41da0626c0331
4
- data.tar.gz: c43e09c5fa96cf35808262263fa58cc8d30e59bf
3
+ metadata.gz: 20c52aa88f06a8177fe9d43fa20e7ebd444a9a64
4
+ data.tar.gz: e1616bbc74d55c0e431606b0cb11f91bab3fb68a
5
5
  SHA512:
6
- metadata.gz: ebb50ffdefcab540dd712073abf9be5ee889429a8b482f6c9300ad226d545d673dd7f9c228c57ba2bc444725d57078a053b053992f0b626bc9b47679820b2cf9
7
- data.tar.gz: 4e5c905d9c783195184d9e18a135e5aafa89cef6c0bbf2ad616a1e6a039274a305dabe4d153b58fb2873f2fd831e49dfd6601b6c517432bc3010651c8b8c7d71
6
+ metadata.gz: 77794deeef38718df73253ac8d9088691e64272ed14bc7180fa7c237e88c67e02b0c45f8c426e5311587cab8fe6523b7f287d752d08ee108180cded5ba54f1c8
7
+ data.tar.gz: e767e0eeefed0b8806a24633ca77f7acf5fb307f9e795f9afeef5a52893bf52fbee64ae70dc3d3766e405f86e8fadbd5f8c5286d4a3e53fc8bf13202180ba73a
data/README.md CHANGED
@@ -25,11 +25,60 @@ Or install it yourself as:
25
25
 
26
26
  ## Usage
27
27
 
28
- TODO: Write usage instructions here
28
+ Before you can use fog-aws, you must require it in your application:
29
+
30
+ ```ruby
31
+ require 'fog/aws'
32
+ ```
33
+
34
+ Since it's a bad practice to have your credentials in source code, you should load them from default fog configuration file: ```~/.fog```. This file could look like this:
35
+
36
+ ```
37
+ default:
38
+ aws_access_key_id: <YOUR_ACCESS_KEY_ID>
39
+ aws_secret_access_key: <YOUR_SECRET_ACCESS_KEY>
40
+ ```
41
+
42
+ ### Connecting to EC2 service
43
+ ```ruby
44
+ ec2 = Fog::Compute.new :provider => 'AWS', :region => 'us-west-2'
45
+ ```
46
+
47
+ You can review all the requests available with this service using ```#requests``` method:
48
+
49
+ ```ruby
50
+ ec2.requests # => [:allocate_address, :assign_private_ip_addresses, :associate_address, ...]
51
+ ```
52
+
53
+ ### Launch an EC2 on-demand instance:
54
+
55
+ ```ruby
56
+ response = ec2.run_instances(
57
+ "ami-23ebb513",
58
+ 1,
59
+ 1,
60
+ "InstanceType" => "t1.micro",
61
+ "SecurityGroup" => "ssh",
62
+ "KeyName" => "miguel"
63
+ )
64
+ instance_id = response.body["instancesSet"].first["instanceId"] # => "i-02db5af4"
65
+ instance = ec2.servers.get(instance_id)
66
+ instance.wait_for { ready? }
67
+ puts instance.public_ip_address # => "356.300.501.20"
68
+ ```
69
+
70
+ ### Terminate an EC2 instance:
71
+
72
+ ```ruby
73
+ instance = ec2.servers.get("i-02db5af4")
74
+ instance.destroy
75
+ ```
76
+
77
+ Fog::AWS is more than EC2 since it supports many services provided by AWS. The best way to learn and to know about how many services are supported is to take a look at the source code. To review the tests directory and to play with the library in ```irb``` can be very helpful resources as well.
29
78
 
30
79
  ## Contributing
31
80
 
32
- 1. Fork it ( https://github.com/[my-github-username]/fog-aws/fork )
81
+ 1. Fork it ( https://github.com/fog/fog-aws/fork )
33
82
  2. Create your feature branch (`git checkout -b my-new-feature`)
34
83
  3. Commit your changes (`git commit -am 'Add some feature'`)
35
84
  4. Push to the branch (`git push origin my-new-feature`)
@@ -3,9 +3,6 @@ require 'fog/xml'
3
3
  require 'fog/json'
4
4
 
5
5
  require File.expand_path('../aws/version', __FILE__)
6
- require File.expand_path('../aws/credential_fetcher', __FILE__)
7
- require File.expand_path('../aws/region_methods', __FILE__)
8
- require File.expand_path('../aws/signaturev4', __FILE__)
9
6
 
10
7
  module Fog
11
8
  module CDN
@@ -23,57 +20,62 @@ module Fog
23
20
  module Storage
24
21
  autoload :AWS, File.expand_path('../aws/storage', __FILE__)
25
22
  end
26
-
23
+
27
24
  module AWS
28
25
  extend Fog::Provider
29
26
 
30
- autoload :Mock, File.expand_path('../aws/mock', __FILE__)
27
+ autoload :CredentialFetcher, File.expand_path('../aws/credential_fetcher', __FILE__)
31
28
  autoload :Errors, File.expand_path('../aws/errors', __FILE__)
29
+ autoload :Mock, File.expand_path('../aws/mock', __FILE__)
30
+ autoload :RegionMethods, File.expand_path('../aws/region_methods', __FILE__)
31
+ autoload :SignatureV4, File.expand_path('../aws/signaturev4', __FILE__)
32
32
 
33
33
  # Services
34
- autoload :AutoScaling, File.expand_path('../aws/auto_scaling', __FILE__)
34
+ autoload :AutoScaling, File.expand_path('../aws/auto_scaling', __FILE__)
35
+ autoload :CloudFormation, File.expand_path('../aws/cloud_formation', __FILE__)
36
+ autoload :CloudWatch, File.expand_path('../aws/cloud_watch', __FILE__)
37
+ autoload :DataPipeline, File.expand_path('../aws/data_pipeline', __FILE__)
38
+ autoload :DynamoDB, File.expand_path('../aws/dynamodb', __FILE__)
39
+ autoload :ELB, File.expand_path('../aws/elb', __FILE__)
40
+ autoload :EMR, File.expand_path('../aws/emr', __FILE__)
35
41
  autoload :ElasticBeanstalk, File.expand_path('../aws/beanstalk', __FILE__)
36
- autoload :CloudFormation, File.expand_path('../aws/cloud_formation', __FILE__)
37
- autoload :CloudWatch, File.expand_path('../aws/cloud_watch', __FILE__)
38
- autoload :DataPipeline, File.expand_path('../aws/data_pipeline', __FILE__)
39
- autoload :DynamoDB, File.expand_path('../aws/dynamodb', __FILE__)
40
- autoload :Elasticache, File.expand_path('../aws/elasticache', __FILE__)
41
- autoload :ELB, File.expand_path('../aws/elb', __FILE__)
42
- autoload :EMR, File.expand_path('../aws/emr', __FILE__)
43
- autoload :Federation, File.expand_path('../aws/federation', __FILE__)
44
- autoload :Glacier, File.expand_path('../aws/glacier', __FILE__)
45
- autoload :IAM, File.expand_path('../aws/iam', __FILE__)
46
- autoload :RDS, File.expand_path('../aws/rds', __FILE__)
47
- autoload :Redshift, File.expand_path('../aws/redshift', __FILE__)
48
- autoload :SES, File.expand_path('../aws/ses', __FILE__)
49
- autoload :SimpleDB, File.expand_path('../aws/simpledb', __FILE__)
50
- autoload :SNS, File.expand_path('../aws/sns', __FILE__)
51
- autoload :SQS, File.expand_path('../aws/sqs', __FILE__)
52
- autoload :STS, File.expand_path('../aws/sts', __FILE__)
42
+ autoload :Elasticache, File.expand_path('../aws/elasticache', __FILE__)
43
+ autoload :Federation, File.expand_path('../aws/federation', __FILE__)
44
+ autoload :Glacier, File.expand_path('../aws/glacier', __FILE__)
45
+ autoload :IAM, File.expand_path('../aws/iam', __FILE__)
46
+ autoload :KMS, File.expand_path('../aws/kms', __FILE__)
47
+ autoload :RDS, File.expand_path('../aws/rds', __FILE__)
48
+ autoload :Redshift, File.expand_path('../aws/redshift', __FILE__)
49
+ autoload :SES, File.expand_path('../aws/ses', __FILE__)
50
+ autoload :SNS, File.expand_path('../aws/sns', __FILE__)
51
+ autoload :SQS, File.expand_path('../aws/sqs', __FILE__)
52
+ autoload :STS, File.expand_path('../aws/sts', __FILE__)
53
+ autoload :SimpleDB, File.expand_path('../aws/simpledb', __FILE__)
53
54
 
54
55
  service(:auto_scaling, 'AutoScaling')
55
56
  service(:beanstalk, 'ElasticBeanstalk')
56
57
  service(:cdn, 'CDN')
57
- service(:compute, 'Compute')
58
58
  service(:cloud_formation, 'CloudFormation')
59
59
  service(:cloud_watch, 'CloudWatch')
60
+ service(:compute, 'Compute')
60
61
  service(:data_pipeline, 'DataPipeline')
61
- service(:dynamodb, 'DynamoDB')
62
62
  service(:dns, 'DNS')
63
+ service(:dynamodb, 'DynamoDB')
63
64
  service(:elasticache, 'Elasticache')
64
65
  service(:elb, 'ELB')
65
66
  service(:emr, 'EMR')
66
67
  service(:federation, 'Federation')
67
68
  service(:glacier, 'Glacier')
68
69
  service(:iam, 'IAM')
70
+ service(:kms, 'KMS')
69
71
  service(:rds, 'RDS')
70
72
  service(:redshift, 'Redshift')
71
73
  service(:ses, 'SES')
72
74
  service(:simpledb, 'SimpleDB')
73
75
  service(:sns, 'SNS')
74
76
  service(:sqs, 'SQS')
75
- service(:sts, 'STS')
76
77
  service(:storage, 'Storage')
78
+ service(:sts, 'STS')
77
79
 
78
80
  def self.indexed_param(key, values)
79
81
  params = {}
@@ -206,4 +208,4 @@ module Fog
206
208
  options
207
209
  end
208
210
  end
209
- end
211
+ end
@@ -96,7 +96,6 @@ module Fog
96
96
  @aws_secret_access_key = options[:aws_secret_access_key]
97
97
 
98
98
  @signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key,@region,'elasticloadbalancing')
99
-
100
99
  end
101
100
 
102
101
  def data
@@ -10,7 +10,7 @@ module Fog
10
10
  class ValidationError < Fog::AWS::IAM::Error; end
11
11
 
12
12
  requires :aws_access_key_id, :aws_secret_access_key
13
- recognizes :host, :path, :port, :scheme, :persistent, :instrumentor, :instrumentor_name, :aws_session_token, :use_iam_profile, :aws_credentials_expire_at
13
+ recognizes :host, :path, :port, :scheme, :persistent, :instrumentor, :instrumentor_name, :aws_session_token, :use_iam_profile, :aws_credentials_expire_at, :region
14
14
 
15
15
  request_path 'fog/aws/requests/iam'
16
16
  request :add_user_to_group
@@ -211,6 +211,7 @@ module Fog
211
211
  @persistent = options[:persistent] || false
212
212
  @port = options[:port] || 443
213
213
  @scheme = options[:scheme] || 'https'
214
+ @region = options[:region] || "us-east-1"
214
215
  @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
215
216
 
216
217
  setup_credentials(options)
@@ -230,7 +231,8 @@ module Fog
230
231
  @aws_credentials_expire_at = options[:aws_credentials_expire_at]
231
232
 
232
233
  #global services that have no region are signed with the us-east-1 region
233
- @signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key,'us-east-1','iam')
234
+ #the only exception is GovCloud, which requires the region to be explicitly specified as us-gov-west-1
235
+ @signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key, @region,'iam')
234
236
  end
235
237
 
236
238
  def request(params)
@@ -0,0 +1,180 @@
1
+ module Fog
2
+ module AWS
3
+ class KMS < Fog::Service
4
+ extend Fog::AWS::CredentialFetcher::ServiceMethods
5
+
6
+ DependencyTimeoutException = Class.new(Fog::Errors::Error)
7
+ DisabledException = Class.new(Fog::Errors::Error)
8
+ InvalidArnException = Class.new(Fog::Errors::Error)
9
+ InvalidGrantTokenException = Class.new(Fog::Errors::Error)
10
+ InvalidKeyUsageException = Class.new(Fog::Errors::Error)
11
+ KMSInternalException = Class.new(Fog::Errors::Error)
12
+ KeyUnavailableException = Class.new(Fog::Errors::Error)
13
+ MalformedPolicyDocumentException = Class.new(Fog::Errors::Error)
14
+ NotFoundException = Class.new(Fog::Errors::Error)
15
+
16
+ requires :aws_access_key_id, :aws_secret_access_key
17
+ recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :instrumentor, :instrumentor_name
18
+
19
+ request_path 'fog/aws/requests/kms'
20
+ request :list_keys
21
+ request :create_key
22
+ request :describe_key
23
+
24
+ model_path 'fog/aws/models/kms'
25
+ model :key
26
+ collection :keys
27
+
28
+ class Mock
29
+ def self.data
30
+ @data ||= Hash.new do |hash, region|
31
+ hash[region] = Hash.new do |region_hash, access_key|
32
+ region_hash[access_key] = {
33
+ :keys => {},
34
+ }
35
+ end
36
+ end
37
+ end
38
+
39
+ def self.reset
40
+ @data.clear
41
+ end
42
+
43
+ attr_reader :account_id
44
+
45
+ def initialize(options={})
46
+ @use_iam_profile = options[:use_iam_profile]
47
+ @account_id = Fog::AWS::Mock.owner_id
48
+
49
+ @region = options[:region] || 'us-east-1'
50
+ setup_credentials(options)
51
+
52
+ unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
53
+ raise ArgumentError, "Unknown region: #{@region.inspect}"
54
+ end
55
+ end
56
+
57
+ def setup_credentials(options)
58
+ @aws_access_key_id = options[:aws_access_key_id]
59
+ @aws_secret_access_key = options[:aws_secret_access_key]
60
+
61
+ @signer = Fog::AWS::SignatureV4.new(@aws_access_key_id, @aws_secret_access_key, @region, 'kms')
62
+ end
63
+
64
+ def data
65
+ self.class.data[@region][@aws_access_key_id]
66
+ end
67
+
68
+ def reset_data
69
+ self.class.data[@region].delete(@aws_access_key_id)
70
+ end
71
+ end
72
+
73
+ class Real
74
+ include Fog::AWS::CredentialFetcher::ConnectionMethods
75
+ # Initialize connection to KMS
76
+ #
77
+ # ==== Notes
78
+ # options parameter must include values for :aws_access_key_id and
79
+ # :aws_secret_access_key in order to create a connection
80
+ #
81
+ # ==== Examples
82
+ # kms = KMS.new(
83
+ # :aws_access_key_id => your_aws_access_key_id,
84
+ # :aws_secret_access_key => your_aws_secret_access_key
85
+ # )
86
+ #
87
+ # ==== Parameters
88
+ # * options<~Hash> - config arguments for connection. Defaults to {}.
89
+ # * region<~String> - optional region to use. For instance, 'eu-west-1', 'us-east-1', etc.
90
+ #
91
+ # ==== Returns
92
+ # * KMS object with connection to AWS.
93
+ def initialize(options={})
94
+
95
+ @use_iam_profile = options[:use_iam_profile]
96
+ @connection_options = options[:connection_options] || {}
97
+ @instrumentor = options[:instrumentor]
98
+ @instrumentor_name = options[:instrumentor_name] || 'fog.aws.kms'
99
+
100
+ options[:region] ||= 'us-east-1'
101
+
102
+ @region = options[:region]
103
+ @host = options[:host] || "kms.#{@region}.amazonaws.com"
104
+ @path = options[:path] || '/'
105
+ @persistent = options[:persistent] || false
106
+ @port = options[:port] || 443
107
+ @scheme = options[:scheme] || 'https'
108
+
109
+ @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
110
+
111
+ setup_credentials(options)
112
+ end
113
+
114
+ def reload
115
+ @connection.reset
116
+ end
117
+
118
+ private
119
+
120
+ def setup_credentials(options={})
121
+ @aws_access_key_id = options[:aws_access_key_id]
122
+ @aws_secret_access_key = options[:aws_secret_access_key]
123
+ @aws_session_token = options[:aws_session_token]
124
+
125
+ @signer = Fog::AWS::SignatureV4.new(@aws_access_key_id, @aws_secret_access_key, @region, 'kms')
126
+ end
127
+
128
+ def request(params)
129
+ refresh_credentials_if_expired
130
+
131
+ idempotent = params.delete(:idempotent)
132
+ parser = params.delete(:parser)
133
+
134
+ body, headers = Fog::AWS.signed_params_v4(
135
+ params,
136
+ { 'Content-Type' => 'application/x-www-form-urlencoded' },
137
+ {
138
+ :aws_session_token => @aws_session_token,
139
+ :signer => @signer,
140
+ :host => @host,
141
+ :path => @path,
142
+ :port => @port,
143
+ :version => '2014-11-01',
144
+ :method => 'POST'
145
+ }
146
+ )
147
+
148
+ if @instrumentor
149
+ @instrumentor.instrument("#{@instrumentor_name}.request", params) do
150
+ _request(body, headers, idempotent, parser)
151
+ end
152
+ else
153
+ _request(body, headers, idempotent, parser)
154
+ end
155
+ end
156
+
157
+ def _request(body, headers, idempotent, parser)
158
+ @connection.request({
159
+ :body => body,
160
+ :expects => 200,
161
+ :headers => headers,
162
+ :idempotent => idempotent,
163
+ :method => 'POST',
164
+ :parser => parser
165
+ })
166
+ rescue Excon::Errors::HTTPStatusError => error
167
+ match = Fog::AWS::Errors.match_error(error)
168
+
169
+ if match.empty?
170
+ raise
171
+ elsif Fog::AWS::KMS.const_defined?(match[:code])
172
+ raise Fog::AWS::KMS.const_get(match[:code]).slurp(error, match[:message])
173
+ else
174
+ raise Fog::AWS::KMS::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end
180
+ end
@@ -165,6 +165,18 @@ module Fog
165
165
  def self.rds_address(db_name,region)
166
166
  "#{db_name}.#{Fog::Mock.random_letters(rand(12) + 4)}.#{region}.rds.amazonaws.com"
167
167
  end
168
+
169
+ def self.spot_instance_request_id
170
+ "sir-#{Fog::Mock.random_letters_and_numbers(8)}"
171
+ end
172
+
173
+ def self.spot_product_descriptions
174
+ [
175
+ 'Linux/UNIX',
176
+ 'Windows',
177
+ 'SUSE Linux'
178
+ ]
179
+ end
168
180
  end
169
181
  end
170
- end
182
+ end
@@ -433,6 +433,46 @@ module Fog
433
433
  :disk => 640,
434
434
  :ebs_optimized_available => true,
435
435
  :instance_store_volumes => 2
436
+ },
437
+ {
438
+ :id => "d2.xlarge",
439
+ :name => "D2 Extra Large",
440
+ :bits => 64,
441
+ :cores => 4,
442
+ :ram => 31232,
443
+ :disk => 6000,
444
+ :ebs_optimized_available => true,
445
+ :instance_store_volumes => 3
446
+ },
447
+ {
448
+ :id => "d2.2xlarge",
449
+ :name => "D2 Double Extra Large",
450
+ :bits => 64,
451
+ :cores => 8,
452
+ :ram => 62464,
453
+ :disk => 12000,
454
+ :ebs_optimized_available => true,
455
+ :instance_store_volumes => 6
456
+ },
457
+ {
458
+ :id => "d2.4xlarge",
459
+ :name => "D2 Quadruple Extra Large",
460
+ :bits => 64,
461
+ :cores => 16,
462
+ :ram => 124928,
463
+ :disk => 24000,
464
+ :ebs_optimized_available => true,
465
+ :instance_store_volumes => 12
466
+ },
467
+ {
468
+ :id => "d2.8xlarge",
469
+ :name => "D2 Eight Extra Large",
470
+ :bits => 64,
471
+ :cores => 36,
472
+ :ram => 249856,
473
+ :disk => 48000,
474
+ :ebs_optimized_available => true,
475
+ :instance_store_volumes => 24
436
476
  }
437
477
  ]
438
478