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 +4 -4
- data/lib/tagenv/ec2/tag.rb +9 -7
- data/lib/tagenv/ec2/tag_util.rb +2 -2
- data/lib/tagenv/version.rb +1 -1
- data/lib/tagenv.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8046a15f8a4b53a188d8826ed47bfc5024623c53
|
4
|
+
data.tar.gz: f05be3aa35a9f2e607140886173724a38ca2b043
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cf95dcf7b8c8f317a35c09fd80d2a289ee15004a81bdf8e9b243b333493471e801c35ca655b22acd071a1c15d76315fdf510cef15e58b24b9863ccb11eea9c9
|
7
|
+
data.tar.gz: 1e3be10e4e492334563f6601a21af8148e4cbd77b48174fa4bb805a95033afe6c93be1ed209436b183dcc3e708ab147b532f7d29c28f1c7d011cf3ab9034285a
|
data/lib/tagenv/ec2/tag.rb
CHANGED
@@ -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
|
14
|
-
|
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
|
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
|
data/lib/tagenv/ec2/tag_util.rb
CHANGED
@@ -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
|
data/lib/tagenv/version.rb
CHANGED
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}]"
|