chef-provisioning-aws 3.0.4 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +16 -5
  3. data/Rakefile +15 -6
  4. data/chef-provisioning-aws.gemspec +17 -17
  5. data/lib/chef/provider/aws_auto_scaling_group.rb +5 -6
  6. data/lib/chef/provider/aws_cache_cluster.rb +21 -15
  7. data/lib/chef/provider/aws_cache_replication_group.rb +12 -8
  8. data/lib/chef/provider/aws_cache_subnet_group.rb +3 -3
  9. data/lib/chef/provider/aws_cloudsearch_domain.rb +9 -13
  10. data/lib/chef/provider/aws_cloudwatch_alarm.rb +10 -12
  11. data/lib/chef/provider/aws_dhcp_options.rb +18 -21
  12. data/lib/chef/provider/aws_ebs_volume.rb +24 -26
  13. data/lib/chef/provider/aws_eip_address.rb +10 -13
  14. data/lib/chef/provider/aws_elasticsearch_domain.rb +19 -18
  15. data/lib/chef/provider/aws_iam_instance_profile.rb +5 -7
  16. data/lib/chef/provider/aws_iam_role.rb +14 -17
  17. data/lib/chef/provider/aws_image.rb +6 -6
  18. data/lib/chef/provider/aws_instance.rb +5 -5
  19. data/lib/chef/provider/aws_internet_gateway.rb +8 -11
  20. data/lib/chef/provider/aws_key_pair.rb +15 -17
  21. data/lib/chef/provider/aws_launch_configuration.rb +11 -14
  22. data/lib/chef/provider/aws_load_balancer.rb +1 -2
  23. data/lib/chef/provider/aws_nat_gateway.rb +6 -7
  24. data/lib/chef/provider/aws_network_acl.rb +28 -29
  25. data/lib/chef/provider/aws_network_interface.rb +25 -27
  26. data/lib/chef/provider/aws_rds_instance.rb +12 -13
  27. data/lib/chef/provider/aws_rds_parameter_group.rb +8 -8
  28. data/lib/chef/provider/aws_rds_subnet_group.rb +8 -9
  29. data/lib/chef/provider/aws_route_table.rb +19 -20
  30. data/lib/chef/provider/aws_s3_bucket.rb +22 -25
  31. data/lib/chef/provider/aws_security_group.rb +268 -285
  32. data/lib/chef/provider/aws_server_certificate.rb +6 -5
  33. data/lib/chef/provider/aws_sns_topic.rb +4 -6
  34. data/lib/chef/provider/aws_sqs_queue.rb +3 -4
  35. data/lib/chef/provider/aws_subnet.rb +29 -34
  36. data/lib/chef/provider/aws_vpc.rb +108 -116
  37. data/lib/chef/provider/aws_vpc_peering_connection.rb +11 -11
  38. data/lib/chef/provisioning/aws_driver.rb +4 -2
  39. data/lib/chef/provisioning/aws_driver/aws_provider.rb +234 -241
  40. data/lib/chef/provisioning/aws_driver/aws_rds_resource.rb +5 -7
  41. data/lib/chef/provisioning/aws_driver/aws_resource.rb +182 -185
  42. data/lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb +17 -17
  43. data/lib/chef/provisioning/aws_driver/aws_taggable.rb +13 -15
  44. data/lib/chef/provisioning/aws_driver/aws_tagger.rb +47 -48
  45. data/lib/chef/provisioning/aws_driver/credentials.rb +96 -100
  46. data/lib/chef/provisioning/aws_driver/credentials2.rb +42 -45
  47. data/lib/chef/provisioning/aws_driver/driver.rb +1349 -1362
  48. data/lib/chef/provisioning/aws_driver/exceptions.rb +10 -12
  49. data/lib/chef/provisioning/aws_driver/super_lwrp.rb +60 -60
  50. data/lib/chef/provisioning/aws_driver/tagging_strategy/auto_scaling.rb +49 -50
  51. data/lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb +37 -38
  52. data/lib/chef/provisioning/aws_driver/tagging_strategy/elasticsearch.rb +14 -15
  53. data/lib/chef/provisioning/aws_driver/tagging_strategy/elb.rb +29 -31
  54. data/lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb +39 -40
  55. data/lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb +41 -43
  56. data/lib/chef/provisioning/aws_driver/version.rb +5 -5
  57. data/lib/chef/provisioning/driver_init/aws.rb +2 -2
  58. data/lib/chef/resource/aws_auto_scaling_group.rb +1 -1
  59. data/lib/chef/resource/aws_cache_cluster.rb +9 -12
  60. data/lib/chef/resource/aws_cache_replication_group.rb +9 -11
  61. data/lib/chef/resource/aws_cache_subnet_group.rb +8 -10
  62. data/lib/chef/resource/aws_cloudsearch_domain.rb +4 -5
  63. data/lib/chef/resource/aws_cloudwatch_alarm.rb +17 -18
  64. data/lib/chef/resource/aws_dhcp_options.rb +2 -2
  65. data/lib/chef/resource/aws_ebs_volume.rb +10 -10
  66. data/lib/chef/resource/aws_eip_address.rb +5 -5
  67. data/lib/chef/resource/aws_elasticsearch_domain.rb +4 -4
  68. data/lib/chef/resource/aws_iam_instance_profile.rb +4 -5
  69. data/lib/chef/resource/aws_iam_role.rb +2 -3
  70. data/lib/chef/resource/aws_image.rb +3 -3
  71. data/lib/chef/resource/aws_instance.rb +4 -4
  72. data/lib/chef/resource/aws_internet_gateway.rb +3 -3
  73. data/lib/chef/resource/aws_key_pair.rb +7 -7
  74. data/lib/chef/resource/aws_launch_configuration.rb +4 -4
  75. data/lib/chef/resource/aws_load_balancer.rb +7 -7
  76. data/lib/chef/resource/aws_nat_gateway.rb +11 -11
  77. data/lib/chef/resource/aws_network_acl.rb +7 -8
  78. data/lib/chef/resource/aws_network_interface.rb +9 -9
  79. data/lib/chef/resource/aws_rds_instance.rb +4 -4
  80. data/lib/chef/resource/aws_rds_parameter_group.rb +3 -3
  81. data/lib/chef/resource/aws_rds_subnet_group.rb +4 -4
  82. data/lib/chef/resource/aws_route53_hosted_zone.rb +37 -40
  83. data/lib/chef/resource/aws_route53_record_set.rb +22 -24
  84. data/lib/chef/resource/aws_route_table.rb +7 -7
  85. data/lib/chef/resource/aws_s3_bucket.rb +7 -7
  86. data/lib/chef/resource/aws_security_group.rb +10 -10
  87. data/lib/chef/resource/aws_server_certificate.rb +6 -8
  88. data/lib/chef/resource/aws_sns_topic.rb +2 -2
  89. data/lib/chef/resource/aws_sqs_queue.rb +5 -7
  90. data/lib/chef/resource/aws_subnet.rb +9 -9
  91. data/lib/chef/resource/aws_vpc.rb +11 -11
  92. data/lib/chef/resource/aws_vpc_peering_connection.rb +4 -4
  93. data/spec/aws_support.rb +44 -45
  94. data/spec/aws_support/aws_resource_run_wrapper.rb +2 -2
  95. data/spec/aws_support/deep_matcher.rb +2 -3
  96. data/spec/aws_support/deep_matcher/fuzzy_match_objects.rb +6 -9
  97. data/spec/aws_support/deep_matcher/match_values_failure_messages.rb +30 -37
  98. data/spec/aws_support/deep_matcher/matchable_array.rb +0 -1
  99. data/spec/aws_support/deep_matcher/matchable_object.rb +1 -2
  100. data/spec/aws_support/deep_matcher/rspec_monkeypatches.rb +4 -4
  101. data/spec/aws_support/delayed_stream.rb +2 -2
  102. data/spec/aws_support/matchers/create_an_aws_object.rb +6 -6
  103. data/spec/aws_support/matchers/destroy_an_aws_object.rb +6 -6
  104. data/spec/aws_support/matchers/have_aws_object_tags.rb +4 -5
  105. data/spec/aws_support/matchers/match_an_aws_object.rb +5 -6
  106. data/spec/aws_support/matchers/update_an_aws_object.rb +6 -7
  107. data/spec/integration/aws_auto_scaling_group_spec.rb +56 -64
  108. data/spec/integration/aws_cache_cluster_spec.rb +70 -71
  109. data/spec/integration/aws_cache_subnet_group_spec.rb +13 -14
  110. data/spec/integration/aws_cloudsearch_domain_spec.rb +6 -8
  111. data/spec/integration/aws_cloudwatch_alarm_spec.rb +200 -208
  112. data/spec/integration/aws_dhcp_options_spec.rb +32 -43
  113. data/spec/integration/aws_ebs_volume_spec.rb +52 -73
  114. data/spec/integration/aws_eip_address_spec.rb +24 -31
  115. data/spec/integration/aws_elasticsearch_domain_spec.rb +31 -33
  116. data/spec/integration/aws_iam_instance_profile_spec.rb +36 -45
  117. data/spec/integration/aws_iam_role_spec.rb +39 -46
  118. data/spec/integration/aws_internet_gateway_spec.rb +64 -75
  119. data/spec/integration/aws_key_pair_spec.rb +6 -6
  120. data/spec/integration/aws_launch_configuration_spec.rb +17 -18
  121. data/spec/integration/aws_nat_gateway_spec.rb +21 -24
  122. data/spec/integration/aws_network_acl_spec.rb +81 -95
  123. data/spec/integration/aws_network_interface_spec.rb +28 -43
  124. data/spec/integration/aws_rds_instance_spec.rb +29 -40
  125. data/spec/integration/aws_rds_parameter_group_spec.rb +32 -35
  126. data/spec/integration/aws_rds_subnet_group_spec.rb +30 -40
  127. data/spec/integration/aws_route53_hosted_zone_spec.rb +205 -205
  128. data/spec/integration/aws_route_table_spec.rb +118 -136
  129. data/spec/integration/aws_s3_bucket_spec.rb +19 -27
  130. data/spec/integration/aws_security_group_spec.rb +369 -388
  131. data/spec/integration/aws_server_certificate_spec.rb +16 -18
  132. data/spec/integration/aws_subnet_spec.rb +44 -58
  133. data/spec/integration/aws_vpc_peering_connection_spec.rb +43 -50
  134. data/spec/integration/aws_vpc_spec.rb +99 -115
  135. data/spec/integration/load_balancer_spec.rb +169 -183
  136. data/spec/integration/machine_batch_spec.rb +24 -31
  137. data/spec/integration/machine_image_spec.rb +54 -66
  138. data/spec/integration/machine_spec.rb +216 -237
  139. data/spec/persistence_file.txt +219 -0
  140. data/spec/spec_helper.rb +16 -17
  141. data/spec/unit/chef/provisioning/aws_driver/credentials_spec.rb +67 -74
  142. data/spec/unit/chef/provisioning/aws_driver/driver_spec.rb +29 -29
  143. data/spec/unit/chef/provisioning/aws_driver/route53_spec.rb +13 -15
  144. metadata +4 -3
@@ -1,18 +1,16 @@
1
1
  module Chef::Provisioning::AWSDriver
2
- # This module is meant to be included in a resource that is taggable
3
- # This will add the appropriate attribute that can be converged by the provider
4
- # TODO it would be nice to not have two seperate modules (taggable/tagger)
5
- # and just have the provider decorate the resource or vice versa. Complicated
6
- # by resources <-> providers being many-to-many.
7
- module AWSTaggable
8
-
9
- def self.included(klass)
10
- # This should be a hash of tags to apply to the AWS object
11
- #
12
- # @param aws_tags [Hash] Should be a hash of keys & values to add. Keys and values
13
- # can be provided as symbols or strings, but will be stored in AWS as strings.
14
- klass.attribute :aws_tags, kind_of: Hash
2
+ # This module is meant to be included in a resource that is taggable
3
+ # This will add the appropriate attribute that can be converged by the provider
4
+ # TODO it would be nice to not have two seperate modules (taggable/tagger)
5
+ # and just have the provider decorate the resource or vice versa. Complicated
6
+ # by resources <-> providers being many-to-many.
7
+ module AWSTaggable
8
+ def self.included(klass)
9
+ # This should be a hash of tags to apply to the AWS object
10
+ #
11
+ # @param aws_tags [Hash] Should be a hash of keys & values to add. Keys and values
12
+ # can be provided as symbols or strings, but will be stored in AWS as strings.
13
+ klass.attribute :aws_tags, kind_of: Hash
14
+ end
15
15
  end
16
-
17
- end
18
16
  end
@@ -1,61 +1,60 @@
1
- require 'retryable'
1
+ require "retryable"
2
2
 
3
3
  module Chef::Provisioning::AWSDriver
4
- # Include this module on a class or instance that is responsible for tagging
5
- # itself. Fill in the hook methods so it knows how to tag itself.
6
- class AWSTagger
7
- extend Forwardable
4
+ # Include this module on a class or instance that is responsible for tagging
5
+ # itself. Fill in the hook methods so it knows how to tag itself.
6
+ class AWSTagger
7
+ extend Forwardable
8
8
 
9
- attr_reader :action_handler
9
+ attr_reader :action_handler
10
10
 
11
- def initialize(tagging_strategy, action_handler)
12
- @tagging_strategy = tagging_strategy
13
- @action_handler = action_handler
14
- end
15
-
16
- def_delegators :@tagging_strategy, :desired_tags, :current_tags, :set_tags, :delete_tags
17
-
18
- def converge_tags
19
- if desired_tags.nil?
20
- Chef::Log.debug "aws_tags not provided, nothing to converge"
21
- return
11
+ def initialize(tagging_strategy, action_handler)
12
+ @tagging_strategy = tagging_strategy
13
+ @action_handler = action_handler
22
14
  end
23
15
 
24
- # Duplication and normalization
25
- # ::Aws::EC2::Errors::InvalidParameterValue: Tag value cannot be null. Use empty string instead.
26
- n_desired_tags = Hash[desired_tags.map {|k,v| [k.to_s, v.to_s]}]
27
- n_current_tags = Hash[current_tags.map {|k,v| [k.to_s, v.to_s]}]
28
-
29
- tags_to_set = n_desired_tags.reject {|k,v| n_current_tags[k] && n_current_tags[k] == v}
30
- tags_to_delete = n_current_tags.keys - n_desired_tags.keys
31
- # We don't want to delete `Name`, just all other tags
32
- # Tag keys and values are case sensitive - `Name` is special because it
33
- # shows as the name in the console
34
- tags_to_delete.delete('Name')
35
-
36
- # Tagging frequently fails so we retry with an exponential backoff, a maximum of 10 seconds
37
- Retryable.retryable(
38
- :tries => 20,
39
- :sleep => lambda { |n| [2**n, 10].min },
40
- :on => [::Aws::EC2::Errors, Aws::S3::Errors, ::Aws::S3::Errors::ServiceError,]
41
- ) do |retries, exception|
42
- if retries > 0
43
- Chef::Log.info "Retrying the tagging, previous try failed with #{exception.inspect}"
16
+ def_delegators :@tagging_strategy, :desired_tags, :current_tags, :set_tags, :delete_tags
17
+
18
+ def converge_tags
19
+ if desired_tags.nil?
20
+ Chef::Log.debug "aws_tags not provided, nothing to converge"
21
+ return
44
22
  end
45
- unless tags_to_set.empty?
46
- action_handler.perform_action "creating tags #{tags_to_set}" do
47
- set_tags(tags_to_set)
23
+
24
+ # Duplication and normalization
25
+ # ::Aws::EC2::Errors::InvalidParameterValue: Tag value cannot be null. Use empty string instead.
26
+ n_desired_tags = Hash[desired_tags.map { |k, v| [k.to_s, v.to_s] }]
27
+ n_current_tags = Hash[current_tags.map { |k, v| [k.to_s, v.to_s] }]
28
+
29
+ tags_to_set = n_desired_tags.reject { |k, v| n_current_tags[k] && n_current_tags[k] == v }
30
+ tags_to_delete = n_current_tags.keys - n_desired_tags.keys
31
+ # We don't want to delete `Name`, just all other tags
32
+ # Tag keys and values are case sensitive - `Name` is special because it
33
+ # shows as the name in the console
34
+ tags_to_delete.delete("Name")
35
+
36
+ # Tagging frequently fails so we retry with an exponential backoff, a maximum of 10 seconds
37
+ Retryable.retryable(
38
+ tries: 20,
39
+ sleep: ->(n) { [2**n, 10].min },
40
+ on: [::Aws::EC2::Errors, Aws::S3::Errors, ::Aws::S3::Errors::ServiceError]
41
+ ) do |retries, exception|
42
+ if retries > 0
43
+ Chef::Log.info "Retrying the tagging, previous try failed with #{exception.inspect}"
48
44
  end
49
- tags_to_set = []
50
- end
51
- unless tags_to_delete.empty?
52
- action_handler.perform_action "deleting tags #{tags_to_delete}" do
53
- delete_tags(tags_to_delete)
45
+ unless tags_to_set.empty?
46
+ action_handler.perform_action "creating tags #{tags_to_set}" do
47
+ set_tags(tags_to_set)
48
+ end
49
+ tags_to_set = []
50
+ end
51
+ unless tags_to_delete.empty?
52
+ action_handler.perform_action "deleting tags #{tags_to_delete}" do
53
+ delete_tags(tags_to_delete)
54
+ end
55
+ tags_to_delete = []
54
56
  end
55
- tags_to_delete = []
56
57
  end
57
58
  end
58
59
  end
59
-
60
- end
61
60
  end
@@ -1,124 +1,120 @@
1
- require 'inifile'
2
- require 'csv'
3
- require 'chef/mixin/deep_merge'
1
+ require "inifile"
2
+ require "csv"
3
+ require "chef/mixin/deep_merge"
4
4
 
5
5
  class Chef
6
- module Provisioning
7
- module AWSDriver
8
- # Reads in credential files in Amazon's download format and presents the credentials to you
9
- class Credentials
10
- def initialize
11
- @credentials = {}
12
- load_default
13
- end
6
+ module Provisioning
7
+ module AWSDriver
8
+ # Reads in credential files in Amazon's download format and presents the credentials to you
9
+ class Credentials
10
+ def initialize
11
+ @credentials = {}
12
+ load_default
13
+ end
14
14
 
15
- include Enumerable
16
- include Chef::Mixin::DeepMerge
15
+ include Enumerable
16
+ include Chef::Mixin::DeepMerge
17
17
 
18
- def default
19
- if @credentials.size == 0
20
- raise 'No credentials loaded! Do you have a ~/.aws/config?'
21
- end
22
- @credentials[ENV['AWS_DEFAULT_PROFILE'] || 'default'] || @credentials.first[1]
23
- end
18
+ def default
19
+ if @credentials.empty?
20
+ raise "No credentials loaded! Do you have a ~/.aws/config?"
21
+ end
22
+ @credentials[ENV["AWS_DEFAULT_PROFILE"] || "default"] || @credentials.first[1]
23
+ end
24
24
 
25
- def keys
26
- @credentials.keys
27
- end
25
+ def keys
26
+ @credentials.keys
27
+ end
28
28
 
29
- def [](name)
30
- @credentials[name]
31
- end
29
+ def [](name)
30
+ @credentials[name]
31
+ end
32
32
 
33
- def each(&block)
34
- @credentials.each(&block)
35
- end
33
+ def each(&block)
34
+ @credentials.each(&block)
35
+ end
36
36
 
37
- def load_inis(config_ini_file, credentials_ini_file = nil)
38
- @credentials = load_config_ini(config_ini_file)
39
- @credentials = deep_merge!(@credentials,
40
- load_credentials_ini(credentials_ini_file)
41
- ) if credentials_ini_file
42
- end
37
+ def load_inis(config_ini_file, credentials_ini_file = nil)
38
+ @credentials = load_config_ini(config_ini_file)
39
+ if credentials_ini_file
40
+ @credentials = deep_merge!(@credentials,
41
+ load_credentials_ini(credentials_ini_file))
42
+ end
43
+ end
43
44
 
44
- def load_config_ini(config_ini_file)
45
- inifile = IniFile.load(File.expand_path(config_ini_file))
46
- config = {}
47
- if inifile
48
- inifile.each_section do |section|
49
- if section =~ /^\s*profile\s+(.+)$/ || section =~ /^\s*(default)\s*/
50
- profile_name = $1.strip
51
- profile = inifile[section].inject({}) do |result, pair|
52
- result[pair[0].to_sym] = pair[1]
53
- result
45
+ def load_config_ini(config_ini_file)
46
+ inifile = IniFile.load(File.expand_path(config_ini_file))
47
+ config = {}
48
+ if inifile
49
+ inifile.each_section do |section|
50
+ next unless section =~ /^\s*profile\s+(.+)$/ || section =~ /^\s*(default)\s*/
51
+ profile_name = Regexp.last_match(1).strip
52
+ profile = inifile[section].each_with_object({}) do |pair, result|
53
+ result[pair[0].to_sym] = pair[1]
54
+ end
55
+ profile[:name] = profile_name
56
+ config[profile_name] = profile
54
57
  end
55
- profile[:name] = profile_name
56
- config[profile_name] = profile
57
58
  end
59
+ config
58
60
  end
59
- end
60
- config
61
- end
62
61
 
63
- def load_credentials_ini(credentials_ini_file)
64
- inifile = IniFile.load(File.expand_path(credentials_ini_file))
65
- config = {}
66
- if inifile
67
- inifile.each_section do |section|
68
- profile = inifile[section].inject({}) do |result, pair|
69
- result[pair[0].to_sym] = pair[1]
70
- result
62
+ def load_credentials_ini(credentials_ini_file)
63
+ inifile = IniFile.load(File.expand_path(credentials_ini_file))
64
+ config = {}
65
+ if inifile
66
+ inifile.each_section do |section|
67
+ profile = inifile[section].each_with_object({}) do |pair, result|
68
+ result[pair[0].to_sym] = pair[1]
69
+ end
70
+ profile[:name] = section
71
+ config[section] = profile
72
+ end
71
73
  end
72
- profile[:name] = section
73
- config[section] = profile
74
+ config
74
75
  end
75
- end
76
- config
77
- end
78
76
 
79
- def load_csv(credentials_csv_file)
80
- CSV.new(File.open(credentials_csv_file), :headers => :first_row).each do |row|
81
- @credentials[row['User Name']] = {
82
- :name => row['User Name'],
83
- :user_name => row['User Name'],
84
- :aws_access_key_id => row['Access Key Id'],
85
- :aws_secret_access_key => row['Secret Access Key']
86
- }
87
- end
88
- end
77
+ def load_csv(credentials_csv_file)
78
+ CSV.new(File.open(credentials_csv_file), headers: :first_row).each do |row|
79
+ @credentials[row["User Name"]] = {
80
+ name: row["User Name"],
81
+ user_name: row["User Name"],
82
+ aws_access_key_id: row["Access Key Id"],
83
+ aws_secret_access_key: row["Secret Access Key"]
84
+ }
85
+ end
86
+ end
89
87
 
90
- def load_env_variables
91
- if ENV["AWS_ACCESS_KEY_ID"] && ENV["AWS_SECRET_ACCESS_KEY"]
92
- @credentials["default"] = {
93
- aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
94
- aws_secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"]
95
- }
96
- end
97
- end
88
+ def load_env_variables
89
+ if ENV["AWS_ACCESS_KEY_ID"] && ENV["AWS_SECRET_ACCESS_KEY"]
90
+ @credentials["default"] = {
91
+ aws_access_key_id: ENV["AWS_ACCESS_KEY_ID"],
92
+ aws_secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"]
93
+ }
94
+ end
95
+ end
98
96
 
99
- def load_default
100
- config_file = ENV['AWS_CONFIG_FILE'] || File.expand_path('~/.aws/config')
101
- credentials_file = ENV['AWS_SHARED_CREDENTIALS_FILE'] || ENV['AWS_CREDENTIAL_FILE'] || File.expand_path('~/.aws/credentials')
102
- if File.file?(config_file)
103
- if File.file?(credentials_file)
104
- load_inis(config_file, credentials_file)
105
- else
106
- load_inis(config_file)
97
+ def load_default
98
+ config_file = ENV["AWS_CONFIG_FILE"] || File.expand_path("~/.aws/config")
99
+ credentials_file = ENV["AWS_SHARED_CREDENTIALS_FILE"] || ENV["AWS_CREDENTIAL_FILE"] || File.expand_path("~/.aws/credentials")
100
+ if File.file?(config_file)
101
+ if File.file?(credentials_file)
102
+ load_inis(config_file, credentials_file)
103
+ else
104
+ load_inis(config_file)
105
+ end
106
+ end
107
+ load_env_variables if @credentials.empty?
107
108
  end
108
- end
109
- if @credentials.size == 0
110
- load_env_variables
111
- end
112
- end
113
109
 
114
- def self.method_missing(name, *args, &block)
115
- singleton.send(name, *args, &block)
116
- end
110
+ def self.method_missing(name, *args, &block)
111
+ singleton.send(name, *args, &block)
112
+ end
117
113
 
118
- def self.singleton
119
- @aws_credentials ||= Credentials.new
114
+ def self.singleton
115
+ @aws_credentials ||= Credentials.new
116
+ end
117
+ end
120
118
  end
121
119
  end
122
120
  end
123
- end
124
- end
@@ -5,52 +5,49 @@ require "aws-sdk-core/instance_profile_credentials"
5
5
  require "aws-sdk-core/assume_role_credentials"
6
6
 
7
7
  class Chef
8
- module Provisioning
9
- module AWSDriver
10
-
11
- class LoadCredentialsError < RuntimeError; end
12
-
13
- # Loads the credentials for the AWS SDK V2
14
- # Attempts to load credentials in the order specified at http://docs.aws.amazon.com/sdkforruby/api/index.html#Configuration
15
- class Credentials2
16
-
17
- attr_reader :profile_name
18
-
19
- # @param [Hash] options
20
- # @option options [String] :profile_name (ENV["AWS_DEFAULT_PROFILE"]) The profile name to use
21
- # when loading the config from '~/.aws/credentials'. This can be nil.
22
- def initialize(options = {})
23
- @profile_name = options[:profile_name] || ENV["AWS_DEFAULT_PROFILE"]
24
- end
25
-
26
- # Try to load the credentials from an ordered list of sources and return the first one that
27
- # can be loaded successfully.
28
- def get_credentials
29
- # http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-environment
30
- credentials_file = ENV.fetch('AWS_SHARED_CREDENTIALS_FILE', ENV['AWS_CONFIG_FILE'])
31
- shared_creds = ::Aws::SharedCredentials.new(
32
- :profile_name => profile_name,
33
- :path => credentials_file
34
- )
35
- instance_profile_creds = ::Aws::InstanceProfileCredentials.new(:retries => 1)
36
-
37
- if ENV["AWS_ACCESS_KEY_ID"] && ENV["AWS_SECRET_ACCESS_KEY"]
38
- creds = ::Aws::Credentials.new(
39
- ENV["AWS_ACCESS_KEY_ID"],
40
- ENV["AWS_SECRET_ACCESS_KEY"],
41
- ENV["AWS_SESSION_TOKEN"]
42
- )
43
- elsif shared_creds.set?
44
- creds = shared_creds
45
- elsif instance_profile_creds.set?
46
- creds = instance_profile_creds
47
- else
48
- raise LoadCredentialsError.new("Could not load credentials from the environment variables, the .aws/credentials file or the metadata service")
8
+ module Provisioning
9
+ module AWSDriver
10
+ class LoadCredentialsError < RuntimeError; end
11
+
12
+ # Loads the credentials for the AWS SDK V2
13
+ # Attempts to load credentials in the order specified at http://docs.aws.amazon.com/sdkforruby/api/index.html#Configuration
14
+ class Credentials2
15
+ attr_reader :profile_name
16
+
17
+ # @param [Hash] options
18
+ # @option options [String] :profile_name (ENV["AWS_DEFAULT_PROFILE"]) The profile name to use
19
+ # when loading the config from '~/.aws/credentials'. This can be nil.
20
+ def initialize(options = {})
21
+ @profile_name = options[:profile_name] || ENV["AWS_DEFAULT_PROFILE"]
22
+ end
23
+
24
+ # Try to load the credentials from an ordered list of sources and return the first one that
25
+ # can be loaded successfully.
26
+ def get_credentials
27
+ # http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-environment
28
+ credentials_file = ENV.fetch("AWS_SHARED_CREDENTIALS_FILE", ENV["AWS_CONFIG_FILE"])
29
+ shared_creds = ::Aws::SharedCredentials.new(
30
+ profile_name: profile_name,
31
+ path: credentials_file
32
+ )
33
+ instance_profile_creds = ::Aws::InstanceProfileCredentials.new(retries: 1)
34
+
35
+ if ENV["AWS_ACCESS_KEY_ID"] && ENV["AWS_SECRET_ACCESS_KEY"]
36
+ creds = ::Aws::Credentials.new(
37
+ ENV["AWS_ACCESS_KEY_ID"],
38
+ ENV["AWS_SECRET_ACCESS_KEY"],
39
+ ENV["AWS_SESSION_TOKEN"]
40
+ )
41
+ elsif shared_creds.set?
42
+ creds = shared_creds
43
+ elsif instance_profile_creds.set?
44
+ creds = instance_profile_creds
45
+ else
46
+ raise LoadCredentialsError, "Could not load credentials from the environment variables, the .aws/credentials file or the metadata service"
47
+ end
48
+ creds
49
+ end
49
50
  end
50
- creds
51
51
  end
52
52
  end
53
-
54
- end
55
- end
56
53
  end