miasma-aws 0.1.26 → 0.1.28

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: e2b126709ec8b6eed394efa4132e8937bd58239b
4
- data.tar.gz: c7337847d54b916534769749f7fd04b22a323487
3
+ metadata.gz: 07096224821dda2e08f3bda1532073082f12266d
4
+ data.tar.gz: 3c64010ced9c7dceb1f2c4202946538b76f8fe3d
5
5
  SHA512:
6
- metadata.gz: 34e2134959017fdc2139cbc50d968c8976c2049cfee4446d43a191ca959df5f027ad2f9ad778f388154b7d5eca1cbc534145961758b05886ea6323a8fe587f0e
7
- data.tar.gz: 4dde8df2ee26860791d52955b7ac1ad2a95a7086cbb6fce31c648b6519ac77ea3071f93a8c47179cef432a651d7dcea9164cd83bf0976391156cbd4cbf11e2ed
6
+ metadata.gz: f4cde26b9fce70ec6d900b823f7366018a0c075f6a891a0ee7aeddad68b11a1d65b5aa4c661d689d52a04fd4a444dc697f7c05817c35ee367f1a0881624ec995
7
+ data.tar.gz: bfe73ddbdc975d9f48ee3a01ed1bd7f2c2a1e4736693d21e67fee32bbd5585f1fd20d7054fdda5f910bc5f3d98c030f723578fec2016021edae68a59bb633813
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # v0.1.28
2
+ * Fix STS usage when building new API connections from existing connections (#21 and #23)
3
+
4
+ __Note:__ Thanks to @cixelsyd and @imbriaco for getting this sorted
5
+
1
6
  # v0.1.26
2
7
  * Fix broken S3 API interactions due to ordering in header modifications
3
8
 
@@ -1,4 +1,4 @@
1
1
  module MiasmaAws
2
2
  # Current library version
3
- VERSION = Gem::Version.new('0.1.26')
3
+ VERSION = Gem::Version.new('0.1.28')
4
4
  end
@@ -383,7 +383,8 @@ module Miasma
383
383
  end
384
384
  end
385
385
 
386
- # Allow loading credentials via local credentials file
386
+ # Provide custom setup functionality to support alternative
387
+ # credential loading.
387
388
  #
388
389
  # @param creds [Hash]
389
390
  # @return [TrueClass]
@@ -410,6 +411,21 @@ module Miasma
410
411
  true
411
412
  end
412
413
 
414
+ # Persist any underlying stored credential data that is not a
415
+ # defined attribute (things like STS information)
416
+ #
417
+ # @param creds [Hash]
418
+ # @return [TrueClass]
419
+ def after_setup(creds)
420
+ skip = self.class.attributes.keys.map(&:to_s)
421
+ creds.each do |k,v|
422
+ k = k.to_s
423
+ if(k.start_with?('aws_') && !skip.include?(k))
424
+ data[k] = v
425
+ end
426
+ end
427
+ end
428
+
413
429
  # Attempt to load credentials from instance metadata
414
430
  #
415
431
  # @param creds [Hash]
@@ -462,21 +478,23 @@ module Miasma
462
478
  creds[:aws_access_key_id_original] = creds[:aws_access_key_id]
463
479
  creds[:aws_secret_access_key_original] = creds[:aws_secret_access_key]
464
480
  end
465
- sts = Miasma::Contrib::Aws::Api::Sts.new(
466
- :aws_access_key_id => creds[:aws_access_key_id_original],
467
- :aws_secret_access_key => creds[:aws_secret_access_key_original],
468
- :aws_region => creds.fetch(:aws_sts_region, 'us-east-1'),
469
- :aws_credentials_file => creds.fetch(:aws_credentials_file, aws_credentials_file),
470
- :aws_config_file => creds.fetch(:aws_config_file, aws_config_file),
471
- :aws_profile_name => creds[:aws_profile_name],
472
- :aws_host => creds[:aws_host]
473
- )
474
- role_info = sts.assume_role(
475
- creds[:aws_sts_role_arn],
476
- :session_name => creds[:aws_sts_role_session_name],
477
- :external_id => creds[:aws_sts_external_id]
478
- )
479
- creds.merge!(role_info)
481
+ if(sts_update_required?(creds))
482
+ sts = Miasma::Contrib::Aws::Api::Sts.new(
483
+ :aws_access_key_id => creds[:aws_access_key_id_original],
484
+ :aws_secret_access_key => creds[:aws_secret_access_key_original],
485
+ :aws_region => creds.fetch(:aws_sts_region, 'us-east-1'),
486
+ :aws_credentials_file => creds.fetch(:aws_credentials_file, aws_credentials_file),
487
+ :aws_config_file => creds.fetch(:aws_config_file, aws_config_file),
488
+ :aws_profile_name => creds[:aws_profile_name],
489
+ :aws_host => creds[:aws_host]
490
+ )
491
+ role_info = sts.assume_role(
492
+ creds[:aws_sts_role_arn],
493
+ :session_name => creds[:aws_sts_role_session_name],
494
+ :external_id => creds[:aws_sts_external_id]
495
+ )
496
+ creds.merge!(role_info)
497
+ end
480
498
  true
481
499
  end
482
500
 
@@ -611,6 +629,7 @@ module Miasma
611
629
  end
612
630
  end
613
631
  if(aws_sts_token)
632
+ sts_assume_role!(data) if sts_update_required?
614
633
  options.set(:headers, 'X-Amz-Security-Token', aws_sts_token)
615
634
  end
616
635
  signature = signer.generate(http_method, path, options)
@@ -619,6 +638,12 @@ module Miasma
619
638
  connection.auth(signature).send(http_method, dest, options)
620
639
  end
621
640
 
641
+ # @return [TrueClass, FalseClass]
642
+ def sts_update_required?(args={})
643
+ expiry = args.fetch(:aws_sts_token_expires, data[:aws_sts_token_expires])
644
+ expiry.nil? || expiry >= Time.now - 1
645
+ end
646
+
622
647
  # Simple callback to allow request option adjustments prior to
623
648
  # signature calculation
624
649
  #
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.26
4
+ version: 0.1.28
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-10-01 00:00:00.000000000 Z
11
+ date: 2015-10-06 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: