bb8 0.2.0 → 0.3.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 +4 -4
- data/README.markdown +2 -2
- data/bb8.gemspec +1 -2
- data/lib/bb8.rb +2 -5
- data/lib/bb8/cli.rb +3 -1
- data/lib/bb8/commands/help.rb +3 -1
- data/lib/bb8/commands/initialise_environment.rb +15 -8
- data/lib/bb8/decrypt.rb +6 -6
- data/lib/bb8/encrypt.rb +6 -6
- data/lib/bb8/set_encryption_keys.rb +5 -5
- data/lib/bb8/version.rb +1 -1
- data/lib/bb8/voltos.rb +15 -0
- data/lib/bb8/voltos/api.rb +46 -0
- data/lib/bb8/voltos/bundle.rb +39 -0
- metadata +8 -23
- data/lib/bb8/commands/environment.rb +0 -10
- data/lib/bb8/voltos_api.rb +0 -34
- data/lib/bb8/voltos_variables.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f54c2857060d4c328cb1063a69c8fd294e062ee
|
4
|
+
data.tar.gz: 9fe628260d9068b4a3873fb6f4f37c5d6e82354e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cf2e2640ce2233cd262dfffc1361eae169edccf1afc9779ff62d35734a55fb4a6f27f57ede199c4ef89a3f2c415e4cbd473edbefb8bec795b99506a15595bff
|
7
|
+
data.tar.gz: 6da423cf3ddfe53d517be7b9430fb69f03baa5fe400d691665a1ee994e072922673661b8d41b742a0eb09e15e0744064c37dfb585a6f5cb99d7e5d7cf2d99f41
|
data/README.markdown
CHANGED
@@ -22,9 +22,9 @@ Then move into your project's directory (i.e. `cd servers`). You'll want to add
|
|
22
22
|
|
23
23
|
The next step is to set up an environment:
|
24
24
|
|
25
|
-
$ bb8 staging
|
25
|
+
$ bb8 environment staging my-servers-staging
|
26
26
|
|
27
|
-
The
|
27
|
+
The arguments are the name of the environment (in this case, `staging`), and the name of a bundle of Voltos settings. BB-8 will create the latter for you, if you've not already done so.
|
28
28
|
|
29
29
|
From this point on, you'll want to issue Terraform commands through BB-8 and a specified environment:
|
30
30
|
|
data/bb8.gemspec
CHANGED
@@ -20,8 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |file| File.basename(file) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_runtime_dependency "
|
24
|
-
spec.add_runtime_dependency "voltos", "~> 0.3"
|
23
|
+
spec.add_runtime_dependency "faraday", "~> 0.10.0"
|
25
24
|
|
26
25
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
26
|
end
|
data/lib/bb8.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'faraday'
|
2
2
|
require 'fileutils'
|
3
3
|
require 'json'
|
4
4
|
require 'openssl'
|
5
5
|
require 'securerandom'
|
6
|
-
require 'voltos'
|
7
6
|
|
8
7
|
module BB8
|
9
8
|
module Commands
|
@@ -11,7 +10,6 @@ module BB8
|
|
11
10
|
end
|
12
11
|
|
13
12
|
require 'bb8/cli'
|
14
|
-
require 'bb8/commands/environment'
|
15
13
|
require 'bb8/commands/help'
|
16
14
|
require 'bb8/commands/initialise_environment'
|
17
15
|
require 'bb8/commands/initialise_project'
|
@@ -21,5 +19,4 @@ require 'bb8/decrypt'
|
|
21
19
|
require 'bb8/encrypt'
|
22
20
|
require 'bb8/set_encryption_keys'
|
23
21
|
require 'bb8/version'
|
24
|
-
require 'bb8/
|
25
|
-
require 'bb8/voltos_variables'
|
22
|
+
require 'bb8/voltos'
|
data/lib/bb8/cli.rb
CHANGED
@@ -7,8 +7,10 @@ class BB8::CLI
|
|
7
7
|
BB8::Commands::InitialiseProject.call arguments[1]
|
8
8
|
when 'version'
|
9
9
|
BB8::Commands::Version.call
|
10
|
+
when 'environment'
|
11
|
+
BB8::Commands::InitialiseEnvironment.call arguments[1], arguments[2]
|
10
12
|
when *environments
|
11
|
-
BB8::Commands::
|
13
|
+
BB8::Commands::Terraform.call(*arguments)
|
12
14
|
else
|
13
15
|
BB8::Commands::Help.call
|
14
16
|
end
|
data/lib/bb8/commands/help.rb
CHANGED
@@ -7,10 +7,12 @@ Usage:
|
|
7
7
|
|
8
8
|
bb8 init . Set up a directory as a git
|
9
9
|
repository.
|
10
|
-
bb8
|
10
|
+
bb8 environment staging my-voltos-bundle Set up a directory for a specific
|
11
11
|
environment.
|
12
12
|
bb8 ENVIRONMENT [show|apply|destroy|...] Run a Terraform command within a
|
13
13
|
specific environment's context.
|
14
|
+
bb8 version Outputs BB8's version.
|
15
|
+
bb8 help Outputs this information.
|
14
16
|
MESSAGE
|
15
17
|
end
|
16
18
|
end
|
@@ -10,24 +10,31 @@ class BB8::Commands::InitialiseEnvironment
|
|
10
10
|
def call
|
11
11
|
FileUtils.mkdir_p name
|
12
12
|
Dir.chdir name
|
13
|
+
File.write '.bb8_bundle', voltos_bundle
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
BB8::Voltos::Bundle.create voltos_bundle unless bundle_exists?
|
16
|
+
append_token unless set_bundle?
|
16
17
|
BB8::SetEncryptionKeys.call
|
17
|
-
|
18
|
-
File.write '.bb8_bundle', voltos_bundle
|
19
18
|
end
|
20
19
|
|
21
20
|
private
|
22
21
|
|
23
22
|
attr_reader :name, :voltos_bundle
|
24
23
|
|
25
|
-
def
|
26
|
-
|
24
|
+
def append_token
|
25
|
+
File.open('.env', 'a') do |file|
|
26
|
+
file.puts "VOLTOS_KEY=#{bundle.token}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def bundle
|
31
|
+
@bundle ||= BB8::Voltos.bundles.detect { |bundle|
|
32
|
+
bundle.name == voltos_bundle
|
33
|
+
} || BB8::Voltos::Bundle.create(voltos_bundle)
|
27
34
|
end
|
28
35
|
|
29
|
-
def
|
30
|
-
|
36
|
+
def bundle_exists?
|
37
|
+
BB8::Voltos.bundles.collect(&:name).include? voltos_bundle
|
31
38
|
end
|
32
39
|
|
33
40
|
def set_bundle?
|
data/lib/bb8/decrypt.rb
CHANGED
@@ -9,8 +9,8 @@ class BB8::Decrypt
|
|
9
9
|
|
10
10
|
def call
|
11
11
|
cipher.decrypt
|
12
|
-
cipher.key = variables['BB8_SECRET_KEY']
|
13
|
-
cipher.iv = variables['BB8_SECRET_IV']
|
12
|
+
cipher.key = bundle.variables['BB8_SECRET_KEY']
|
13
|
+
cipher.iv = bundle.variables['BB8_SECRET_IV']
|
14
14
|
|
15
15
|
buffer = ""
|
16
16
|
File.open(path.gsub('.enc', ''), "wb") do |output|
|
@@ -27,11 +27,11 @@ class BB8::Decrypt
|
|
27
27
|
|
28
28
|
attr_reader :path
|
29
29
|
|
30
|
-
def
|
31
|
-
@
|
30
|
+
def bundle
|
31
|
+
@bundle ||= BB8::Voltos.current_bundle
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
35
|
-
@
|
34
|
+
def cipher
|
35
|
+
@cipher ||= OpenSSL::Cipher.new('aes-256-cbc')
|
36
36
|
end
|
37
37
|
end
|
data/lib/bb8/encrypt.rb
CHANGED
@@ -9,8 +9,8 @@ class BB8::Encrypt
|
|
9
9
|
|
10
10
|
def call
|
11
11
|
cipher.encrypt
|
12
|
-
cipher.key = variables['BB8_SECRET_KEY']
|
13
|
-
cipher.iv = variables['BB8_SECRET_IV']
|
12
|
+
cipher.key = bundle.variables['BB8_SECRET_KEY']
|
13
|
+
cipher.iv = bundle.variables['BB8_SECRET_IV']
|
14
14
|
|
15
15
|
buffer = ""
|
16
16
|
File.open("#{path}.enc", "wb") do |output|
|
@@ -27,11 +27,11 @@ class BB8::Encrypt
|
|
27
27
|
|
28
28
|
attr_reader :path
|
29
29
|
|
30
|
-
def
|
31
|
-
@
|
30
|
+
def bundle
|
31
|
+
@bundle ||= BB8::Voltos.current_bundle
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
35
|
-
@
|
34
|
+
def cipher
|
35
|
+
@cipher ||= OpenSSL::Cipher.new('aes-256-cbc')
|
36
36
|
end
|
37
37
|
end
|
@@ -4,15 +4,15 @@ class BB8::SetEncryptionKeys
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def call
|
7
|
-
return if variables['BB8_SECRET_KEY']
|
7
|
+
return if bundle.variables['BB8_SECRET_KEY']
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
bundle.set 'BB8_SECRET_KEY', SecureRandom.hex(16)
|
10
|
+
bundle.set 'BB8_SECRET_IV', SecureRandom.hex(8)
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
-
def
|
16
|
-
@
|
15
|
+
def bundle
|
16
|
+
@bundle ||= BB8::Voltos.current_bundle
|
17
17
|
end
|
18
18
|
end
|
data/lib/bb8/version.rb
CHANGED
data/lib/bb8/voltos.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class BB8::Voltos
|
2
|
+
def self.bundles
|
3
|
+
api = BB8::Voltos::API.new
|
4
|
+
api.get("bundles").collect { |hash|
|
5
|
+
BB8::Voltos::Bundle.new hash['name'], api
|
6
|
+
}
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.current_bundle
|
10
|
+
BB8::Voltos::Bundle.new File.read('.bb8_bundle')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'bb8/voltos/api'
|
15
|
+
require 'bb8/voltos/bundle'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class BB8::Voltos::API
|
2
|
+
DOMAIN = 'https://api.voltos.io'
|
3
|
+
VERSION = 'v1'
|
4
|
+
ENDPOINT = "#{DOMAIN}/#{VERSION}"
|
5
|
+
|
6
|
+
def get(path)
|
7
|
+
JSON.parse connection.get("#{VERSION}/#{path}").body
|
8
|
+
end
|
9
|
+
|
10
|
+
def put(path, params)
|
11
|
+
JSON.parse connection.put("#{VERSION}/#{path}", params).body
|
12
|
+
end
|
13
|
+
|
14
|
+
def post(path, params)
|
15
|
+
JSON.parse connection.post("#{VERSION}/#{path}", params).body
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_bundle(name)
|
19
|
+
JSON.parse connection.post("#{VERSION}/bundles", {
|
20
|
+
:name => name,
|
21
|
+
:token_name => 'BB8'
|
22
|
+
}).body
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def configuration
|
28
|
+
@configuration ||= JSON.parse(
|
29
|
+
File.read(File.expand_path('~/.voltos/config.json'))
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def connection
|
34
|
+
@connection ||= Faraday.new(:url => DOMAIN) do |faraday|
|
35
|
+
faraday.request :url_encoded
|
36
|
+
faraday.adapter Faraday.default_adapter
|
37
|
+
|
38
|
+
faraday.headers['User-Agent'] = "BB8/#{BB8::VERSION}"
|
39
|
+
faraday.headers['Authorization'] = "Token token=#{token}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def token
|
44
|
+
configuration['auths']["#{ENDPOINT}"]['auth']
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class BB8::Voltos::Bundle
|
2
|
+
attr_reader :name
|
3
|
+
|
4
|
+
def self.create(name, api = nil)
|
5
|
+
api ||= BB8::Voltos::API.new
|
6
|
+
response = api.post("bundles", {
|
7
|
+
:name => name,
|
8
|
+
:token_name => 'BB8'
|
9
|
+
})
|
10
|
+
|
11
|
+
new name, api, response['token']
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(name, api = nil, token = nil)
|
15
|
+
@name = name
|
16
|
+
@api = api || BB8::Voltos::API.new
|
17
|
+
@token = token
|
18
|
+
end
|
19
|
+
|
20
|
+
def set(key, value)
|
21
|
+
api.put "/bundles/#{name}", "#{key}=#{value}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def token
|
25
|
+
@token || new_token
|
26
|
+
end
|
27
|
+
|
28
|
+
def variables
|
29
|
+
@variables ||= api.get "/bundles/#{name}"
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :api
|
35
|
+
|
36
|
+
def new_token
|
37
|
+
api.post("/bundles/#{name}/token", :name => name)['token']
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bb8
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Allan
|
@@ -11,33 +11,19 @@ cert_chain: []
|
|
11
11
|
date: 2016-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.10.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: voltos
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.3'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.3'
|
26
|
+
version: 0.10.0
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rspec
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,7 +58,6 @@ files:
|
|
72
58
|
- exe/bb8
|
73
59
|
- lib/bb8.rb
|
74
60
|
- lib/bb8/cli.rb
|
75
|
-
- lib/bb8/commands/environment.rb
|
76
61
|
- lib/bb8/commands/help.rb
|
77
62
|
- lib/bb8/commands/initialise_environment.rb
|
78
63
|
- lib/bb8/commands/initialise_project.rb
|
@@ -82,8 +67,9 @@ files:
|
|
82
67
|
- lib/bb8/encrypt.rb
|
83
68
|
- lib/bb8/set_encryption_keys.rb
|
84
69
|
- lib/bb8/version.rb
|
85
|
-
- lib/bb8/
|
86
|
-
- lib/bb8/
|
70
|
+
- lib/bb8/voltos.rb
|
71
|
+
- lib/bb8/voltos/api.rb
|
72
|
+
- lib/bb8/voltos/bundle.rb
|
87
73
|
homepage: https://github.com/pat/bb8
|
88
74
|
licenses:
|
89
75
|
- MIT
|
@@ -104,9 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
90
|
version: '0'
|
105
91
|
requirements: []
|
106
92
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.5.
|
93
|
+
rubygems_version: 2.5.2
|
108
94
|
signing_key:
|
109
95
|
specification_version: 4
|
110
96
|
summary: Manage and share Terraform variables, environments, and states securely.
|
111
97
|
test_files: []
|
112
|
-
has_rdoc:
|
@@ -1,10 +0,0 @@
|
|
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
|
data/lib/bb8/voltos_api.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
class BB8::VoltosAPI
|
2
|
-
DOMAIN = 'https://api.voltos.io'
|
3
|
-
VERSION = 'v1'
|
4
|
-
ENDPOINT = "#{DOMAIN}/#{VERSION}"
|
5
|
-
|
6
|
-
def bundles
|
7
|
-
JSON.parse Curl.get("#{ENDPOINT}/bundles") { |http|
|
8
|
-
http.headers['User-Agent'] = "BB8/#{BB8::VERSION}"
|
9
|
-
http.headers['Authorization'] = "Token token=#{token}"
|
10
|
-
}.body_str
|
11
|
-
end
|
12
|
-
|
13
|
-
def create_bundle(name)
|
14
|
-
JSON.parse Curl.post("#{ENDPOINT}/bundles", {
|
15
|
-
:name => name,
|
16
|
-
:token_name => 'BB8'
|
17
|
-
}) { |http|
|
18
|
-
http.headers['User-Agent'] = "BB8/#{BB8::VERSION}"
|
19
|
-
http.headers['Authorization'] = "Token token=#{token}"
|
20
|
-
}.body_str
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def configuration
|
26
|
-
@configuration ||= JSON.parse(
|
27
|
-
File.read(File.expand_path('~/.voltos/config.json'))
|
28
|
-
)
|
29
|
-
end
|
30
|
-
|
31
|
-
def token
|
32
|
-
configuration['auths']["#{ENDPOINT}"]['auth']
|
33
|
-
end
|
34
|
-
end
|
data/lib/bb8/voltos_variables.rb
DELETED
@@ -1,16 +0,0 @@
|
|
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
|