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.
- checksums.yaml +4 -4
- data/Gemfile +16 -5
- data/Rakefile +15 -6
- data/chef-provisioning-aws.gemspec +17 -17
- data/lib/chef/provider/aws_auto_scaling_group.rb +5 -6
- data/lib/chef/provider/aws_cache_cluster.rb +21 -15
- data/lib/chef/provider/aws_cache_replication_group.rb +12 -8
- data/lib/chef/provider/aws_cache_subnet_group.rb +3 -3
- data/lib/chef/provider/aws_cloudsearch_domain.rb +9 -13
- data/lib/chef/provider/aws_cloudwatch_alarm.rb +10 -12
- data/lib/chef/provider/aws_dhcp_options.rb +18 -21
- data/lib/chef/provider/aws_ebs_volume.rb +24 -26
- data/lib/chef/provider/aws_eip_address.rb +10 -13
- data/lib/chef/provider/aws_elasticsearch_domain.rb +19 -18
- data/lib/chef/provider/aws_iam_instance_profile.rb +5 -7
- data/lib/chef/provider/aws_iam_role.rb +14 -17
- data/lib/chef/provider/aws_image.rb +6 -6
- data/lib/chef/provider/aws_instance.rb +5 -5
- data/lib/chef/provider/aws_internet_gateway.rb +8 -11
- data/lib/chef/provider/aws_key_pair.rb +15 -17
- data/lib/chef/provider/aws_launch_configuration.rb +11 -14
- data/lib/chef/provider/aws_load_balancer.rb +1 -2
- data/lib/chef/provider/aws_nat_gateway.rb +6 -7
- data/lib/chef/provider/aws_network_acl.rb +28 -29
- data/lib/chef/provider/aws_network_interface.rb +25 -27
- data/lib/chef/provider/aws_rds_instance.rb +12 -13
- data/lib/chef/provider/aws_rds_parameter_group.rb +8 -8
- data/lib/chef/provider/aws_rds_subnet_group.rb +8 -9
- data/lib/chef/provider/aws_route_table.rb +19 -20
- data/lib/chef/provider/aws_s3_bucket.rb +22 -25
- data/lib/chef/provider/aws_security_group.rb +268 -285
- data/lib/chef/provider/aws_server_certificate.rb +6 -5
- data/lib/chef/provider/aws_sns_topic.rb +4 -6
- data/lib/chef/provider/aws_sqs_queue.rb +3 -4
- data/lib/chef/provider/aws_subnet.rb +29 -34
- data/lib/chef/provider/aws_vpc.rb +108 -116
- data/lib/chef/provider/aws_vpc_peering_connection.rb +11 -11
- data/lib/chef/provisioning/aws_driver.rb +4 -2
- data/lib/chef/provisioning/aws_driver/aws_provider.rb +234 -241
- data/lib/chef/provisioning/aws_driver/aws_rds_resource.rb +5 -7
- data/lib/chef/provisioning/aws_driver/aws_resource.rb +182 -185
- data/lib/chef/provisioning/aws_driver/aws_resource_with_entry.rb +17 -17
- data/lib/chef/provisioning/aws_driver/aws_taggable.rb +13 -15
- data/lib/chef/provisioning/aws_driver/aws_tagger.rb +47 -48
- data/lib/chef/provisioning/aws_driver/credentials.rb +96 -100
- data/lib/chef/provisioning/aws_driver/credentials2.rb +42 -45
- data/lib/chef/provisioning/aws_driver/driver.rb +1349 -1362
- data/lib/chef/provisioning/aws_driver/exceptions.rb +10 -12
- data/lib/chef/provisioning/aws_driver/super_lwrp.rb +60 -60
- data/lib/chef/provisioning/aws_driver/tagging_strategy/auto_scaling.rb +49 -50
- data/lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb +37 -38
- data/lib/chef/provisioning/aws_driver/tagging_strategy/elasticsearch.rb +14 -15
- data/lib/chef/provisioning/aws_driver/tagging_strategy/elb.rb +29 -31
- data/lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb +39 -40
- data/lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb +41 -43
- data/lib/chef/provisioning/aws_driver/version.rb +5 -5
- data/lib/chef/provisioning/driver_init/aws.rb +2 -2
- data/lib/chef/resource/aws_auto_scaling_group.rb +1 -1
- data/lib/chef/resource/aws_cache_cluster.rb +9 -12
- data/lib/chef/resource/aws_cache_replication_group.rb +9 -11
- data/lib/chef/resource/aws_cache_subnet_group.rb +8 -10
- data/lib/chef/resource/aws_cloudsearch_domain.rb +4 -5
- data/lib/chef/resource/aws_cloudwatch_alarm.rb +17 -18
- data/lib/chef/resource/aws_dhcp_options.rb +2 -2
- data/lib/chef/resource/aws_ebs_volume.rb +10 -10
- data/lib/chef/resource/aws_eip_address.rb +5 -5
- data/lib/chef/resource/aws_elasticsearch_domain.rb +4 -4
- data/lib/chef/resource/aws_iam_instance_profile.rb +4 -5
- data/lib/chef/resource/aws_iam_role.rb +2 -3
- data/lib/chef/resource/aws_image.rb +3 -3
- data/lib/chef/resource/aws_instance.rb +4 -4
- data/lib/chef/resource/aws_internet_gateway.rb +3 -3
- data/lib/chef/resource/aws_key_pair.rb +7 -7
- data/lib/chef/resource/aws_launch_configuration.rb +4 -4
- data/lib/chef/resource/aws_load_balancer.rb +7 -7
- data/lib/chef/resource/aws_nat_gateway.rb +11 -11
- data/lib/chef/resource/aws_network_acl.rb +7 -8
- data/lib/chef/resource/aws_network_interface.rb +9 -9
- data/lib/chef/resource/aws_rds_instance.rb +4 -4
- data/lib/chef/resource/aws_rds_parameter_group.rb +3 -3
- data/lib/chef/resource/aws_rds_subnet_group.rb +4 -4
- data/lib/chef/resource/aws_route53_hosted_zone.rb +37 -40
- data/lib/chef/resource/aws_route53_record_set.rb +22 -24
- data/lib/chef/resource/aws_route_table.rb +7 -7
- data/lib/chef/resource/aws_s3_bucket.rb +7 -7
- data/lib/chef/resource/aws_security_group.rb +10 -10
- data/lib/chef/resource/aws_server_certificate.rb +6 -8
- data/lib/chef/resource/aws_sns_topic.rb +2 -2
- data/lib/chef/resource/aws_sqs_queue.rb +5 -7
- data/lib/chef/resource/aws_subnet.rb +9 -9
- data/lib/chef/resource/aws_vpc.rb +11 -11
- data/lib/chef/resource/aws_vpc_peering_connection.rb +4 -4
- data/spec/aws_support.rb +44 -45
- data/spec/aws_support/aws_resource_run_wrapper.rb +2 -2
- data/spec/aws_support/deep_matcher.rb +2 -3
- data/spec/aws_support/deep_matcher/fuzzy_match_objects.rb +6 -9
- data/spec/aws_support/deep_matcher/match_values_failure_messages.rb +30 -37
- data/spec/aws_support/deep_matcher/matchable_array.rb +0 -1
- data/spec/aws_support/deep_matcher/matchable_object.rb +1 -2
- data/spec/aws_support/deep_matcher/rspec_monkeypatches.rb +4 -4
- data/spec/aws_support/delayed_stream.rb +2 -2
- data/spec/aws_support/matchers/create_an_aws_object.rb +6 -6
- data/spec/aws_support/matchers/destroy_an_aws_object.rb +6 -6
- data/spec/aws_support/matchers/have_aws_object_tags.rb +4 -5
- data/spec/aws_support/matchers/match_an_aws_object.rb +5 -6
- data/spec/aws_support/matchers/update_an_aws_object.rb +6 -7
- data/spec/integration/aws_auto_scaling_group_spec.rb +56 -64
- data/spec/integration/aws_cache_cluster_spec.rb +70 -71
- data/spec/integration/aws_cache_subnet_group_spec.rb +13 -14
- data/spec/integration/aws_cloudsearch_domain_spec.rb +6 -8
- data/spec/integration/aws_cloudwatch_alarm_spec.rb +200 -208
- data/spec/integration/aws_dhcp_options_spec.rb +32 -43
- data/spec/integration/aws_ebs_volume_spec.rb +52 -73
- data/spec/integration/aws_eip_address_spec.rb +24 -31
- data/spec/integration/aws_elasticsearch_domain_spec.rb +31 -33
- data/spec/integration/aws_iam_instance_profile_spec.rb +36 -45
- data/spec/integration/aws_iam_role_spec.rb +39 -46
- data/spec/integration/aws_internet_gateway_spec.rb +64 -75
- data/spec/integration/aws_key_pair_spec.rb +6 -6
- data/spec/integration/aws_launch_configuration_spec.rb +17 -18
- data/spec/integration/aws_nat_gateway_spec.rb +21 -24
- data/spec/integration/aws_network_acl_spec.rb +81 -95
- data/spec/integration/aws_network_interface_spec.rb +28 -43
- data/spec/integration/aws_rds_instance_spec.rb +29 -40
- data/spec/integration/aws_rds_parameter_group_spec.rb +32 -35
- data/spec/integration/aws_rds_subnet_group_spec.rb +30 -40
- data/spec/integration/aws_route53_hosted_zone_spec.rb +205 -205
- data/spec/integration/aws_route_table_spec.rb +118 -136
- data/spec/integration/aws_s3_bucket_spec.rb +19 -27
- data/spec/integration/aws_security_group_spec.rb +369 -388
- data/spec/integration/aws_server_certificate_spec.rb +16 -18
- data/spec/integration/aws_subnet_spec.rb +44 -58
- data/spec/integration/aws_vpc_peering_connection_spec.rb +43 -50
- data/spec/integration/aws_vpc_spec.rb +99 -115
- data/spec/integration/load_balancer_spec.rb +169 -183
- data/spec/integration/machine_batch_spec.rb +24 -31
- data/spec/integration/machine_image_spec.rb +54 -66
- data/spec/integration/machine_spec.rb +216 -237
- data/spec/persistence_file.txt +219 -0
- data/spec/spec_helper.rb +16 -17
- data/spec/unit/chef/provisioning/aws_driver/credentials_spec.rb +67 -74
- data/spec/unit/chef/provisioning/aws_driver/driver_spec.rb +29 -29
- data/spec/unit/chef/provisioning/aws_driver/route53_spec.rb +13 -15
- 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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
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
|
-
|
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
|
-
|
9
|
+
attr_reader :action_handler
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
2
|
-
require
|
3
|
-
require
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
16
|
-
|
15
|
+
include Enumerable
|
16
|
+
include Chef::Mixin::DeepMerge
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
25
|
+
def keys
|
26
|
+
@credentials.keys
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
def [](name)
|
30
|
+
@credentials[name]
|
31
|
+
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
def each(&block)
|
34
|
+
@credentials.each(&block)
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
73
|
-
config[section] = profile
|
74
|
+
config
|
74
75
|
end
|
75
|
-
end
|
76
|
-
config
|
77
|
-
end
|
78
76
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
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
|
-
|
115
|
-
|
116
|
-
|
110
|
+
def self.method_missing(name, *args, &block)
|
111
|
+
singleton.send(name, *args, &block)
|
112
|
+
end
|
117
113
|
|
118
|
-
|
119
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|