tfoutputs 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ce846ca6bd7bd7b6f76e17ac3c1c7971cc92cda7
4
+ data.tar.gz: 73e3495d3826861b05de0c388504b3c4d7533f52
5
+ SHA512:
6
+ metadata.gz: fa5391c6e6c00f81d70d78be77dadf2d1731154d3a90617c2e88fc2fb611694bc54672f61dae86f8993144c2c3016fbfe9174e48e14b8dc9c41a2dcae225c0ca
7
+ data.tar.gz: d5a317d6a4ecd5a094d49ccd3fae4bbf0a4ffb1d72ec0de25034da59996f3a4aed3ac4c7c7c6c9b7c171dd00f4af85038734b308b1824e1caec687f6faa2d797
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea/
11
+ .DS_Store
12
+ bin/
13
+ binaries/
14
+ vendor/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at admin@jaetech.org. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tfoutputs-configurator.gemspec
4
+
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 James Edwards
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/README.md ADDED
@@ -0,0 +1,43 @@
1
+ ```
2
+ ____ __ ____________ ____ __ __
3
+ / __ \__ __/ /_ __ __ /_ __/ ____/ / __ \__ __/ /_____ __ __/ /______
4
+ / /_/ / / / / __ \/ / / / / / / /_ / / / / / / / __/ __ \/ / / / __/ ___/
5
+ / _, _/ /_/ / /_/ / /_/ / / / / __/ / /_/ / /_/ / /_/ /_/ / /_/ / /_(__ )
6
+ /_/ |_|\__,_/_.___/\__, / /_/ /_/ \____/\__,_/\__/ .___/\__,_/\__/____/
7
+ /____/ /_/
8
+ ```
9
+
10
+ # Ruby TF Outputs
11
+
12
+ This gem takes your terraform outputs and imports them into ruby.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'tfoutputs'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install tfoutputs
29
+
30
+ ## Usage
31
+
32
+ TODO: Write usage instructions here
33
+
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jae2/ruby-tfoutput. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
38
+
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
43
+
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake'
3
+ require 'rspec/core/rake_task'
4
+ require 'tfoutputs/tooling/vcr_redacter'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.pattern = Dir.glob('spec/**/*_spec.rb')
8
+ end
9
+
10
+ task :rubocop do
11
+ sh('rubocop')
12
+ end
13
+
14
+ def redact(dir)
15
+ # Remove some but NOT necessarily all sensitive data from the VCR cassettes
16
+ vcr_redacter = VCRRedacter.new
17
+ puts("redacting: #{dir}")
18
+ vcr_redacter.redact(dir)
19
+ end
20
+
21
+ at_exit do
22
+ unless redact(Dir.pwd + '/spec/fixtures/vcr_cassettes') == 0
23
+ raise('WARNING: VCR CASSETTES MAY NOT HAVE BEEN REDACTED INVESTIGATE BEFORE PUSHING CHANGES')
24
+ end
25
+ end
data/lib/tfoutputs.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'tfoutputs/configurator/version'
2
+ require 'tfoutputs/configurator/state_configurator'
3
+ require 'tfoutputs/configurator/state_reader'
4
+
5
+ # Expect a list of files and options:
6
+
7
+ module TfOutputs
8
+ def configure(options)
9
+ if options.is_a?(Hash)
10
+ file_list = TfOutputs::Configurator::StateConfigurator.new([options]).file_list
11
+ end
12
+ file_list ||= TfOutputs::Configurator::StateConfigurator.new(options).file_list
13
+ TfOutputs::Configurator::StateReader.new(file_list)
14
+ end
15
+ module_function :configure
16
+ end
@@ -0,0 +1,15 @@
1
+ module TfOutputs
2
+ module Configurator
3
+ class FileStateConfiguration
4
+ attr_accessor :file_paths
5
+
6
+ def initialize(options)
7
+ @options = options
8
+ end
9
+
10
+ def save
11
+ File.new (@options[:file_path])
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ require 'aws-sdk'
2
+ require 'tempfile'
3
+
4
+ module TfOutputs
5
+ module Configurator
6
+ class S3StateConfiguration
7
+ :attr_accessor
8
+ def initialize(options)
9
+ @bucket_name = options[:bucket_name]
10
+ @bucket_key = options[:bucket_key]
11
+ @bucket_region = options[:bucket_region]
12
+ end
13
+
14
+ def save
15
+ file = Tempfile.new('tf_state')
16
+ s3 = Aws::S3::Client.new(region: @bucket_region)
17
+ resp = s3.get_object bucket: @bucket_name, key: @bucket_key
18
+ file.write(resp.body.string)
19
+ file.rewind
20
+ file
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ require 'active_support/inflector'
2
+
3
+ module TfOutputs
4
+ module Configurator
5
+ class StateConfigurator
6
+ attr_accessor :state_uris
7
+
8
+ BACKENDS = { s3: 's3_state_configuration',
9
+ file: 'file_state_configuration' }.freeze
10
+
11
+ BACKENDS.each { |_backend, filename| require "tfoutputs/configurator/#{filename}" }
12
+
13
+ def initialize(states_array)
14
+ @states_array = states_array
15
+ end
16
+ def file_list
17
+ file_list = []
18
+ @states_array.each do |state_hash|
19
+ backend_name = state_hash[:backend]
20
+ class_name = BACKENDS[backend_name.to_sym]
21
+ clazz = Object.const_get("TfOutputs::Configurator::#{class_name.camelize}")
22
+ state = clazz.new (state_hash[:options])
23
+ file_list.push(state.save)
24
+ end
25
+ file_list
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,47 @@
1
+ require 'json'
2
+
3
+ module TfOutputs
4
+ module Configurator
5
+ class StateReader
6
+ attr_accessor :file_paths, :outputs
7
+
8
+ def initialize(file_paths)
9
+ @file_paths = file_paths
10
+ @outputs = []
11
+ get_outputs_from_file
12
+ self
13
+ end
14
+
15
+ protected
16
+
17
+ def get_outputs_from_file
18
+ @file_paths.each do |path, _use_sensitive|
19
+ parser = JSON.parse(File.read(path))
20
+ parser['modules'].each do |tf_module|
21
+ parse_outputs(tf_module)
22
+ end
23
+ end
24
+ end
25
+
26
+ protected
27
+
28
+ def parse_outputs(tf_module)
29
+ if tf_module['path'] == ['root']
30
+ tf_module['outputs'].collect do |k, v|
31
+ @outputs.each { |output| raise "Duplicate key found #{k}" if output.key?(k) }
32
+ @outputs.push(k => v)
33
+ end
34
+ end
35
+ end
36
+
37
+ def method_missing(name, *args, &block)
38
+ outputs.each do |output|
39
+ next unless output.keys[0] == name.to_s
40
+ return 'sensitive' if output[name.to_s]['sensitive']
41
+ return output[name.to_s]['value']
42
+ end
43
+ super(name, *args, &block)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ module TfOutputs
2
+ module Configurator
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ require 'yaml'
2
+
3
+ class VCRRedacter
4
+ # Goes through every file in directory, looks for yaml files, attempt to parse and remove the AWS access keys from them.
5
+ def redact(path)
6
+ return 1 if !Dir.exist?(path) || Dir[path + '/*.yml'].empty?
7
+ Dir.glob(path + '/*.yml') do |yml_file|
8
+ file = YAML.load_file(yml_file)
9
+ redacted = { 'Authorization' => ['redacted'] }
10
+ file['http_interactions'].first['request']['headers'] = redacted
11
+ File.open(yml_file, 'w') { |f| YAML.dump(file, f) }
12
+ end
13
+ 0
14
+ end
15
+ end
data/tfoutputs.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tfoutputs/configurator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'tfoutputs'
8
+ spec.version = TfOutputs::Configurator::VERSION
9
+ spec.authors = ['James Edwards']
10
+ spec.email = ['admin@jaetech.org']
11
+
12
+ spec.summary = 'Gem for grabbing variables from terraform'
13
+ spec.description = 'Sometimes we want to use the outputs of terraform in our ruby code for generating dashboard etc.. This gem enables this'
14
+ spec.homepage = 'https://jaetech.org'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|fixtures)/}) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.12'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_development_dependency 'rubocop'
23
+ spec.add_runtime_dependency 'aws-sdk', '~> 2'
24
+ spec.add_runtime_dependency 'activesupport', '~> 5'
25
+ spec.add_development_dependency 'rspec', '~> 3.5'
26
+ spec.add_development_dependency 'vcr', '~>3.0'
27
+ spec.add_development_dependency 'webmock', '~> 2.1'
28
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tfoutputs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Edwards
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aws-sdk
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.1'
125
+ description: Sometimes we want to use the outputs of terraform in our ruby code for
126
+ generating dashboard etc.. This gem enables this
127
+ email:
128
+ - admin@jaetech.org
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".ruby-version"
135
+ - CODE_OF_CONDUCT.md
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - lib/tfoutputs.rb
141
+ - lib/tfoutputs/configurator/file_state_configuration.rb
142
+ - lib/tfoutputs/configurator/s3_state_configuration.rb
143
+ - lib/tfoutputs/configurator/state_configurator.rb
144
+ - lib/tfoutputs/configurator/state_reader.rb
145
+ - lib/tfoutputs/configurator/version.rb
146
+ - lib/tfoutputs/tooling/vcr_redacter.rb
147
+ - tfoutputs.gemspec
148
+ homepage: https://jaetech.org
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.5.1
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Gem for grabbing variables from terraform
172
+ test_files: []