mydrive-aws-mfa 1.0.1 → 1.1.0

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
- SHA1:
3
- metadata.gz: 07621ca0fa5c31dd33e4f4fb34d1712e00912a44
4
- data.tar.gz: eb7ee3da6efd28847f03215a0b36152138102a08
2
+ SHA256:
3
+ metadata.gz: 5776f52ef1b781f9aeea4996019358182f49502f27ed0ad943e0a1a55ce8e2d6
4
+ data.tar.gz: b1e19ee73a61ace3c884f984e0967a539ae2302efb7503dff7aeb31f810a75fd
5
5
  SHA512:
6
- metadata.gz: 3cee3d86acda2ef27e9ad2dc1eb1a2b6c617372d34fc7edbc2eb2696ccfc5afe560471de798b75e0457d86e10a8280b49c0e4b8dc3b64104c042c38d70d8b244
7
- data.tar.gz: 4a64ec6e80f54da21973ef65c4d3053f29ed5e9707e78572735c474ba24bcbcc239a2aff790ae5b7d8815739cb99c2fae8ed3f4972b60a9283c5dd8a9a2940b9
6
+ metadata.gz: dcb52467e7e567861ba18101affbcad5c508dba8f9e0acbe7db1bd921b26fc65b94fe95a250e3979ffacd811492e0c1040626cadaeb4966f69c892b79dc89ae8
7
+ data.tar.gz: b01e529138a2ff94dbeca9abd6dc3111af935819c8fe781562733bdf2559eca0795e060f8648e58c4196a1c7a0367cceec635c2ab67978cbe5d1b7dc5b41cc68
@@ -1,6 +1,6 @@
1
- require 'aws-sdk-core/ini_parser'
2
1
  require 'fileutils'
3
2
  require 'json'
3
+ require_relative 'aws_mfa/config_loader'
4
4
  require_relative 'aws_mfa/credentials_output_executor'
5
5
  require_relative 'aws_mfa/credentials_loader'
6
6
  require_relative 'aws_mfa/errors'
@@ -8,17 +8,16 @@ require_relative 'aws_mfa/profile_config'
8
8
  require_relative 'aws_mfa/shell_command'
9
9
 
10
10
  class AwsMfa
11
- ARN_CONFIG_FILE_PATH = ".aws/config"
12
11
  MYDRIVE_CREDENTIALS_FILE_PATH = '.mydrive-aws'
13
12
 
14
13
  def initialize
15
14
  verify_aws_installed
16
- @aws_config_file = find_aws_config_file
15
+ verify_config_file
17
16
  @mydrive_credentials_cache_dir = set_mydrive_credentials_cache_dir
18
17
  end
19
18
 
20
19
  def execute(execution_output = :set_env, profile = nil)
21
- aws_profile = profile || ENV['AWS_PROFILE'] || 'default'
20
+ aws_profile = profile || ENV['AWS_PROFILE'] || "default"
22
21
  profile_config = load_profile_config(aws_profile)
23
22
  credentials = load_credentials(profile_config)
24
23
  execute_output(execution_output, credentials)
@@ -26,7 +25,7 @@ class AwsMfa
26
25
 
27
26
  private
28
27
 
29
- attr_reader :aws_config_file, :mydrive_credentials_cache_dir
28
+ attr_reader :mydrive_credentials_cache_dir
30
29
 
31
30
  def verify_aws_installed
32
31
  unless AwsMfa::ShellCommand.new("which aws").call.success?
@@ -34,13 +33,8 @@ class AwsMfa
34
33
  end
35
34
  end
36
35
 
37
- def find_aws_config_file
38
- aws_config_file = File.join(ENV['HOME'], ARN_CONFIG_FILE_PATH)
39
- unless File.readable?(aws_config_file)
40
- raise Errors::ConfigurationNotFound, 'Aws configuration not found. You must run `aws configure`'
41
- end
42
-
43
- aws_config_file
36
+ def verify_config_file
37
+ aws_config
44
38
  end
45
39
 
46
40
  def set_mydrive_credentials_cache_dir
@@ -50,7 +44,6 @@ class AwsMfa
50
44
  end
51
45
 
52
46
  def load_profile_config(profile)
53
- aws_config = Aws::IniParser.ini_parse(File.read(aws_config_file))
54
47
  if profile_config = aws_config[profile]
55
48
  AwsMfa::ProfileConfig.new(profile_config, profile)
56
49
  else
@@ -72,4 +65,8 @@ class AwsMfa
72
65
  def expiration_buffer_minutes
73
66
  ENV.fetch("MYDRIVE_MFA_TOKEN_EXPIRATION_BUFFER", 0).to_i
74
67
  end
68
+
69
+ def aws_config
70
+ @aws_config ||= ConfigLoader.build.load
71
+ end
75
72
  end
@@ -0,0 +1,32 @@
1
+ require "inifile"
2
+ require_relative "errors"
3
+
4
+ class ConfigLoader
5
+ ARN_CONFIG_FILE_PATH = ".aws/config".freeze
6
+
7
+ def self.build
8
+ config_file = File.join(ENV["HOME"], ARN_CONFIG_FILE_PATH)
9
+
10
+ raise AwsMfa::Errors::ConfigurationNotFound, "Configuration not found." unless File.readable?(config_file)
11
+
12
+ new(config_file)
13
+ end
14
+
15
+ def initialize(config_file)
16
+ @config_file = config_file
17
+ end
18
+
19
+ def load
20
+ config = IniFile.load(@config_file).to_h
21
+ config.each_with_object({}) do |(key, value), acc|
22
+ key =
23
+ if key.start_with?("profile ")
24
+ key.gsub("profile ", "")
25
+ else
26
+ key
27
+ end
28
+
29
+ acc[key] = value
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mydrive-aws-mfa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MyDrive Solutions Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-28 00:00:00.000000000 Z
11
+ date: 2019-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: aws-sdk-core
14
+ name: inifile
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.44'
19
+ version: 3.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.44'
26
+ version: 3.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -63,6 +63,7 @@ files:
63
63
  - README.md
64
64
  - bin/mydrive-aws-mfa
65
65
  - lib/aws_mfa.rb
66
+ - lib/aws_mfa/config_loader.rb
66
67
  - lib/aws_mfa/credentials_loader.rb
67
68
  - lib/aws_mfa/credentials_output_executor.rb
68
69
  - lib/aws_mfa/errors.rb
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  requirements:
92
93
  - aws-cli
93
94
  rubyforge_project:
94
- rubygems_version: 2.6.14.3
95
+ rubygems_version: 2.7.6
95
96
  signing_key:
96
97
  specification_version: 4
97
98
  summary: Run AWS commands with MFA (MyDrive fork)