Class: Chef::Provisioning::AWSDriver::TaggingStrategy::S3
- Inherits:
-
Object
- Object
- Chef::Provisioning::AWSDriver::TaggingStrategy::S3
- Defined in:
- lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb
Instance Attribute Summary collapse
-
#bucket_name ⇒ Object
readonly
Returns the value of attribute bucket_name.
-
#desired_tags ⇒ Object
readonly
Returns the value of attribute desired_tags.
-
#s3_client ⇒ Object
readonly
Returns the value of attribute s3_client.
Instance Method Summary collapse
- #current_tags ⇒ Object
- #delete_tags(tag_keys) ⇒ Object
-
#initialize(s3_client, bucket_name, desired_tags) ⇒ S3
constructor
A new instance of S3.
- #set_tags(tags) ⇒ Object
Constructor Details
#initialize(s3_client, bucket_name, desired_tags) ⇒ S3
Returns a new instance of S3.
7 8 9 10 11 |
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb', line 7 def initialize(s3_client, bucket_name, ) @s3_client = s3_client @bucket_name = bucket_name @desired_tags = end |
Instance Attribute Details
#bucket_name ⇒ Object (readonly)
Returns the value of attribute bucket_name.
5 6 7 |
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb', line 5 def bucket_name @bucket_name end |
#desired_tags ⇒ Object (readonly)
Returns the value of attribute desired_tags.
5 6 7 |
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb', line 5 def @desired_tags end |
#s3_client ⇒ Object (readonly)
Returns the value of attribute s3_client.
5 6 7 |
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb', line 5 def s3_client @s3_client end |
Instance Method Details
#current_tags ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb', line 13 def # http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Client.html#get_bucket_tagging-instance_method resp = s3_client.get_bucket_tagging({ bucket: bucket_name }) Hash[resp.tag_set.map {|t| [t.key, t.value]}] rescue Aws::S3::Errors::NoSuchTagSet => e # Instead of returning nil or empty, AWS raises an error :) {} end |
#delete_tags(tag_keys) ⇒ Object
34 35 36 37 38 |
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb', line 34 def (tag_keys) # S3 doesn't have a client action for deleting individual tags, just ALL tags. But the # put_bucket_tagging method will set the tags to what is provided so we don't need to # worry about this end |
#set_tags(tags) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/s3.rb', line 24 def () # http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Client.html#put_bucket_tagging-instance_method s3_client.put_bucket_tagging({ bucket: bucket_name, tagging: { tag_set: .map {|k,v| {key: k, value: v} } } }) end |