vt 0.8.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.
@@ -0,0 +1,6 @@
1
+ Gemfile.lock
2
+ .DS_Store
3
+ results.html
4
+ pkg
5
+ html
6
+ .vagrant/
@@ -0,0 +1 @@
1
+ 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vt.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Andy Bashelor
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,115 @@
1
+ ## vt
2
+
3
+ A simple command line interface for interacting with the [Vault Tree] library.
4
+
5
+ [Vault Tree]: http://vaulttree.github.io
6
+
7
+ ### Background
8
+
9
+ _vt_ is meant to be a very light interface around the [Vault Tree] Ruby library.
10
+
11
+ Take a look at the [homepage] and [library] before you begin to learn more about the overall project.
12
+
13
+ [homepage]: http://vaulttree.github.io
14
+ [library]: https://github.com/VaultTree/vault-tree
15
+ [Vault Tree]: http://vaulttree.github.io
16
+
17
+ ### Install
18
+
19
+ ```
20
+ gem install vt
21
+ ```
22
+
23
+ ### Usage
24
+
25
+ Like many of your favorite UNIX tools, _vt_ operates as a filter in the _STDIN_ and _STDOUT_ stream. Pipe your Vault Tree JSON contract into _vt_ and simply specify which vault you want to open or close.
26
+
27
+ #### Closing Vaults
28
+
29
+ When the vault you are closing requires no external input do this:
30
+
31
+ ```shell
32
+ cat /path/to/your_contract.json | vt close vault_id
33
+ ```
34
+
35
+ This command sends the newly modified JSON contract back to _STDOUT_.
36
+
37
+ To save changes to your contract, just pipe _vt_ output to a text file.
38
+
39
+ ```shell
40
+ cat ~/my_contract.json | vt close_vault vault_id > ~/my_modified_contract.json
41
+ ```
42
+
43
+ #### Opening Vaults
44
+
45
+ Again, with no external input simply:
46
+
47
+ ```shell
48
+ cat /path/to/your_contract.json | vt open vault_id
49
+ ```
50
+
51
+ This will send the contents of the specified vault to _STDOUT_.
52
+
53
+ #### Formating Contracts
54
+
55
+ Take a look at this command:
56
+
57
+ ```shell
58
+ cat /path/to/your_contract.json | vt format
59
+ ```
60
+
61
+ This will add some nice coloring and line indentation to make it easier to read
62
+ your contract in the terminal.
63
+
64
+ Since `vt close <id>` always returns a contract, you may want do something like this:
65
+
66
+ ```shell
67
+ cat ~/my_contract.json | vt close_vault vault_id | vt format
68
+ ```
69
+
70
+ to get a better look at your modified contract.
71
+
72
+ ##### Not Valid JSON
73
+
74
+ Remember, the `vt format` command changes the bytes on your contract string and invalidates the JSON. Only use this command to help make your terminal output more readable.
75
+
76
+ #### External Input
77
+
78
+ _vt_ allows you to pass external input into your contract via shell variables.
79
+
80
+ For example, suppose you have a `contract.json` file in your `~/` dir and it looks like
81
+ this:
82
+
83
+ ```javascript
84
+
85
+ {
86
+ "header": {},
87
+ "vaults": {
88
+ "message":{
89
+ "description": "a simple message",
90
+ "fill_with": "EXTERNAL_INPUT['msg']",
91
+ "lock_with": "EXTERNAL_KEY['my_secret']",
92
+ "unlock_with": "EXTERNAL_KEY['my_secret']",
93
+ "contents": "25cc8ed8c75e665b911788bb5ba1520a05d96e8108868ef3d14c3b0aa45"
94
+
95
+ }
96
+ }
97
+ }
98
+
99
+ ```
100
+
101
+ To return the decrypted vault contents back to STDOUT you need to provide the Vault Tree Library with the value for _my_secret_.
102
+
103
+ When you issue the following command:
104
+
105
+ ```shell
106
+ cat ~/contract.json | vt open message my_secret
107
+ ```
108
+
109
+ The _vt_ cli assumes by convention there is a variable ` $my_secret ` defined
110
+ with the secret value in the current shell. This allows you to get sensitive data into Vault Tree without necessarily exposing it to your shell history logs.
111
+
112
+ Take a look at the [documentation] and the tests in the actual code libarary to get a better idea of how to properly reference external input within your contracts.
113
+
114
+ [documentation]: http://vaulttree.github.io
115
+
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'fileutils'
4
+
5
+ task :default => :test
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs << "spec"
9
+ t.test_files = FileList['spec/*_spec.rb']
10
+ end
@@ -0,0 +1,3 @@
1
+ Vagrant.configure("2") do |config|
2
+ config.vm.box = 'ruby-development'
3
+ end
data/bin/vt ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'methadone'
5
+ require 'vault-tree'
6
+ require 'vt'
7
+
8
+ class App
9
+ include Methadone::Main
10
+ include Methadone::CLILogging
11
+
12
+ main do |action, vault_id, *env_vars| # Add args you want: |like,so|
13
+ stdin_input = (STDIN.tty?) ? nil : $stdin.read;
14
+
15
+ # Be Careful about puts or STDOUT around here
16
+ # Results may be piped to next process
17
+
18
+ begin
19
+ Vt::CommandValidator.new(
20
+ stdin_input: stdin_input,
21
+ vault_id: vault_id,
22
+ env_vars: env_vars,
23
+ action: action
24
+ ).execute
25
+
26
+ case action
27
+ when 'open'
28
+ STDOUT.puts Vt::OpenCommand.new(
29
+ stdin_input: stdin_input,
30
+ vault_id: vault_id,
31
+ env_vars: env_vars
32
+ ).execute
33
+ when 'close'
34
+ STDOUT.puts Vt::CloseCommand.new(
35
+ stdin_input: stdin_input,
36
+ vault_id: vault_id,
37
+ env_vars: env_vars
38
+ ).execute
39
+ when 'format'
40
+ STDOUT.puts Vt::FormatCommand.new(stdin_input).execute
41
+ end
42
+
43
+ rescue(ArgumentError) => e
44
+ STDERR.puts e.message
45
+ return 1
46
+ end
47
+ end
48
+
49
+ # supplemental methods here
50
+
51
+ # Declare command-line interface here
52
+
53
+ # description "one line description of your app"
54
+ #
55
+ # Accept flags via:
56
+ # on("--flag VAL","Some flag")
57
+ # options[flag] will contain VAL
58
+ #
59
+ # Specify switches via:
60
+ # on("--[no-]switch","Some switch")
61
+ #
62
+ # Or, just call OptionParser methods on opts
63
+ #
64
+ # Require an argument
65
+ # arg :some_arg
66
+ #
67
+ # # Make an argument optional
68
+ # arg :optional_arg, :optional
69
+
70
+ version Vt::VERSION
71
+
72
+ use_log_level_option
73
+
74
+ go!
75
+ end
@@ -0,0 +1,8 @@
1
+ require "vt/version"
2
+ require "vt/command_validator"
3
+ require "vt/close_command"
4
+ require "vt/open_command"
5
+ require "vt/format_command"
6
+
7
+ module Vt
8
+ end
@@ -0,0 +1,25 @@
1
+ module Vt
2
+ class CloseCommand
3
+ attr_reader :stdin_input, :env_vars, :vault_id
4
+
5
+ def initialize(opts)
6
+ @stdin_input = opts[:stdin_input]
7
+ @env_vars = opts[:env_vars]
8
+ @vault_id = opts[:vault_id]
9
+ end
10
+
11
+ def execute
12
+ contract.close_vault(vault_id, external_data_hash)
13
+ end
14
+
15
+ private
16
+
17
+ def contract
18
+ VaultTree::Contract.new(stdin_input)
19
+ end
20
+
21
+ def external_data_hash
22
+ r = {}; env_vars.each{|v| r[v.to_sym] = ENV["#{v}"]}; r;
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,68 @@
1
+ module Vt
2
+ class CommandValidator
3
+ attr_reader :stdin_input, :action, :env_vars, :vault_id
4
+
5
+ def initialize(opts)
6
+ @stdin_input = opts[:stdin_input]
7
+ @action = opts[:action]
8
+ @env_vars = opts[:env_vars]
9
+ @vault_id = opts[:vault_id]
10
+ end
11
+
12
+ def execute
13
+ return if action == 'format'
14
+ validate_stdin
15
+ validate_vault_action
16
+ validate_vault_id
17
+ validate_env_vars
18
+ end
19
+
20
+ private
21
+
22
+ def validate_stdin
23
+ raise(ArgumentError, stdin_msg) if stdin_input.nil?
24
+ end
25
+
26
+ def stdin_msg
27
+ 'vt expects stdin to be piped in'
28
+ end
29
+
30
+ def validate_vault_action
31
+ raise(ArgumentError, action_msg) unless valid_action?
32
+ end
33
+
34
+ def action_msg
35
+ 'unsupported vault action'
36
+ end
37
+
38
+ def validate_vault_id
39
+ raise(ArgumentError, vault_id_msg) unless valid_vault_id?
40
+ end
41
+
42
+ def vault_id_msg
43
+ 'vault_id not provided'
44
+ end
45
+
46
+ def validate_env_vars
47
+ env_vars.each do |v|
48
+ raise(ArgumentError, env_var_msg(v)) if undefined_env_var?(v)
49
+ end
50
+ end
51
+
52
+ def undefined_env_var?(v)
53
+ ENV["#{v}"].nil? || ENV["#{v}"].empty?
54
+ end
55
+
56
+ def env_var_msg(v)
57
+ "cant find shell variable named #{v}"
58
+ end
59
+
60
+ def valid_action?
61
+ ['open','close','format'].include?(action)
62
+ end
63
+
64
+ def valid_vault_id?
65
+ !vault_id.nil? && !vault_id.empty?
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,71 @@
1
+ require 'json'
2
+ module Vt
3
+ class FormatCommand
4
+ attr_reader :raw_contract, :colored_contract, :compressed_contract
5
+
6
+ def initialize(c)
7
+ @raw_contract = c
8
+ end
9
+
10
+ def execute
11
+ @formated_contract, @colored_contract, @compressed_contract = ""
12
+ @formated_contract = color_vault_contents(raw_contract)
13
+ @formated_contract = compress_vault_contents(colored_contract)
14
+ @formated_contract
15
+ end
16
+
17
+ private
18
+
19
+
20
+ def contract
21
+ JSON.parse(raw_contract)
22
+ end
23
+
24
+ def color_vault_contents(c)
25
+ @colored_contract = c
26
+ vault_keys.each{|v| @colored_contract = @colored_contract.gsub(raw_vault_contents(v), colored_vault_contents(v))}
27
+ @colored_contract
28
+ end
29
+
30
+ def compress_vault_contents(c)
31
+ @compressed_contract = c
32
+ vault_keys.each{|v| @compressed_contract = @compressed_contract.gsub(raw_vault_contents(v), compressed_vault_contents(v))}
33
+ @compressed_contract
34
+ end
35
+
36
+ def vault_keys
37
+ contract['vaults'].keys
38
+ end
39
+
40
+ def raw_vault_contents(v)
41
+ contract['vaults'][v]['contents']
42
+ end
43
+
44
+ def colored_vault_contents(v)
45
+ contract['vaults'][v]['contents'].yellow
46
+ end
47
+
48
+ def compressed_vault_contents(v)
49
+ contract['vaults'][v]['contents'].compressed
50
+ end
51
+
52
+ end
53
+ end
54
+
55
+ class String
56
+ def yellow
57
+ colorize(33)
58
+ end
59
+
60
+ def colorize(color_code)
61
+ "\e[#{color_code}m#{self}\e[0m"
62
+ end
63
+
64
+ def compressed
65
+ gsub(/(.{60})(?=.)/, '\1 \2').gsub(' ',"\n").gsub("\n","\n #{blank_spaces(18)}")
66
+ end
67
+
68
+ def blank_spaces(number)
69
+ x = ''; number.times{x = x + ' '}; x;
70
+ end
71
+ end
@@ -0,0 +1,25 @@
1
+ module Vt
2
+ class OpenCommand
3
+ attr_reader :stdin_input, :env_vars, :vault_id
4
+
5
+ def initialize(opts)
6
+ @stdin_input = opts[:stdin_input]
7
+ @env_vars = opts[:env_vars]
8
+ @vault_id = opts[:vault_id]
9
+ end
10
+
11
+ def execute
12
+ contract.open_vault(vault_id, external_data_hash)
13
+ end
14
+
15
+ private
16
+
17
+ def contract
18
+ VaultTree::Contract.new(stdin_input)
19
+ end
20
+
21
+ def external_data_hash
22
+ r = {}; env_vars.each{|v| r[v.to_sym] = ENV["#{v}"]}; r;
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Vt
2
+ VERSION = "0.8.0"
3
+ end
@@ -0,0 +1,2 @@
1
+ # Run From Project Root to test CLI Comands
2
+ # export VAULT_MESSAGE='HEY NOW HEY NOW HEY HEY NOW HEY NOW'; cat spec/fixtures/test_with_env_vars.json | bundle exec bin/vt close test_vault VAULT_MESSAGE | bundle exec bin/vt format
@@ -0,0 +1,65 @@
1
+ require "minitest"
2
+ require "minitest/autorun"
3
+ require_relative '../lib/vt/close_command'
4
+
5
+ module ValidInputDouble
6
+ def self.stdin
7
+ %Q{
8
+ {
9
+ "header": {},
10
+ "vaults": {
11
+ "test_vault":{
12
+ "description":"Random Number",
13
+ "fill_with": "RANDOM_NUMBER",
14
+ "lock_with": "UNLOCKED",
15
+ "unlock_with": "UNLOCKED",
16
+ "contents": ""
17
+ }
18
+ }
19
+ }
20
+ }
21
+ end
22
+ end
23
+
24
+ module VaultTree
25
+ class Contract
26
+ def initialize(a = nil)
27
+ end
28
+
29
+ def open_vault(vault_id, external_data = {})
30
+ 'RETURN_STRING'
31
+ end
32
+
33
+ def close_vault(vault_id, external_data = {})
34
+ if external_data == expected_hash
35
+ %Q[{"closed":"contract_with_env_vars"}]
36
+ else
37
+ %Q[{"closed":"contract"}]
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def expected_hash
44
+ { data_var_one: ENV['data_var_one'], data_var_two: ENV['data_var_two']}
45
+ end
46
+
47
+ end
48
+ end
49
+
50
+ describe Vt::CloseCommand do
51
+ describe "#execute" do
52
+
53
+ it "can tell Vault Tree lib to close vault" do
54
+ opts = {
55
+ stdin_input: ValidInputDouble.stdin,
56
+ action: 'close',
57
+ vault_id: "test_vault",
58
+ env_vars: []
59
+ }
60
+ @response = Vt::CloseCommand.new(opts).execute
61
+ @response.must_equal %Q[{"closed":"contract"}]
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,83 @@
1
+ require "minitest/autorun"
2
+ require "minitest/spec"
3
+ require_relative '../lib/vt/command_validator'
4
+
5
+ module ValidInputDouble
6
+ def self.stdin
7
+ %Q{
8
+ {
9
+ "header": {},
10
+ "vaults": {
11
+ "test_vault":{
12
+ "description":"Random Number",
13
+ "fill_with": "RANDOM_NUMBER",
14
+ "lock_with": "UNLOCKED",
15
+ "unlock_with": "UNLOCKED",
16
+ "contents": ""
17
+ }
18
+ }
19
+ }
20
+ }
21
+ end
22
+ end
23
+
24
+ module Vt
25
+ describe CommandValidator do
26
+
27
+ it 'raises if the action is not open, close, or format' do
28
+ opts = {
29
+ stdin_input: ValidInputDouble.stdin,
30
+ action: 'something_else',
31
+ vault_id: "test_vault",
32
+ env_vars: []
33
+ }
34
+ begin
35
+ Vt::CommandValidator.new(opts).execute
36
+ rescue =>e
37
+ e.message.must_equal('unsupported vault action')
38
+ end
39
+ end
40
+
41
+ it 'raises if a vault_id is not given' do
42
+ opts = {
43
+ stdin_input: ValidInputDouble.stdin,
44
+ action: 'open',
45
+ vault_id: nil,
46
+ env_vars: []
47
+ }
48
+ begin
49
+ Vt::CommandValidator.new(opts).execute
50
+ rescue =>e
51
+ e.message.must_equal('vault_id not provided')
52
+ end
53
+ end
54
+
55
+ it 'raises if stdin is nil' do
56
+ opts = {
57
+ stdin_input: nil,
58
+ action: 'close',
59
+ vault_id: 'test_vault',
60
+ env_vars: []
61
+ }
62
+ begin
63
+ Vt::CommandValidator.new(opts).execute
64
+ rescue =>e
65
+ e.message.must_equal('vt expects stdin to be piped in')
66
+ end
67
+ end
68
+
69
+ it 'raises of env variable values are not defined' do
70
+ opts = {
71
+ stdin_input: ValidInputDouble.stdin,
72
+ action: 'close',
73
+ vault_id: 'test_vault',
74
+ env_vars: ['undefined_var']
75
+ }
76
+ begin
77
+ Vt::CommandValidator.new(opts).execute
78
+ rescue =>e
79
+ e.message.must_include('cant find shell variable')
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,12 @@
1
+ {
2
+ "header": {},
3
+ "vaults": {
4
+ "test_vault":{
5
+ "description":"Random Number",
6
+ "fill_with": "RANDOM_NUMBER",
7
+ "lock_with": "UNLOCKED",
8
+ "unlock_with": "UNLOCKED",
9
+ "contents": ""
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "header": {},
3
+ "vaults": {
4
+ "test_vault":{
5
+ "description":"A Simple Message",
6
+ "fill_with": "EXTERNAL_INPUT['VAULT_MESSAGE']",
7
+ "lock_with": "UNLOCKED",
8
+ "unlock_with": "UNLOCKED",
9
+ "contents": ""
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,50 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require_relative '../lib/vt/format_command.rb'
4
+
5
+ require 'json'
6
+ module ContractDoubles
7
+
8
+
9
+ def self.raw_contract
10
+ JSON.pretty_generate JSON.parse(unspaced_contract)
11
+ end
12
+
13
+ def self.unspaced_contract
14
+ %Q[
15
+ {
16
+ "header": {
17
+ },
18
+ "vaults": {
19
+ "subcontract_vault": {
20
+ "fill_with": "SUBCONTRACT['first_vault','second_vault']",
21
+ "lock_with": "UNLOCKED",
22
+ "unlock_with": "UNLOCKED",
23
+ "contents": "071298ea5ce8440db57560fcb90f299bfe1926936395c0eec9d10cb1fcc602ffdc77fbd2340d9a253dbc5aac0a999b46264bdd63b26e9888c6a09424fb1f9139452233bb9b8ed596096ce2ca91232f562d994efe945ef211b54c4fcd8f6485300b43f4f32d053bfdadba3b5897e50d31b7eedc879dcc7bdbe4a48b0c15e00cf4594af088edd5c6801c389de420bc147a5ad6378f32989aac8e4d66f986b817075527ea8489135043dbc06173df695540c9d09ed1a3f47c6125b4511476e9270d67df194ae4a17678cff2ca3d7abc7c45ca554e7fec900c6bab55fc00b1137118e1bd5f3c9a560e405be73ca6682c1122fe3bcf1a5673128ec817d7a649075b6e7cdd2a2c0ad20ca9ee6b73349c7f648a081b70ef89aab25ee91ddc8aa3fe9ada580abb05d920605ddbea21bcdd9c14c68e2d03ee524d90c807c983d57841ba27f4dcaa2e054ddb4c416b0e2e3aba5d3956c5a2728160cc81a204bf96e853481720cf53a9354d8cc7899dacec10dabc99261d9e3d7e845f89d931fc448c91fe33bea9ba5cd523e547f72893abedfcf76f567cdb5d5fea8ae43ea2d2939b52d3532d4d2689da3e112801b8ad925fb9fcec3ebe5e60c4b6a2483db2cdad6e4e7400475aaf2898414f13ed6697a6a2adc55ba252226487701a2bf557e923ecacd2361dbe06997a99f260c3da8bc46587fb533e3ab1d92e09f76081d2e7656133383fbaf73af329665403bf4ccc480589fb38168bac9f2b89cda38ded7fc67010900b6bf2bcfafc6345601aa9b1fa9f24af0a58bb12b7341007ebdde8c1b6eb35680fe5a8cbef3ec19df2246c4bc11f9d3cc45aba67ede916981d16048f4cf4804d2b26be8ebb0bcd8a9ffc4de96981a314c02233737a067059fc1c656f858c9efcfc14fa7b3b860c0ea86346e95cc5da9623bd3b491c0e73dbfcaf706e7d71b7a29f7a134b149dc9e3c0ea78d24f62af625f5e5a355676cade9c9bda49838359cdb3e7d6a37da324f8a67696b744639b63a941e15c7ec8d6c7e17a7f853153071e48c530676170221fbd5ff1eb32bc543733e12c5400df97de914dd0227288d5d83c8b4d2bcb308ea8682a7ad4a093a2cd99b3cb16d015b83f2ca3"
24
+ },
25
+ "first_vault": {
26
+ "fill_with": "RANDOM_NUMBER",
27
+ "lock_with": "UNLOCKED",
28
+ "unlock_with": "UNLOCKED",
29
+ "contents": "a7e11a20e0a8b11bd662f051b164c2a7bd70b433c67dbec00cd0e32d9246e5495b517b4f3c256c0937bf4877ede783fbf7794f1ebe2b59cd92a85dbe0cba4b143d02caadbd8e8e0f9c0fac08cec09f8616503e4df28e9f68714ce8c987bf8214df407db654173854"
30
+ },
31
+ "second_vault": {
32
+ "fill_with": "RANDOM_NUMBER",
33
+ "lock_with": "UNLOCKED",
34
+ "unlock_with": "UNLOCKED",
35
+ "contents": "25cc8ed8c75e665b911788bb5ba1520a05d96e8108868ef3d14c3b0aa45557bdcb6e01b689af82732f402589eedfc8d1751033544f922733ee7f705a07a347af77f4e9ec2ff90d3d15e6a5e2a721d23226b71861d546f067eeb81efabfeaf8e4a9691e5026a314d8"
36
+ }
37
+ }
38
+ }
39
+ ]
40
+ end
41
+ end
42
+
43
+ describe 'FormatCommand#execute' do
44
+
45
+ it 'can return the formated contract' do
46
+ @contract = ContractDoubles.raw_contract
47
+ @formated_contract = Vt::FormatCommand.new(@contract).execute
48
+ puts @formated_contract
49
+ end
50
+ end
@@ -0,0 +1,65 @@
1
+ require "minitest"
2
+ require "minitest/autorun"
3
+ require_relative '../lib/vt/open_command'
4
+
5
+ module ValidInputDouble
6
+ def self.stdin
7
+ %Q{
8
+ {
9
+ "header": {},
10
+ "vaults": {
11
+ "test_vault":{
12
+ "description":"Random Number",
13
+ "fill_with": "RANDOM_NUMBER",
14
+ "lock_with": "UNLOCKED",
15
+ "unlock_with": "UNLOCKED",
16
+ "contents": ""
17
+ }
18
+ }
19
+ }
20
+ }
21
+ end
22
+ end
23
+
24
+ module VaultTree
25
+ class Contract
26
+ def initialize(a = nil)
27
+ end
28
+
29
+ def open_vault(vault_id, external_data = {})
30
+ 'RETURN_STRING'
31
+ end
32
+
33
+ def close_vault(vault_id, external_data = {})
34
+ if external_data == expected_hash
35
+ %Q[{"closed":"contract_with_env_vars"}]
36
+ else
37
+ %Q[{"closed":"contract"}]
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def expected_hash
44
+ { data_var_one: ENV['data_var_one'], data_var_two: ENV['data_var_two']}
45
+ end
46
+
47
+ end
48
+ end
49
+
50
+ module Vt
51
+ describe OpenCommand do
52
+ describe "#execute" do
53
+ it "can tell Vault Tree lib to open vault" do
54
+ opts = {
55
+ stdin_input: ValidInputDouble.stdin,
56
+ action: 'open',
57
+ vault_id: "test_vault",
58
+ env_vars: []
59
+ }
60
+ @response = Vt::OpenCommand.new(opts).execute
61
+ @response.must_equal 'RETURN_STRING'
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vt/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vt"
8
+ spec.version = Vt::VERSION
9
+ spec.authors = ["Andy Bashelor"]
10
+ spec.email = ["abash1212@gmail.com"]
11
+ spec.description = "Vault Tree Command Line Application"
12
+ spec.summary = "CLI App for Vault Tree"
13
+ spec.homepage = "http://vaulttree.github.io"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec)/})
19
+ spec.require_paths = ["lib"]
20
+ spec.add_dependency "vault-tree", "0.8.0"
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_dependency('methadone', '~> 1.5.1')
23
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andy Bashelor
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: vault-tree
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: methadone
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.5.1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.1
62
+ description: Vault Tree Command Line Application
63
+ email:
64
+ - abash1212@gmail.com
65
+ executables:
66
+ - vt
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .ruby-version
72
+ - Gemfile
73
+ - Gemfile.lock
74
+ - LICENSE.txt
75
+ - README.md
76
+ - Rakefile
77
+ - Vagrantfile
78
+ - bin/vt
79
+ - lib/vt.rb
80
+ - lib/vt/close_command.rb
81
+ - lib/vt/command_validator.rb
82
+ - lib/vt/format_command.rb
83
+ - lib/vt/open_command.rb
84
+ - lib/vt/version.rb
85
+ - spec/cli_spec.rb
86
+ - spec/close_command_spec.rb
87
+ - spec/command_validator_spec.rb
88
+ - spec/fixtures/test_contract.json
89
+ - spec/fixtures/test_with_env_vars.json
90
+ - spec/format_command_spec.rb
91
+ - spec/open_command_spec.rb
92
+ - vt.gemspec
93
+ homepage: http://vaulttree.github.io
94
+ licenses:
95
+ - MIT
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 1.8.23
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: CLI App for Vault Tree
118
+ test_files:
119
+ - spec/cli_spec.rb
120
+ - spec/close_command_spec.rb
121
+ - spec/command_validator_spec.rb
122
+ - spec/fixtures/test_contract.json
123
+ - spec/fixtures/test_with_env_vars.json
124
+ - spec/format_command_spec.rb
125
+ - spec/open_command_spec.rb
126
+ has_rdoc: