tagenv 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a31dcee93ac08da65bdd769c8b2b37a96e0a0af7
4
- data.tar.gz: 7b9976b148e7db5fb537419d0e776b801cabc728
3
+ metadata.gz: 6e34cf2452e553e4cb4051340cd0905790f50a0d
4
+ data.tar.gz: edabe84a5d3e4f70d5ac8481ed98a6c3cc1dca22
5
5
  SHA512:
6
- metadata.gz: c3f37bc7ad0c8d540f6e033f835d8f112c00a723d969a70d53d8c6505ec9b7756c18cfd82f3ccbd6c81f678122fd78f6f278c1588ddf93732f2f88fcede39070
7
- data.tar.gz: 45c212287c86b39afdee0c298027a1f770815741ffb84b2a7b665ef347a00781d5704a93d0905c957cff8538b313e74d0cf6dbad50165951edb90d030cd32258
6
+ metadata.gz: '020955db6d7dc98511877fb57980051a8cb22ec480208274b2fb4e54af072af90d51c39360ede242f4d10836638e9bf45fdbbb2bf55ca5aed18754beaae24821'
7
+ data.tar.gz: 44f0bb292908fcaadfea556b5d2e6884c9830180a0705fd070fb4499983d4bbfed1c9dea22d46cec1505928124ac6648b0ada21aac5e23dd0ea2d28231f76dee
data/.travis.yml CHANGED
@@ -1,18 +1,15 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.0.*
5
4
  - 2.1.*
6
5
  - 2.2.*
7
- - 2.3.0
6
+ - 2.3.3
7
+ - 2.4.0
8
8
 
9
9
  gemfile:
10
10
  - Gemfile
11
11
 
12
12
  os:
13
13
  - linux
14
- - osx
15
-
16
- before_install: gem update bundler
17
14
 
18
15
  script: 'bundle exec rake spec'
data/README.md CHANGED
@@ -2,34 +2,63 @@
2
2
 
3
3
  ec2 instance tag apply environment variables.
4
4
 
5
- ## Examples
5
+ ## Settings
6
6
 
7
+ ```sh
8
+ export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX
9
+ export AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
10
+ export AWS_REGION=ap-northeast-1
7
11
  ```
12
+
13
+ * support environment variables and iam role.
14
+
15
+ ## Examples
16
+
17
+ ```ruby
8
18
  require 'tagenv'
9
19
 
10
- Tagenv::Env.load(prefix: 'EC2TAG_')
20
+ Tagenv.load(prefix: 'EC2TAG_')
11
21
 
12
22
  p ENV
13
- # {"EC2TAG_Group"=>"group_a", "EC2TAG_Roles"=>"front", "EC2TAG_Stages"=>"staging", "EC2TAG_Name"=>"feweb07", "EC2TAG_Project"=>"project_a"}
23
+ # {
24
+ # "EC2TAG_Group"=>"group_a",
25
+ # "EC2TAG_Roles"=>"front",
26
+ # "EC2TAG_Stages"=>"staging",
27
+ # "EC2TAG_Name"=>"app01",
28
+ # "EC2TAG_Project"=>"project_a"
29
+ # ....
30
+ # }
14
31
  ```
15
32
 
16
33
  ## Installation
17
34
 
18
35
  Add this line to your application's Gemfile:
19
36
 
20
- gem 'tagenv'
37
+ ```sh
38
+ gem 'tagenv'
39
+ ```
21
40
 
22
41
  And then execute:
23
42
 
24
- $ bundle
43
+ ```sh
44
+ $ bundle
45
+ ```
25
46
 
26
47
  Or install it yourself as:
27
48
 
28
- $ gem install tagenv
49
+ ```sh
50
+ $ gem install tagenv
51
+ ```
29
52
 
30
53
  ## Synopsis
31
54
 
32
- $ tagenv
55
+ ```sh
56
+ $ tagenv
57
+ ```
58
+
59
+ ## Future
60
+
61
+ * Support provider GCP.
33
62
 
34
63
  ## Contributing
35
64
 
@@ -45,9 +74,3 @@ Or install it yourself as:
45
74
  * [Issues](https://github.com/toyama0919/tagenv/issues)
46
75
  * [Documentation](http://rubydoc.info/gems/tagenv/frames)
47
76
  * [Email](mailto:toyama0919@gmail.com)
48
-
49
- ## Copyright
50
-
51
- Copyright (c) 2017 toyama0919
52
-
53
- See [LICENSE.txt](../LICENSE.txt) for details.
data/lib/tagenv/cli.rb CHANGED
@@ -17,7 +17,7 @@ module Tagenv
17
17
  option :provider, type: :string, default: 'ec2', desc: 'provider'
18
18
  option :print, aliases: '-P', type: :boolean, desc: 'print'
19
19
  def load
20
- Tagenv::Env.load(
20
+ Tagenv.load(
21
21
  prefix: options[:prefix],
22
22
  instance_id: options[:instance_id],
23
23
  provider: options[:provider]
@@ -1,3 +1,2 @@
1
1
  module Tagenv
2
- TIME_OUT = 3
3
2
  end
@@ -1,10 +1,13 @@
1
1
  require 'logger'
2
2
  require 'open-uri'
3
3
  require 'json'
4
+ require "timeout"
4
5
 
5
6
  module Tagenv
6
7
  module Ec2
7
8
  class Metadata
9
+ TIME_OUT = 3
10
+
8
11
  def self.get_metadata(path)
9
12
  begin
10
13
  result = {}
@@ -13,7 +16,7 @@ module Tagenv
13
16
  return body
14
17
  }
15
18
  return result
16
- rescue Timeout::Error => e
19
+ rescue ::Timeout::Error => e
17
20
  raise "not EC2 instance"
18
21
  end
19
22
  end
@@ -1,4 +1,5 @@
1
1
  require 'aws-sdk'
2
+ require_relative 'tag_util'
2
3
 
3
4
  module Tagenv
4
5
  module Ec2
@@ -20,15 +21,7 @@ module Tagenv
20
21
  tags = @ec2.describe_instances(
21
22
  instance_ids: [instance_id]
22
23
  ).data.to_h[:reservations].map { |instance| instance[:instances].first }.first[:tags]
23
- convert_tag_hash(tags)
24
- end
25
-
26
- def convert_tag_hash(tags)
27
- result = {}
28
- tags.each {|hash|
29
- result[hash['key'] || hash[:key]] = hash['value'] || hash[:value]
30
- }
31
- result
24
+ TagUtil.convert_tag_hash(tags)
32
25
  end
33
26
  end
34
27
  end
@@ -0,0 +1,15 @@
1
+ require 'aws-sdk'
2
+
3
+ module Tagenv
4
+ module Ec2
5
+ class TagUtil
6
+ def self.convert_tag_hash(tags)
7
+ result = {}
8
+ tags.each {|hash|
9
+ result[hash['key'] || hash[:key]] = hash['value'] || hash[:value]
10
+ }
11
+ result
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,4 +1,4 @@
1
1
  module Tagenv
2
2
  # tagenv version
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
data/lib/tagenv.rb CHANGED
@@ -1,6 +1,20 @@
1
1
  require 'tagenv/version'
2
2
  require 'tagenv/constants'
3
- require 'tagenv/env'
4
3
  require 'tagenv/ec2/metadata'
5
4
  require 'tagenv/ec2/tag'
6
5
  require 'tagenv/cli'
6
+
7
+ module Tagenv
8
+ def self.load(prefix: '', instance_id: nil, provider: 'ec2')
9
+ tag_hash = {}
10
+ if provider == 'ec2'
11
+ @ec2_tag = Ec2::Tag.new
12
+ tag_hash = @ec2_tag.get_tag_hash(instance_id)
13
+ else
14
+ raise "Unsupport provider [#{provider}]"
15
+ end
16
+ tag_hash.each do |k, v|
17
+ ENV[prefix + k] = v
18
+ end
19
+ end
20
+ end
data/spec/cli_spec.rb CHANGED
@@ -5,7 +5,7 @@ describe Tagenv::CLI do
5
5
  before do
6
6
  end
7
7
 
8
- it "should stdout sample" do
8
+ it "should stdout help" do
9
9
  output = capture_stdout do
10
10
  Tagenv::CLI.start(['help'])
11
11
  end
@@ -14,9 +14,11 @@ describe Tagenv::CLI do
14
14
 
15
15
  it "include" do
16
16
  output = capture_stdout do
17
- Tagenv::CLI.start(['help', 'sample'])
17
+ Tagenv::CLI.start(['help', 'load'])
18
18
  end
19
- expect(output).to include('--fields')
19
+ expect(output).to include('--provider')
20
+ expect(output).to include('--instance-id')
21
+ expect(output).to include('--prefix')
20
22
  end
21
23
 
22
24
  after do
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'tagenv'
3
+
4
+ describe Tagenv::Ec2::Tag do
5
+ before do
6
+ end
7
+
8
+ it "convert_tag_hash_1" do
9
+ aws_tag_format = [
10
+ { key: 'Name', value: 'app01' },
11
+ { key: 'Stages', value: 'production' }
12
+ ]
13
+ expect_value = { 'Name' => 'app01', 'Stages' => 'production' }
14
+ expect(Ec2::TagUtil.convert_tag_hash(aws_tag_format)).to(eq(expect_value))
15
+ end
16
+
17
+ it "convert_tag_hash_2" do
18
+ aws_tag_format = [
19
+ { 'key' => 'Name', 'value' => 'app01' },
20
+ { 'key' => 'Stages', 'value' => 'production' }
21
+ ]
22
+ expect_value = { 'Name' => 'app01', 'Stages' => 'production' }
23
+ expect(Ec2::TagUtil.convert_tag_hash(aws_tag_format)).to(eq(expect_value))
24
+ end
25
+
26
+ after do
27
+ end
28
+ 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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - toyama0919
@@ -150,7 +150,6 @@ files:
150
150
  - ".yardopts"
151
151
  - ChangeLog.md
152
152
  - Gemfile
153
- - LICENSE.txt
154
153
  - README.md
155
154
  - Rakefile
156
155
  - bin/tagenv
@@ -159,10 +158,10 @@ files:
159
158
  - lib/tagenv/constants.rb
160
159
  - lib/tagenv/ec2/metadata.rb
161
160
  - lib/tagenv/ec2/tag.rb
162
- - lib/tagenv/env.rb
161
+ - lib/tagenv/ec2/tag_util.rb
163
162
  - lib/tagenv/version.rb
164
163
  - spec/cli_spec.rb
165
- - spec/core_spec.rb
164
+ - spec/ec2/tag_util_spec.rb
166
165
  - spec/spec_helper.rb
167
166
  - spec/tagenv_spec.rb
168
167
  - tagenv.gemspec
@@ -192,6 +191,6 @@ specification_version: 4
192
191
  summary: ec2 instance tag apply environment variables.
193
192
  test_files:
194
193
  - spec/cli_spec.rb
195
- - spec/core_spec.rb
194
+ - spec/ec2/tag_util_spec.rb
196
195
  - spec/spec_helper.rb
197
196
  - spec/tagenv_spec.rb
data/LICENSE.txt DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2017 toyama0919
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/tagenv/env.rb DELETED
@@ -1,16 +0,0 @@
1
- module Tagenv
2
- class Env
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
11
- tag_hash.each do |k, v|
12
- ENV[prefix + k] = v
13
- end
14
- end
15
- end
16
- end
data/spec/core_spec.rb DELETED
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
- require 'tagenv'
3
-
4
- describe Tagenv::Core do
5
- before do
6
- @core = Core.new
7
- end
8
-
9
- it "core not nil" do
10
- expect(@core).not_to eq(nil)
11
- end
12
-
13
- it "private method" do
14
- @core.send(:sample, []).should == []
15
- end
16
-
17
- after do
18
- end
19
- end