tagenv 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fbe06e6524e376cdabf53995fa2000c09cb098b
4
- data.tar.gz: 22e34eb3396dfdcdfd82f0c3ae4a562467eb1fb6
3
+ metadata.gz: 8046a15f8a4b53a188d8826ed47bfc5024623c53
4
+ data.tar.gz: f05be3aa35a9f2e607140886173724a38ca2b043
5
5
  SHA512:
6
- metadata.gz: 3af61d352254dfd83dec9ccb877e68971bbcd461e0b90378fae8b5567075d0b59600562ad0b882d67a597d41d7764f6350d1701d03137fb988fce59f3ee39189
7
- data.tar.gz: c67d6403dd729c610523d8da213486c8363f76fccaf1b02021dd766a11e2b01cf78fe301d03819aa301957954b284cd3464b13aad730b6f0c39971d7a8dade11
6
+ metadata.gz: 7cf95dcf7b8c8f317a35c09fd80d2a289ee15004a81bdf8e9b243b333493471e801c35ca655b22acd071a1c15d76315fdf510cef15e58b24b9863ccb11eea9c9
7
+ data.tar.gz: 1e3be10e4e492334563f6601a21af8148e4cbd77b48174fa4bb805a95033afe6c93be1ed209436b183dcc3e708ab147b532f7d29c28f1c7d011cf3ab9034285a
@@ -4,24 +4,26 @@ require_relative 'tag_util'
4
4
  module Tagenv
5
5
  module Ec2
6
6
  class Tag
7
- def initialize
7
+ def initialize(prefix: '', instance_id: nil)
8
8
  @logger = Logger.new(STDOUT)
9
9
  region = ENV['AWS_REGION'] || Metadata.get_document['region']
10
10
  @ec2 = Aws::EC2::Client.new(region: region)
11
+ @prefix = prefix
12
+ @instance_id = instance_id
11
13
  end
12
14
 
13
- def get_tag_hash(instance_id: nil)
14
- instance_id = instance_id || Metadata.get_instance_id
15
- instances_tag_with_id(instance_id)
15
+ def get_tag_hash
16
+ instances_tag_with_id
16
17
  end
17
18
 
18
19
  private
19
20
 
20
- def instances_tag_with_id(instance_id)
21
+ def instances_tag_with_id
22
+ @instance_id = @instance_id || Metadata.get_instance_id
21
23
  tags = @ec2.describe_instances(
22
- instance_ids: [instance_id]
24
+ instance_ids: [@instance_id]
23
25
  ).data.to_h[:reservations].map { |instance| instance[:instances].first }.first[:tags]
24
- TagUtil.convert_tag_hash(tags)
26
+ TagUtil.convert_tag_hash(@prefix, tags)
25
27
  end
26
28
  end
27
29
  end
@@ -3,10 +3,10 @@ require 'aws-sdk'
3
3
  module Tagenv
4
4
  module Ec2
5
5
  class TagUtil
6
- def self.convert_tag_hash(tags)
6
+ def self.convert_tag_hash(prefix, tags)
7
7
  result = {}
8
8
  tags.each {|hash|
9
- result[hash['key'] || hash[:key]] = hash['value'] || hash[:value]
9
+ result[prefix + (hash['key'] || hash[:key])] = hash['value'] || hash[:value]
10
10
  }
11
11
  result
12
12
  end
@@ -1,4 +1,4 @@
1
1
  module Tagenv
2
2
  # tagenv version
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
  end
data/lib/tagenv.rb CHANGED
@@ -8,7 +8,7 @@ module Tagenv
8
8
  def self.load(prefix: '', instance_id: nil, provider: 'ec2')
9
9
  tag_hash = {}
10
10
  if provider == 'ec2'
11
- @ec2_tag = Ec2::Tag.new
11
+ @ec2_tag = Ec2::Tag.new(prefix: prefix, instance_id: instance_id)
12
12
  tag_hash = @ec2_tag.get_tag_hash(instance_id)
13
13
  else
14
14
  raise "Unsupport provider [#{provider}]"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tagenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - toyama0919