tagenv 0.1.0 → 0.1.1

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: ff00251ab82c3052552b502bd8dee481fa649f67
4
- data.tar.gz: 4839c25d9af623187b3fb11fcc4be1ff839a5afc
3
+ metadata.gz: a31dcee93ac08da65bdd769c8b2b37a96e0a0af7
4
+ data.tar.gz: 7b9976b148e7db5fb537419d0e776b801cabc728
5
5
  SHA512:
6
- metadata.gz: e73818a7e2e7fc8afce45e994fd245b6ae59d1b19f9fb75ce65f87be28c4093430bf4eda66d0b9b6d2e489c60ac192d8f3d15af6341fe5882aa82d25c24bda5b
7
- data.tar.gz: 9ffd30b454f16d10d50a54c21e4072ab674163f55faef973bcaf281545035c2fcc694d22fe978d24c0855ad58a3a9136cceea9694344e640e9530a03d24a8ca8
6
+ metadata.gz: c3f37bc7ad0c8d540f6e033f835d8f112c00a723d969a70d53d8c6505ec9b7756c18cfd82f3ccbd6c81f678122fd78f6f278c1588ddf93732f2f88fcede39070
7
+ data.tar.gz: 45c212287c86b39afdee0c298027a1f770815741ffb84b2a7b665ef347a00781d5704a93d0905c957cff8538b313e74d0cf6dbad50165951edb90d030cd32258
data/lib/tagenv/cli.rb CHANGED
@@ -14,11 +14,13 @@ module Tagenv
14
14
  desc 'load', 'load'
15
15
  option :prefix, aliases: '-p', default: 'EC2TAG_',type: :string, desc: 'prefix'
16
16
  option :instance_id, aliases: '-i', type: :string, desc: 'instance_id'
17
+ option :provider, type: :string, default: 'ec2', desc: 'provider'
17
18
  option :print, aliases: '-P', type: :boolean, desc: 'print'
18
19
  def load
19
20
  Tagenv::Env.load(
20
21
  prefix: options[:prefix],
21
- instance_id: options[:instance_id]
22
+ instance_id: options[:instance_id],
23
+ provider: options[:provider]
22
24
  )
23
25
  p ENV if options[:print]
24
26
  end
@@ -9,14 +9,21 @@ module Tagenv
9
9
  @ec2 = Aws::EC2::Client.new(region: region)
10
10
  end
11
11
 
12
+ def get_tag_hash(instance_id)
13
+ instance_id = instance_id || Metadata.get_instance_id
14
+ instances_tag_with_id(instance_id)
15
+ end
16
+
17
+ private
18
+
12
19
  def instances_tag_with_id(instance_id)
13
20
  tags = @ec2.describe_instances(
14
21
  instance_ids: [instance_id]
15
22
  ).data.to_h[:reservations].map { |instance| instance[:instances].first }.first[:tags]
16
- get_tag_hash(tags)
23
+ convert_tag_hash(tags)
17
24
  end
18
25
 
19
- def get_tag_hash(tags)
26
+ def convert_tag_hash(tags)
20
27
  result = {}
21
28
  tags.each {|hash|
22
29
  result[hash['key'] || hash[:key]] = hash['value'] || hash[:value]
data/lib/tagenv/env.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  module Tagenv
2
2
  class Env
3
- def self.load(prefix: '', instance_id: nil)
4
- @ec2_tag = Ec2::Tag.new
5
- instance_id = instance_id || Ec2::Metadata.get_instance_id
6
- tag_hash = @ec2_tag.instances_tag_with_id(instance_id)
3
+ def self.load(prefix: '', instance_id: nil, provider: 'ec2')
4
+ tag_hash = {}
5
+ if provider == 'ec2'
6
+ @ec2_tag = Ec2::Tag.new
7
+ tag_hash = @ec2_tag.get_tag_hash(instance_id)
8
+ else
9
+ raise "Unsupport provider [#{provider}]"
10
+ end
7
11
  tag_hash.each do |k, v|
8
12
  ENV[prefix + k] = v
9
13
  end
@@ -1,4 +1,4 @@
1
1
  module Tagenv
2
2
  # tagenv version
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - toyama0919