app-rb 0.6.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8058d7410253117a512ac4aaaa078c2f82c8499
4
- data.tar.gz: afc3acbf56448540887b2a6f52c12568c48f0bac
3
+ metadata.gz: e711d636dadff50ef85e9a5d2d064966b3effc49
4
+ data.tar.gz: b73199db204a95a85669ed40c690449f152923c2
5
5
  SHA512:
6
- metadata.gz: d0d030ecece01d4ae12096134054c0bc77d174ae1842d437ed5bba2ffeadf7b3751f3d7463404f0bc3824cb54f9725a0aa615564f698a11f44d2e895a19ed7c8
7
- data.tar.gz: e235501568640bcdc2f5f61b1c87b74c939fd04706112565f9c4def9fbc3df10f95dac4e1e09f8e737aa63b8a4e515a76599beea2540c4c9db596d0848a31177
6
+ metadata.gz: 691263ddcd9e2bebdb6076bc2dfda71a7aab9cd9dbf978da5cb5b16808fa345b6b08ef5d99573ea4503c90f55388283c4c1997cfe6d7dda36edf7d13e6cc48ac
7
+ data.tar.gz: 4c0b4ca076d63fca41eec03907b13f26a1ad0475ffbe62a69ea153c8cd37a56e4cf3ec37b983e2e8a9ba44c37d994a2b8d13aa06ef767fffeba5e6bfd6708bde
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## App-rb 0.7.0 (April 13, 2017) ##
2
+
3
+ * Support crypting of sensitive information using vault file as key.
4
+
1
5
  ## App-rb 0.6.0 (April 10, 2017) ##
2
6
 
3
7
  * Add kind and name labels to each docker image.
data/lib/app-rb/cli.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'openssl'
2
3
 
3
4
  module AppRb
4
5
  class Cli
@@ -12,17 +13,30 @@ module AppRb
12
13
  usage
13
14
  exit
14
15
  end
15
- config = Config.new(YAML.load(File.read(@args[0])))
16
- command = @args[1]
16
+ if File.exists?(@args[0])
17
+ config_path = @args.shift
18
+ end
19
+
20
+ if @args[0] == "--vault" && File.exists?(@args[1])
21
+ @args.shift
22
+ @vault_file = @args.shift
23
+ elsif File.exists?(File.join(Dir.pwd, "vault.key"))
24
+ @vault_file = File.join(Dir.pwd, "vault.key")
25
+ else
26
+ @vault_file = nil
27
+ end
28
+
29
+ command = @args.shift
30
+ config = Config.new(read_yaml(config_path)) if config_path
17
31
 
18
- if AppRb::Util.compare_versions(config.tool_version, AppRb::VERSION) > 0
32
+ if config && AppRb::Util.compare_versions(config.tool_version, AppRb::VERSION) > 0
19
33
  puts "FATAL: need at least '#{config.tool_version}' tool version but current version is '#{AppRb::VERSION}'"
20
34
  exit -1
21
35
  end
22
36
 
23
- if command == "deploy" || command == "d"
37
+ if %w[deploy d].index(command)
24
38
  Command.new(config).deploy(@args[2])
25
- elsif command == "status" || command == "s"
39
+ elsif %w[status s].index(command)
26
40
  Command.new(config).status
27
41
  elsif command == "redeploy"
28
42
  Command.new(config).redeploy
@@ -30,10 +44,14 @@ module AppRb
30
44
  Command.new(config).clean
31
45
  elsif command == "stop"
32
46
  Command.new(config).stop
33
- elsif command == "run" || command == "r"
47
+ elsif %w[run r].index(command)
34
48
  Command.new(config).run(@args[2..-1].join(" "))
35
49
  elsif command == "cd"
36
50
  Command.new(config).cd
51
+ elsif %w[encrypt en e].index(command)
52
+ puts encrypt(@args.shift)
53
+ elsif %w[decrypt de].index(command)
54
+ puts decrypt(@args.shift)
37
55
  else
38
56
  puts "FATAL: unknown command '#{command}'"
39
57
  exit -1
@@ -41,21 +59,79 @@ module AppRb
41
59
  end
42
60
 
43
61
  private
62
+ MARKER = "__VAULT:"
63
+
64
+ def read_yaml(file)
65
+ unvault = proc { |o|
66
+ if o.is_a?(Array)
67
+ o.map { |i| unvault.call(i) }
68
+ elsif o.is_a?(Hash)
69
+ o.map { |k, v| [k, unvault.call(v)] }.to_h
70
+ elsif o.is_a?(String) && o.index(MARKER) == 0
71
+ decrypt(o)
72
+ else
73
+ o
74
+ end
75
+ }
76
+ unvault.call(YAML.load(File.read(file)))
77
+ end
78
+
79
+ def die(msg = nil)
80
+ if msg
81
+ puts "FATAL: #{msg}"
82
+ else
83
+ puts "exit with status code -1"
84
+ end
85
+ exit -1
86
+ end
87
+
88
+ def bin_to_hex(s)
89
+ s.unpack('H*').first
90
+ end
91
+
92
+ def hex_to_bin(s)
93
+ s.scan(/../).map { |x| x.hex }.pack('c*')
94
+ end
95
+
96
+ def encrypt(string)
97
+ die "missed vault file" unless @vault_file
98
+ die "string encrypted yet" if string.index(MARKER) == 0
99
+ cipher = OpenSSL::Cipher::AES256.new :CBC
100
+ cipher.encrypt
101
+ iv = cipher.random_iv
102
+ cipher.key = Digest::SHA256.digest(File.read(@vault_file).strip)
103
+ MARKER + bin_to_hex(cipher.update(string) + cipher.final) + ":" + bin_to_hex(iv)
104
+ end
105
+
106
+ def decrypt(string)
107
+ die "missed vault file" unless @vault_file
108
+ die "string not encrypted" unless string.index(MARKER) == 0
109
+ cipher = OpenSSL::Cipher::AES256.new :CBC
110
+ cipher.decrypt
111
+ cipher.iv = hex_to_bin(string.sub(MARKER, "").split(":")[1])
112
+ cipher.key = Digest::SHA256.digest(File.read(@vault_file).strip)
113
+ cipher.update(hex_to_bin(string.sub(MARKER, "").split(":")[0])) + cipher.final
114
+ end
44
115
 
45
116
  def usage
46
117
  puts "Just deploy your apps with docker and consul. Nothing else."
47
118
  puts "Version: #{AppRb::VERSION}"
48
119
  puts ""
49
- puts " app-rb <yml> <command>"
120
+ puts " app-rb <yml> [options] <command>"
121
+ puts ""
122
+ puts "Options:"
123
+ puts " --vault <vault-file> - vault file (<pwd>/vault.key by default)"
50
124
  puts ""
51
- puts "Usage:"
125
+ puts "Commands:"
52
126
  puts " deploy [hash] - deploy new version of app"
53
127
  puts " status - status of app"
54
- puts " stop - stop app"
128
+ puts " stop - stop app completely"
55
129
  puts " run <cmd> [args] - one time command"
56
130
  puts " cd - go to run node"
131
+ puts " encrypt <string> - encrypt script using vault-file"
132
+ puts " decrypt <string> - decrypt script using vault-file"
57
133
  puts ""
58
- puts "Advanced:"
134
+ puts "Advanced commands:"
59
135
  puts " redeploy - redeploy app"
60
136
  puts " clean - stop and remove not current containers"
61
137
  end
@@ -1,3 +1,3 @@
1
1
  module AppRb
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Vakhov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-10 00:00:00.000000000 Z
11
+ date: 2017-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler