bb8 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ebd3491377b1b0031cc4b605d6bd1d2ce5c74861
4
+ data.tar.gz: d2a9f45e7a93464020b06fe916436ee3dfa532c4
5
+ SHA512:
6
+ metadata.gz: abaaf5d51e16ec11d7415ac2f7e5086d731f6dbd77a13a6e46462bfb9f3e60d4e7c85bee5388ae2eaec231688067e3211767b870f1362d8d8f36d9d73b2cddbf
7
+ data.tar.gz: e3b0e2244c90f714093f114ef2da5de4ea39c2df6ddeabf17cff9dff93797f9c28a6b0cc84fcc0cc4f3a38e04cb85a829292998886a0b3b78c8b61b821f97b2f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.13.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at pat@freelancing-gods.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bb8.gemspec
4
+ gemspec
data/README.markdown ADDED
@@ -0,0 +1,36 @@
1
+ # Bb8
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bb8`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'bb8'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install bb8
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bb8. 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.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bb8.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bb8/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bb8"
8
+ spec.version = BB8::VERSION
9
+ spec.authors = ["Pat Allan"]
10
+ spec.email = ["pat@freelancing-gods.com"]
11
+
12
+ spec.summary = %q{Manage and share Terraform variables, environments, and states securely.}
13
+ spec.homepage = "https://github.com/pat/bb8"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |file|
16
+ file.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |file| File.basename(file) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "voltos", "~> 0.3"
23
+
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bb8"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/bb8 ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+
4
+ require 'bb8'
5
+
6
+ BB8::CLI.call *ARGV
data/lib/bb8.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'fileutils'
2
+ require 'json'
3
+ require 'openssl'
4
+ require 'securerandom'
5
+ require 'voltos'
6
+
7
+ module BB8
8
+ module Commands
9
+ end
10
+ end
11
+
12
+ require 'bb8/cli'
13
+ require 'bb8/commands/environment'
14
+ require 'bb8/commands/help'
15
+ require 'bb8/commands/initialise_environment'
16
+ require 'bb8/commands/initialise_project'
17
+ require 'bb8/commands/terraform'
18
+ require 'bb8/commands/version'
19
+ require 'bb8/decrypt'
20
+ require 'bb8/encrypt'
21
+ require 'bb8/set_encryption_keys'
22
+ require 'bb8/version'
23
+ require 'bb8/voltos_variables'
data/lib/bb8/cli.rb ADDED
@@ -0,0 +1,16 @@
1
+ class BB8::CLI
2
+ def self.call(*arguments)
3
+ environments = Dir['*'].select { |file| File.directory? file }
4
+
5
+ case arguments.first
6
+ when 'init'
7
+ BB8::Commands::InitialiseProject.call arguments[1]
8
+ when 'version'
9
+ BB8::Commands::Version.call
10
+ when *environments
11
+ BB8::Commands::Environment.call *arguments
12
+ else
13
+ BB8::Commands::Help.call
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ class BB8::Commands::Environment
2
+ def self.call(environment, command, *arguments)
3
+ case command
4
+ when 'init'
5
+ BB8::Commands::InitialiseEnvironment.call(environment, *arguments)
6
+ else
7
+ BB8::Commands::Terraform.call(environment, command, *arguments)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ class BB8::Commands::Help
2
+ def self.call
3
+ puts <<-MESSAGE
4
+ BB-8 Version #{BB8::VERSION}
5
+
6
+ Usage:
7
+
8
+ bb8 init . Set up a directory as a git
9
+ repository.
10
+ bb8 ENVIRONMENT init Set up a directory for a specific
11
+ environment.
12
+ bb8 ENVIRONMENT [show|apply|destroy|...] Run a Terraform command within a
13
+ specific environment's context.
14
+ MESSAGE
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ class BB8::Commands::InitialiseEnvironment
2
+ VOLTOS_CONFIGURATION = File.expand_path("~/.voltos/config.json")
3
+
4
+ def self.call(name, voltos_bundle, *arguments)
5
+ new(name, voltos_bundle).call
6
+ end
7
+
8
+ def initialize(name, voltos_bundle)
9
+ @name, @voltos_bundle = name, voltos_bundle
10
+ end
11
+
12
+ def call
13
+ FileUtils.mkdir_p name
14
+ Dir.chdir name
15
+
16
+ `voltos create #{voltos_bundle}`
17
+ `voltos use #{voltos_bundle}`
18
+ BB8::SetEncryptionKeys.call
19
+
20
+ File.write '.bb8_bundle', voltos_bundle
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :name, :voltos_bundle
26
+ end
@@ -0,0 +1,45 @@
1
+ class BB8::Commands::InitialiseProject
2
+ def self.call(path)
3
+ new(path).call
4
+ end
5
+
6
+ def initialize(path)
7
+ @path = File.expand_path path
8
+ end
9
+
10
+ def call
11
+ FileUtils.mkdir_p path
12
+
13
+ `git init #{path}` unless git_present?
14
+ add_gitignore unless gitignore_present?
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :path
20
+
21
+ def add_gitignore
22
+ File.write gitignore_path, <<-INPUT
23
+ .env
24
+ */.env
25
+ *.tfvars
26
+ */*.tfvars
27
+ *.tfstate
28
+ *.tfstate.backup
29
+ */*.tfstate
30
+ */*.tfstate.backup
31
+ INPUT
32
+ end
33
+
34
+ def gitignore_path
35
+ File.join(path, '.gitignore')
36
+ end
37
+
38
+ def git_present?
39
+ File.exist? File.join(path, '.git')
40
+ end
41
+
42
+ def gitignore_present?
43
+ File.exist? gitignore_path
44
+ end
45
+ end
@@ -0,0 +1,39 @@
1
+ class BB8::Commands::Terraform
2
+ def self.call(environment, command, *arguments)
3
+ new(environment, command, *arguments).call
4
+ end
5
+
6
+ def initialize(environment, command, *arguments)
7
+ @environment, @command, @arguments = environment, command, arguments
8
+ end
9
+
10
+ def call
11
+ `git pull origin`
12
+
13
+ Dir.chdir environment
14
+
15
+ BB8::SetEncryptionKeys.call
16
+
17
+ `cp ../common.tf common.tf` if File.exist?('../common.tf')
18
+ Dir['*.enc'].each { |path| BB8::Decrypt.call path }
19
+
20
+ system "terraform #{command} #{arguments.join(' ')}"
21
+
22
+ Dir['*.tfvars'].each { |path| BB8::Encrypt.call path }
23
+ Dir['*.tfstate'].each { |path| BB8::Encrypt.call path }
24
+ Dir['*.tfstate.backup'].each { |path| BB8::Encrypt.call path }
25
+
26
+ Dir.chdir '..'
27
+ `git add .`
28
+ `git commit -m "[bb8] Update Terraform files after running #{command}"`
29
+ `git push origin`
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :environment, :command, :arguments
35
+
36
+ def voltos_bundle
37
+ @voltos_bundle ||= File.read('.bb8_bundle')
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ class BB8::Commands::Version
2
+ def self.call
3
+ puts "BB-8 Version #{BB8::VERSION}"
4
+ end
5
+ end
@@ -0,0 +1,37 @@
1
+ class BB8::Decrypt
2
+ def self.call(path)
3
+ new(path).call
4
+ end
5
+
6
+ def initialize(path)
7
+ @path = path
8
+ end
9
+
10
+ def call
11
+ cipher.decrypt
12
+ cipher.key = variables['BB8_SECRET_KEY']
13
+ cipher.iv = variables['BB8_SECRET_IV']
14
+
15
+ buffer = ""
16
+ File.open(path.gsub('.enc', ''), "wb") do |output|
17
+ File.open(path, "rb") do |input|
18
+ while input.read(4096, buffer)
19
+ output << cipher.update(buffer)
20
+ end
21
+ output << cipher.final
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :path
29
+
30
+ def cipher
31
+ @cipher ||= OpenSSL::Cipher.new('aes-256-cbc')
32
+ end
33
+
34
+ def variables
35
+ @variables ||= BB8::VoltosVariables.call
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ class BB8::Encrypt
2
+ def self.call(path)
3
+ new(path).call
4
+ end
5
+
6
+ def initialize(path)
7
+ @path = path
8
+ end
9
+
10
+ def call
11
+ cipher.encrypt
12
+ cipher.key = variables['BB8_SECRET_KEY']
13
+ cipher.iv = variables['BB8_SECRET_IV']
14
+
15
+ buffer = ""
16
+ File.open("#{path}.enc", "wb") do |output|
17
+ File.open(path, "rb") do |input|
18
+ while input.read(4096, buffer)
19
+ output << cipher.update(buffer)
20
+ end
21
+ output << cipher.final
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :path
29
+
30
+ def cipher
31
+ @cipher ||= OpenSSL::Cipher.new('aes-256-cbc')
32
+ end
33
+
34
+ def variables
35
+ @variables ||= BB8::VoltosVariables.call
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ class BB8::SetEncryptionKeys
2
+ def self.call
3
+ new.call
4
+ end
5
+
6
+ def call
7
+ return if variables['BB8_SECRET_KEY']
8
+
9
+ `voltos set BB8_SECRET_KEY=#{SecureRandom.hex(16)}`
10
+ `voltos set BB8_SECRET_IV=#{SecureRandom.hex(8)}`
11
+ end
12
+
13
+ private
14
+
15
+ def variables
16
+ @variables ||= BB8::VoltosVariables.call
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module BB8
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,16 @@
1
+ class BB8::VoltosVariables
2
+ def self.call
3
+ new.call
4
+ end
5
+
6
+ def call
7
+ Voltos.configuration.api_key = voltos_api_key
8
+ Voltos.load
9
+ end
10
+
11
+ private
12
+
13
+ def voltos_api_key
14
+ @voltos_api_key ||= File.read('.env')[/VOLTOS_KEY=(\w+)/, 1]
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bb8
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pat Allan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: voltos
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ description:
42
+ email:
43
+ - pat@freelancing-gods.com
44
+ executables:
45
+ - bb8
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".travis.yml"
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - README.markdown
54
+ - Rakefile
55
+ - bb8.gemspec
56
+ - bin/console
57
+ - bin/setup
58
+ - exe/bb8
59
+ - lib/bb8.rb
60
+ - lib/bb8/cli.rb
61
+ - lib/bb8/commands/environment.rb
62
+ - lib/bb8/commands/help.rb
63
+ - lib/bb8/commands/initialise_environment.rb
64
+ - lib/bb8/commands/initialise_project.rb
65
+ - lib/bb8/commands/terraform.rb
66
+ - lib/bb8/commands/version.rb
67
+ - lib/bb8/decrypt.rb
68
+ - lib/bb8/encrypt.rb
69
+ - lib/bb8/set_encryption_keys.rb
70
+ - lib/bb8/version.rb
71
+ - lib/bb8/voltos_variables.rb
72
+ homepage: https://github.com/pat/bb8
73
+ licenses: []
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.5.1
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Manage and share Terraform variables, environments, and states securely.
95
+ test_files: []
96
+ has_rdoc: