miasma-aws 0.1.20 → 0.1.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a5b3fe06aa37c3bdc942bceffde1af07852cc74
4
- data.tar.gz: 32e6a2752c4da9a2003da5bba5cf00e9c19ae83a
3
+ metadata.gz: b255feb4bbbd9158ce1928df6b560eafc4b481c5
4
+ data.tar.gz: 7d54dcb2b4b96012cab3e13d89a772604d9b378d
5
5
  SHA512:
6
- metadata.gz: 8ad263d55d74bb5058fcd0ac9b89704605ceb4800976b5519b63b71d2f20bd90d55cfde05fa92ecaba303605a787cdad97f8c8935529555aebe0af6db6aef81c
7
- data.tar.gz: b4fd118303c565890fff9015e9419fbd228c81f4e220f0bb24d39e2f2ade212d2dd0a3f6665827198f82648d2e7c21bd9f90c505408c85a59b18d25323f77350
6
+ metadata.gz: 32ab9151988b38628bec1e50b96e3cc360624c04d656e7c959586a31e6c6bac8d4a5d5e17d2fb47108b01d6ef0dabfa7ecf97036841a29e1e54573453bbdbdcf
7
+ data.tar.gz: e3ceba8f15b6679679f333676a89fe7caa4ef250a047b75fcd5df15761ac50b42e46661cf15180957fed7af107dcabd91a68970aa548261ea546e2257d20b36a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # v0.1.22
2
+ * Fix instance profile credential auto loading
3
+ * Add support for region auto-detection when using instance profiles
4
+ * Update requests to use HTTP GET where possible for better retry support
5
+
1
6
  # v0.1.20
2
7
  * Fix credential loading bug (#11)
3
8
 
@@ -1,4 +1,4 @@
1
1
  module MiasmaAws
2
2
  # Current library version
3
- VERSION = Gem::Version.new('0.1.20')
3
+ VERSION = Gem::Version.new('0.1.22')
4
4
  end
@@ -344,7 +344,7 @@ module Miasma
344
344
  attribute :aws_host, String
345
345
  attribute :aws_bucket_region, String
346
346
  attribute :api_endpoint, String, :required => true, :default => 'amazonaws.com'
347
- attribute :euca_compat, [String, Symbol], :allowed_values => [:path, :dns], :coerce => lambda{|v| v.is_a?(String) ? v.to_sym : v}
347
+ attribute :euca_compat, Symbol, :allowed_values => [:path, :dns], :coerce => lambda{|v| v.is_a?(String) ? v.to_sym : v}
348
348
  attribute :euca_dns_map, Smash, :coerce => lambda{|v| v.to_smash}, :default => Smash.new
349
349
  attribute :ssl_enabled, [TrueClass, FalseClass], :default => true
350
350
 
@@ -355,11 +355,13 @@ module Miasma
355
355
  # AWS config file key remapping
356
356
  klass.const_set(:CONFIG_FILE_REMAP,
357
357
  Smash.new(
358
- 'region' => 'aws_region'
358
+ 'region' => 'aws_region',
359
+ 'role_arn' => 'aws_sts_role_arn'
359
360
  )
360
361
  )
361
362
  klass.const_set(:INSTANCE_PROFILE_HOST, 'http://169.254.169.254')
362
363
  klass.const_set(:INSTANCE_PROFILE_PATH, 'latest/meta-data/iam/security-credentials')
364
+ klass.const_set(:INSTANCE_PROFILE_AZ_PATH, 'latest/meta-data/placement/availability-zone')
363
365
  end
364
366
 
365
367
  # Build new API for specified type using current provider / creds
@@ -412,7 +414,13 @@ module Miasma
412
414
  # @param creds [Hash]
413
415
  # @return [TrueClass]
414
416
  def load_instance_credentials!(creds)
415
- role = HTTP.get(self.class.const_get(:INSTANCE_PROFILE_HOST)).body.to_s.strip
417
+ role = HTTP.get(
418
+ [
419
+ self.class.const_get(:INSTANCE_PROFILE_HOST),
420
+ self.class.const_get(:INSTANCE_PROFILE_PATH),
421
+ ''
422
+ ].join('/')
423
+ ).body.to_s.strip
416
424
  data = HTTP.get(
417
425
  [
418
426
  self.class.const_get(:INSTANCE_PROFILE_HOST),
@@ -420,10 +428,27 @@ module Miasma
420
428
  role
421
429
  ].join('/')
422
430
  ).body
431
+ unless(data.is_a?(Hash))
432
+ begin
433
+ data = MultiJson.load(data.to_s)
434
+ rescue MultiJson::ParseError
435
+ data = {}
436
+ end
437
+ end
423
438
  creds[:aws_access_key_id] = data['AccessKeyId']
424
439
  creds[:aws_secret_access_key] = data['SecretAccessKey']
425
440
  creds[:aws_sts_token] = data['Token']
426
441
  creds[:aws_sts_token_expires] = Time.xmlschema(data['Expiration'])
442
+ unless(creds[:aws_region])
443
+ az = HTTP.get(
444
+ [
445
+ self.class.const_get(:INSTANCE_PROFILE_HOST),
446
+ self.class.const_get(:INSTANCE_PROFILE_AZ_PATH)
447
+ ].join('/')
448
+ ).body.to_s.strip
449
+ az.sub!(/[a-zA-Z]+$/, '')
450
+ creds[:aws_region] = az
451
+ end
427
452
  true
428
453
  end
429
454
 
@@ -486,12 +511,16 @@ module Miasma
486
511
  end
487
512
  end
488
513
  end
489
- l_config.fetch(
514
+
515
+ l_profile = l_config.fetch(profile, Smash.new)
516
+ l_source_profile = l_config.fetch(l_profile[:source_profile], Smash.new)
517
+
518
+ l_creds = l_config.fetch(
490
519
  :default, Smash.new
491
520
  ).merge(
492
- l_config.fetch(
493
- profile, Smash.new
494
- )
521
+ l_source_profile
522
+ ).merge(
523
+ l_profile
495
524
  )
496
525
  else
497
526
  Smash.new
@@ -506,7 +535,7 @@ module Miasma
506
535
  self.class.const_defined?(:EUCA_API_SERVICE) ?
507
536
  self.class::EUCA_API_SERVICE :
508
537
  self.class::API_SERVICE
509
- ).downcase
538
+ )
510
539
  else
511
540
  service_name = self.class::API_SERVICE.downcase
512
541
  end
@@ -13,6 +13,8 @@ module Miasma
13
13
 
14
14
  # Service name of the API
15
15
  API_SERVICE = 'cloudformation'
16
+ # Service name of the eucalyptus API
17
+ EUCA_API_SERVICE = 'CloudFormation'
16
18
  # Supported version of the AutoScaling API
17
19
  API_VERSION = '2010-05-15'
18
20
 
@@ -63,35 +65,27 @@ module Miasma
63
65
  descriptions = all_result_pages(nil, :body, 'DescribeStacksResponse', 'DescribeStacksResult', 'Stacks', 'member') do |options|
64
66
  request(
65
67
  :path => '/',
66
- :form => options.merge(d_params),
67
- :method => :post
68
+ :params => options.merge(d_params),
69
+ :method => :get
68
70
  )
69
71
  end
70
- policy = request(
71
- :path => '/',
72
- :method => :get,
73
- :params => Smash.new(
74
- 'Action' => 'GetStackPolicy',
75
- 'StackName' => stack.id
72
+ else
73
+ lists = all_result_pages(nil, :body, 'ListStacksResponse', 'ListStacksResult', 'StackSummaries', 'member') do |options|
74
+ request(
75
+ :path => '/',
76
+ :form => options.merge(l_params),
77
+ :method => :post
76
78
  )
77
- ).get(:body, 'GetStackPolicyResult', 'StackPolicyBody')
78
- if(policy)
79
- descriptions.first[:stack_policy] = MultiJson.load(policy).to_smash
80
79
  end
81
- else
82
80
  descriptions = []
83
81
  end
84
- lists = all_result_pages(nil, :body, 'ListStacksResponse', 'ListStacksResult', 'StackSummaries', 'member') do |options|
85
- request(
86
- :path => '/',
87
- :form => options.merge(l_params),
88
- :method => :post
89
- )
90
- end.map do |stk|
91
- desc = descriptions.detect do |d_stk|
92
- d_stk['StackId'] == stk['StackId']
93
- end || Smash.new
94
- stk.merge!(desc)
82
+ (lists || descriptions).map do |stk|
83
+ if(lists)
84
+ desc = descriptions.detect do |d_stk|
85
+ d_stk['StackId'] == stk['StackId']
86
+ end || Smash.new
87
+ stk.merge!(desc)
88
+ end
95
89
  if(stack)
96
90
  next if stack.id != stk['StackId'] && stk['StackId'].split('/')[1] != stack.id
97
91
  end
@@ -136,7 +130,8 @@ module Miasma
136
130
  }
137
131
  ],
138
132
  :custom => Smash.new(
139
- :stack_policy_body => policy
133
+ :stack_policy => stk['StackPolicyBody'],
134
+ :stack_policy_url => stk['StackPolicyURL']
140
135
  )
141
136
  ).valid_state
142
137
  end
@@ -314,8 +309,8 @@ module Miasma
314
309
  results = all_result_pages(nil, :body, 'DescribeStackResourcesResponse', 'DescribeStackResourcesResult', 'StackResources', 'member') do |options|
315
310
  request(
316
311
  :path => '/',
317
- :method => :post,
318
- :form => options.merge(
312
+ :method => :get,
313
+ :params => options.merge(
319
314
  Smash.new(
320
315
  'Action' => 'DescribeStackResources',
321
316
  'StackName' => stack.id
@@ -354,8 +349,8 @@ module Miasma
354
349
  results = all_result_pages(nil, :body, 'DescribeStackEventsResponse', 'DescribeStackEventsResult', 'StackEvents', 'member') do |options|
355
350
  request(
356
351
  :path => '/',
357
- :method => :post,
358
- :form => options.merge(
352
+ :method => :get,
353
+ :params => options.merge(
359
354
  'Action' => 'DescribeStackEvents',
360
355
  'StackName' => stack.id
361
356
  )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miasma-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20
4
+ version: 0.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-26 00:00:00.000000000 Z
11
+ date: 2015-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: miasma
@@ -134,9 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.2.2
137
+ rubygems_version: 2.4.8
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: Smoggy AWS API
141
141
  test_files: []
142
- has_rdoc: