Class: Chef::Provisioning::AWSDriver::TaggingStrategy::RDS

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rds_client, rds_object_arn, desired_tags) ⇒ RDS

Returns a new instance of RDS.



53
54
55
56
57
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb', line 53

def initialize(rds_client, rds_object_arn, desired_tags)
  @rds_client = rds_client
  @rds_object_arn = rds_object_arn
  @desired_tags = desired_tags
end

Instance Attribute Details

#desired_tagsObject (readonly)

Returns the value of attribute desired_tags.



51
52
53
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb', line 51

def desired_tags
  @desired_tags
end

#rds_clientObject (readonly)

Returns the value of attribute rds_client.



51
52
53
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb', line 51

def rds_client
  @rds_client
end

#rds_object_arnObject (readonly)

Returns the value of attribute rds_object_arn.



51
52
53
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb', line 51

def rds_object_arn
  @rds_object_arn
end

Instance Method Details

#current_tagsObject



59
60
61
62
63
64
65
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb', line 59

def current_tags
  # http://docs.aws.amazon.com/sdkforruby/api/Aws/RDS/Client.html#list_tags_for_resource-instance_method
  resp = rds_client.list_tags_for_resource({
    resource_name: rds_object_arn
  })
  Hash[resp.tag_list.map {|t| [t.key, t.value]}]
end

#delete_tags(tag_keys) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb', line 83

def delete_tags(tag_keys)
  # http://docs.aws.amazon.com/sdkforruby/api/Aws/RDS/Client.html#remove_tags_from_resource-instance_method
  rds_client.remove_tags_from_resource({
    resource_name: rds_object_arn,
    tag_keys: tag_keys
  })
end

#set_tags(tags) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/rds.rb', line 67

def set_tags(tags)
  # http://docs.aws.amazon.com/sdkforruby/api/Aws/RDS/Client.html#add_tags_to_resource-instance_method
  # Unlike EC2, RDS tags can have a nil value
  tags = tags.map {|k,v|
    if v.nil?
      {key: k}
    else
      {key: k, value: v}
    end
  }
  rds_client.add_tags_to_resource({
    resource_name: rds_object_arn,
    tags: tags
  })
end