Class: TerraspacePluginAws::Interfaces::Backend::Bucket::Tagging
- Inherits:
-
TerraspacePluginAws::Interfaces::Backend::Base
- Object
- TerraspacePluginAws::Interfaces::Backend::Base
- TerraspacePluginAws::Interfaces::Backend::Bucket::Tagging
- Defined in:
- lib/terraspace_plugin_aws/interfaces/backend/bucket/tagging.rb
Instance Method Summary collapse
- #existing_tagging ⇒ Object
-
#initialize(info) ⇒ Tagging
constructor
A new instance of Tagging.
- #tag ⇒ Object
-
#tagging ⇒ Object
Merges existing tag_set structure so always appends tags, wont remove tags.
Methods included from Logging
Methods included from Clients
#dynamodb, #s3, #secretsmanager, #ssm, #sts
Constructor Details
#initialize(info) ⇒ Tagging
Returns a new instance of Tagging.
3 4 5 6 |
# File 'lib/terraspace_plugin_aws/interfaces/backend/bucket/tagging.rb', line 3 def initialize(info) super @bucket = info['bucket'] end |
Instance Method Details
#existing_tagging ⇒ Object
36 37 38 39 40 |
# File 'lib/terraspace_plugin_aws/interfaces/backend/bucket/tagging.rb', line 36 def existing_tagging s3.get_bucket_tagging(bucket: @bucket).to_h rescue Aws::S3::Errors::NoSuchTagSet {tag_set: []} # normalize return structure end |
#tag ⇒ Object
8 9 10 11 |
# File 'lib/terraspace_plugin_aws/interfaces/backend/bucket/tagging.rb', line 8 def tag return if tagging.nil? || tagging[:tag_set].empty? # safeguard: dont overwrite current tags s3.put_bucket_tagging(bucket: @bucket, tagging: tagging) end |
#tagging ⇒ Object
Merges existing tag_set structure so always appends tags, wont remove tags. This behavior is consistent with the dynamodb tagging.
Example return:
{
tag_set: [
{ key: "Key1", value: "Value1" },
{ key: "Key2", value: "Value2" },
],
}
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/terraspace_plugin_aws/interfaces/backend/bucket/tagging.rb', line 25 def tagging c = TerraspacePluginAws::Interfaces::Config.instance.config = !c.s3..empty? ? c.s3. : c. tag_set = .map do |k,v| {key: k.to_s, value: v} end return if tag_set == existing_tagging[:tag_set] # return nil so we can avoid the put_bucket_tagging call tag_set += existing_tagging[:tag_set] { tag_set: tag_set } end |