Class: Chef::Provisioning::AWSDriver::TaggingStrategy::Elasticsearch

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, arn, desired_tags) ⇒ Elasticsearch

Returns a new instance of Elasticsearch.



8
9
10
11
12
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/elasticsearch.rb', line 8

def initialize(client, arn, desired_tags)
  @client = client
  @arn = arn
  @desired_tags = desired_tags
end

Instance Attribute Details

#arnObject (readonly)

Returns the value of attribute arn.



6
7
8
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/elasticsearch.rb', line 6

def arn
  @arn
end

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/elasticsearch.rb', line 6

def client
  @client
end

#desired_tagsObject (readonly)

Returns the value of attribute desired_tags.



6
7
8
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/elasticsearch.rb', line 6

def desired_tags
  @desired_tags
end

Instance Method Details

#current_tagsObject



14
15
16
17
18
19
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/elasticsearch.rb', line 14

def current_tags
  resp = client.list_tags({arn: arn})
  Hash[resp.tag_list.map {|t| [t.key, t.value]}]
rescue ::Aws::ElasticsearchService::Errors::ResourceNotFoundException
  Hash.new
end

#delete_tags(tag_keys) ⇒ Object



35
36
37
38
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/elasticsearch.rb', line 35

def delete_tags(tag_keys)
  client.remove_tags({arn: arn,
                      tag_keys: tag_keys})
end

#set_tags(tags) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/elasticsearch.rb', line 21

def set_tags(tags)
  tags = tags.map {|k,v|
    if v.nil?
      {key: k}
    else
      {key: k, value: v}
    end
  }
  client.add_tags({
                    arn: arn,
                    tag_list: tags
                  })
end