terraform-exporter 0.0.2 → 0.0.3

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: 92a92c3eade1b46a2190e83dcf95cff3c1982b3c
4
- data.tar.gz: 069d6299c8f979325efeda89a1c824436be210ba
3
+ metadata.gz: 268df7a7c3734ec6b3262aaad17fd35992ab3da5
4
+ data.tar.gz: ff73e11a723b3572828093a152b759d7e6e2c23e
5
5
  SHA512:
6
- metadata.gz: dc96559168d75c3ed04c4e18ffa68d0420d582c722e75f872fe7c8db3d4e950463213765de3a017cafe055b40579181d05ad3b9920506551c7277e12d33db9e8
7
- data.tar.gz: 0f74ea201905c4a2424f7b966c377c0877f9d70de5282595e2addda9f39a4ecbb9f29f624ddf4f88d3ebcfe2f387807dc200338074518af846a31f0bf2be0fc6
6
+ metadata.gz: c62a4264e70ea0b3bf45c930e9f913be5ee9372355233995d5f511d4cd232881eb17b481a298a12fc28256fa860894df2a1b836362243fdd9353a4540ac7736f
7
+ data.tar.gz: d99388881840946c339f82633821155571a4bb1b291ce6294d87f943a1da94818d788990884c3554b6a8d16748798ec3c7141ff63300db09c359a4cd97d911cb
@@ -0,0 +1,14 @@
1
+ engines:
2
+ duplication:
3
+ enabled: true
4
+ config:
5
+ languages:
6
+ - ruby
7
+ fixme:
8
+ enabled: true
9
+ rubocop:
10
+ enabled: true
11
+ ratings:
12
+ paths:
13
+ - "**.rb"
14
+ exclude_paths: []
data/.gitignore CHANGED
@@ -1,2 +1,18 @@
1
- pkg/
2
- coverage/
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --require spec_helper
2
+ --format progress
3
+ --order random
4
+ --color
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - 2.1.0
5
+ - 2.2.0
6
+ - 2.3.0
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011- Intercom, Inc. (https://www.intercom.io)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ task.rspec_opts = %w(--format progress --order random --color)
6
+ end
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -1,11 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
+ require "terraformer"
2
3
 
3
- require "terraforming"
4
4
  begin
5
5
  Terraformer::CLI.start(ARGV)
6
- rescue Terraformer::UserInputError, Terraformer::UserInputMaxAttemptsError, Terraformer::TerraformInvalidTfstateFile, Terraformer::TerraformFileNotFound => e
7
- if e.class.is_a? Terraformer::UserInputError
6
+ rescue Exception => exception
7
+ case exception
8
+ when Terraformer::UserInputError
8
9
  exit 0
10
+ else
11
+ message = "[ERROR] #{exception.class.to_s}"
12
+ message += " => #{exception.message}" unless exception.message.strip.empty?
13
+ puts message
14
+ exit 1
9
15
  end
10
- exit 1
11
16
  end
@@ -18,6 +18,8 @@ module Terraformer
18
18
  execute(Terraformer::Resource::DatadogMonitor, options)
19
19
  end
20
20
 
21
+ private
22
+
21
23
  def symbolize(obj)
22
24
  return obj.reduce({}) do |memo, (k, v)|
23
25
  memo.tap { |m| m[k.to_sym] = symbolize(v) }
@@ -1,15 +1,31 @@
1
1
  module Terraformer
2
2
  module Credentials
3
+ class AwsMissingCredentals < RuntimeError
4
+ attr_reader :key
5
+
6
+ def initialize(key)
7
+ @key = key
8
+
9
+ super(message)
10
+ end
11
+
12
+ def message
13
+ "'#{key}' not passed. set it via CLI --#{key} or #{key.upcase} enviroment variable."
14
+ end
15
+ end
16
+
3
17
  class Aws
18
+ KEYS = %w(aws_region aws_access_key_id aws_secret_access_key).freeze
19
+
4
20
  def self.get_from_options(options)
5
- credentials = {}
6
- %w(aws_region aws_access_key_id aws_secret_access_key).each do |key|
21
+ KEYS.inject({}) do |credentials, key|
7
22
  aws_key = key.sub("aws_", "").to_sym
8
23
  credentials[aws_key] = options[key.to_sym].nil? ? options[key] : options[key.to_sym]
9
24
  credentials[aws_key] = ENV[key.upcase] if credentials[aws_key].nil?
10
- end
25
+ raise AwsMissingCredentals.new(key) if credentials[aws_key].nil?
11
26
 
12
- credentials.reject{ |k, v| v.nil? }
27
+ credentials
28
+ end
13
29
  end
14
30
  end
15
31
  end
@@ -1,15 +1,31 @@
1
1
  module Terraformer
2
2
  module Credentials
3
+ class DatadogMissingCredentals < RuntimeError
4
+ attr_reader :key
5
+
6
+ def initialize(key)
7
+ @key = key
8
+
9
+ super(message)
10
+ end
11
+
12
+ def message
13
+ "'#{key}' not being passed. set it via CLI --#{key} or #{key.upcase} enviroment variable."
14
+ end
15
+ end
16
+
3
17
  class Datadog
18
+ KEYS = %w(datadog_api_key datadog_app_key).freeze
19
+
4
20
  def self.get_from_options(options)
5
- credentials = {}
6
- %w(datadog_api_key datadog_app_key).each do |key|
21
+ KEYS.inject({}) do |credentials, key|
7
22
  datadog_key = key.sub("datadog_", "").to_sym
8
23
  credentials[datadog_key] = options[key.to_sym].nil? ? options[key] : options[key.to_sym]
9
24
  credentials[datadog_key] = ENV[key.upcase] if credentials[datadog_key].nil?
10
- end
25
+ raise DatadogMissingCredentals.new(key) if credentials[datadog_key].nil?
11
26
 
12
- credentials.reject{ |k, v| v.nil? }
27
+ credentials
28
+ end
13
29
  end
14
30
  end
15
31
  end
@@ -56,13 +56,17 @@ module Terraformer
56
56
  add_checksummed_attributes(attributes, alarm)
57
57
  end
58
58
 
59
+ private
60
+
59
61
  def alarms
60
62
  @alarms ||= begin
61
- response = @client.describe_alarms.map(&:metric_alarms).flatten
62
- response.each do |alarm|
63
- def alarm.normalized_name
64
- "#{self.alarm_name.gsub(/[^a-zA-Z0-9_]/, "_")}_#{SecureRandom.hex(4)}".gsub(/_+/, '_')
65
- end
63
+ aws_response = @client.describe_alarms.map(&:metric_alarms).flatten
64
+ aws_response.inject([]) do |alarms, alarm|
65
+ alarm = alarm.to_h
66
+ alarm[:normalized_name] = Terraformer::Normalizer.module_name(alarm[:alarm_name])
67
+ alarm[:dimensions].map! { |d| OpenStruct.new(d) }
68
+
69
+ alarms << OpenStruct.new(alarm)
66
70
  end
67
71
  end
68
72
  end
@@ -64,7 +64,7 @@ module Terraformer
64
64
 
65
65
  def check_response(response)
66
66
  unless response[0] == "200"
67
- raise "[ERROR] Received bad response form Datadog. code: #{response[0]} response: #{response[1]}"
67
+ raise "Received bad response form Datadog. code: #{response[0]} response: #{response[1]}"
68
68
  end
69
69
 
70
70
  response[1]
@@ -30,13 +30,12 @@ module Terraformer
30
30
  if File.file?(tfstate_path)
31
31
  tfstate = parse_json_file(tfstate_path)
32
32
  else
33
- puts "[ERROR] File not found while trying to merge state file with: #{tfstate_path}."
34
- raise TerraformFileNotFound
33
+ raise TerraformFileNotFound, "File not found while trying to merge state file with: #{tfstate_path}."
35
34
  end
36
35
  else
37
36
  tfstate_path = "terraform.tfstate"
38
37
  if File.file?(tfstate_path)
39
- UserInput.ask("File: #{tfstate_path} already exists. Overwrite?", "Y", "n")
38
+ UserInput.ask("File: #{tfstate_path} already exists and the 'merge' option was not passed. Overwrite?", "Y", "n")
40
39
  end
41
40
  tfstate = tfstate_skeleton
42
41
  end
@@ -55,8 +54,7 @@ module Terraformer
55
54
  file_content = File.read(file_path)
56
55
  JSON.parse(file_content)
57
56
  rescue JSON::ParserError
58
- puts "[ERROR] Unable to parse: #{file_path}."
59
- raise TerraformInvalidTfstateFile
57
+ raise TerraformInvalidTfstateFile, "Unable to parse: #{file_path}."
60
58
  end
61
59
 
62
60
  def tfstate_skeleton
@@ -9,15 +9,13 @@ module Terraformer
9
9
  MAX_ATTEMPTS = 10
10
10
 
11
11
  class << self
12
- def get_input
13
- response = gets
14
- response.chomp
12
+ def get_input(message, success, failure)
13
+ Thor::Shell::Basic.new.ask("#{message} [#{success}/#{failure}]")
15
14
  end
16
15
 
17
16
  def ask(message, success, failure)
18
17
  (0..MAX_ATTEMPTS).each do |i|
19
- puts "#{message} [#{success}/#{failure}]"
20
- response = get_input
18
+ response = get_input(message, success, failure).chomp
21
19
 
22
20
  if response.downcase == success.downcase || response == ""
23
21
  return true
@@ -26,7 +24,7 @@ module Terraformer
26
24
  raise UserInputError
27
25
  end
28
26
  end
29
- raise UserInputMaxAttemptsError
27
+ raise UserInputMaxAttemptsError, "Reached max number of attempts."
30
28
  end
31
29
  end
32
30
  end
@@ -1,3 +1,3 @@
1
1
  module Terraformer
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -23,11 +23,11 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency "dogapi", "~> 1.23"
24
24
  spec.add_dependency "oj", "~> 2.17.1"
25
25
  spec.add_dependency "ox", "~> 2.4.0"
26
- spec.add_dependency "thor"
26
+ spec.add_dependency "thor", "~> 0.19.1"
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 1.7"
29
29
  spec.add_development_dependency "coveralls", "~> 0.8.13"
30
- spec.add_development_dependency "rake"
30
+ spec.add_development_dependency "rake", "~> 10.5"
31
31
  spec.add_development_dependency "rspec", "~> 3.2"
32
32
  spec.add_development_dependency "simplecov", "~> 0.11.1"
33
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraform-exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacopo Scrinzi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-08 00:00:00.000000000 Z
11
+ date: 2016-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: thor
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.19.1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.19.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -112,16 +112,16 @@ dependencies:
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '10.5'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: '10.5'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -158,10 +158,13 @@ executables:
158
158
  extensions: []
159
159
  extra_rdoc_files: []
160
160
  files:
161
+ - ".codeclimate.yml"
161
162
  - ".gitignore"
163
+ - ".rspec"
164
+ - ".travis.yml"
162
165
  - Gemfile
163
- - Gemfile.lock
164
166
  - Guardfile
167
+ - MIT-LICENCE
165
168
  - README.md
166
169
  - Rakefile
167
170
  - bin/terraformer
@@ -1,127 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- terraform-exporter (0.0.1)
5
- aws-sdk (~> 2.5.1)
6
- dogapi (~> 1.23)
7
- oj (~> 2.17.1)
8
- ox (~> 2.4.0)
9
- thor
10
-
11
- GEM
12
- remote: https://rubygems.org/
13
- specs:
14
- ast (2.3.0)
15
- aws-sdk (2.5.11)
16
- aws-sdk-resources (= 2.5.11)
17
- aws-sdk-core (2.5.11)
18
- jmespath (~> 1.0)
19
- aws-sdk-resources (2.5.11)
20
- aws-sdk-core (= 2.5.11)
21
- coderay (1.1.1)
22
- coveralls (0.8.13)
23
- json (~> 1.8)
24
- simplecov (~> 0.11.0)
25
- term-ansicolor (~> 1.3)
26
- thor (~> 0.19.1)
27
- tins (~> 1.6.0)
28
- diff-lcs (1.2.5)
29
- docile (1.1.5)
30
- dogapi (1.23.0)
31
- multi_json
32
- ffi (1.9.14)
33
- formatador (0.2.5)
34
- guard (2.14.0)
35
- formatador (>= 0.2.4)
36
- listen (>= 2.7, < 4.0)
37
- lumberjack (~> 1.0)
38
- nenv (~> 0.1)
39
- notiffany (~> 0.0)
40
- pry (>= 0.9.12)
41
- shellany (~> 0.0)
42
- thor (>= 0.18.1)
43
- guard-compat (1.2.1)
44
- guard-rspec (4.7.3)
45
- guard (~> 2.1)
46
- guard-compat (~> 1.1)
47
- rspec (>= 2.99.0, < 4.0)
48
- jmespath (1.3.1)
49
- json (1.8.3)
50
- listen (3.1.5)
51
- rb-fsevent (~> 0.9, >= 0.9.4)
52
- rb-inotify (~> 0.9, >= 0.9.7)
53
- ruby_dep (~> 1.2)
54
- lumberjack (1.0.10)
55
- method_source (0.8.2)
56
- multi_json (1.12.1)
57
- nenv (0.3.0)
58
- notiffany (0.1.1)
59
- nenv (~> 0.1)
60
- shellany (~> 0.0)
61
- oj (2.17.4)
62
- ox (2.4.5)
63
- parser (2.3.1.4)
64
- ast (~> 2.2)
65
- powerpack (0.1.1)
66
- pry (0.10.4)
67
- coderay (~> 1.1.0)
68
- method_source (~> 0.8.1)
69
- slop (~> 3.4)
70
- rainbow (2.1.0)
71
- rake (11.3.0)
72
- rb-fsevent (0.9.7)
73
- rb-inotify (0.9.7)
74
- ffi (>= 0.5.0)
75
- rspec (3.5.0)
76
- rspec-core (~> 3.5.0)
77
- rspec-expectations (~> 3.5.0)
78
- rspec-mocks (~> 3.5.0)
79
- rspec-core (3.5.3)
80
- rspec-support (~> 3.5.0)
81
- rspec-expectations (3.5.0)
82
- diff-lcs (>= 1.2.0, < 2.0)
83
- rspec-support (~> 3.5.0)
84
- rspec-mocks (3.5.0)
85
- diff-lcs (>= 1.2.0, < 2.0)
86
- rspec-support (~> 3.5.0)
87
- rspec-support (3.5.0)
88
- rubocop (0.43.0)
89
- parser (>= 2.3.1.1, < 3.0)
90
- powerpack (~> 0.1)
91
- rainbow (>= 1.99.1, < 3.0)
92
- ruby-progressbar (~> 1.7)
93
- unicode-display_width (~> 1.0, >= 1.0.1)
94
- ruby-progressbar (1.8.1)
95
- ruby_dep (1.4.0)
96
- shellany (0.0.1)
97
- simplecov (0.11.2)
98
- docile (~> 1.1.0)
99
- json (~> 1.8)
100
- simplecov-html (~> 0.10.0)
101
- simplecov-html (0.10.0)
102
- slop (3.6.0)
103
- term-ansicolor (1.3.2)
104
- tins (~> 1.0)
105
- terminal-notifier-guard (1.7.0)
106
- thor (0.19.1)
107
- tins (1.6.0)
108
- unicode-display_width (1.1.1)
109
-
110
- PLATFORMS
111
- ruby
112
-
113
- DEPENDENCIES
114
- bundler (~> 1.7)
115
- coveralls (~> 0.8.13)
116
- guard
117
- guard-rspec
118
- listen (~> 3.1.0)
119
- rake
120
- rspec (~> 3.2)
121
- rubocop
122
- simplecov (~> 0.11.1)
123
- terminal-notifier-guard
124
- terraform-exporter!
125
-
126
- BUNDLED WITH
127
- 1.13.2