rgc 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENCE.txt +20 -0
- data/lib/rgc/arg_parser.rb +98 -0
- data/lib/rgc/clean.rb +20 -0
- data/lib/rgc/encrypt.rb +61 -0
- data/lib/rgc/init.rb +72 -0
- data/lib/rgc/key_file.rb +8 -0
- data/lib/rgc/keygen.rb +22 -0
- data/lib/rgc/smudge.rb +19 -0
- data/lib/rgc/version.rb +1 -1
- data/lib/rgc.rb +1 -0
- metadata +49 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db18bb2bbf0ad2550d898019063b04b6f725fb22
|
4
|
+
data.tar.gz: 2f133cdbdad21b2281fc055f461b27fd3feb86ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f084301fb16c44e24e2b324c7b96a16a20b05343d1d841224fc90acd6b7dcb11fc52a6bfc6de3b81c2f75f081d1bfdead761747a5f147c6205f1d73a2968d972
|
7
|
+
data.tar.gz: e41fa11f53ac3ba4b42f02afec4b82963d8fa377459c9e21623bc89f099f28d4084fdcb2a3548626f70190f427b66c0bc55e24a7361f8e8fd1ed89da09c162b3
|
data/LICENCE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Jiri Chara
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Rgc
|
2
|
+
class ArgParser
|
3
|
+
include GLI::App
|
4
|
+
|
5
|
+
def initialize(argv, argf)
|
6
|
+
program_desc 'Program to encrypt certain files inside git repository.'
|
7
|
+
|
8
|
+
version Rgc::VERSION
|
9
|
+
|
10
|
+
pre do |global,command,options,args|
|
11
|
+
# Pre logic here
|
12
|
+
# Return true to proceed; false to abort and not call the
|
13
|
+
# chosen command
|
14
|
+
# Use skips_pre before a command to skip this block
|
15
|
+
# on that command only
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
post do |global,command,options,args|
|
20
|
+
# Post logic here
|
21
|
+
# Use skips_post before a command to skip this
|
22
|
+
# block on that command only
|
23
|
+
end
|
24
|
+
|
25
|
+
on_error do |exception|
|
26
|
+
# Error logic here
|
27
|
+
# return false to skip default error handling
|
28
|
+
puts exception.backtrace
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
init_keygen
|
33
|
+
init_init
|
34
|
+
init_encrypt
|
35
|
+
init_clean
|
36
|
+
init_smudge
|
37
|
+
|
38
|
+
exit run(ARGV)
|
39
|
+
end
|
40
|
+
|
41
|
+
def init_keygen
|
42
|
+
desc('generate a rgc key in the given file')
|
43
|
+
|
44
|
+
command(:keygen) do |c|
|
45
|
+
|
46
|
+
c.action do |global_options, options, args|
|
47
|
+
Rgc::Keygen.new(global_options, options, args)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def init_init
|
53
|
+
desc('prepare git repository to use rgc with given key file')
|
54
|
+
|
55
|
+
command(:init) do |c|
|
56
|
+
|
57
|
+
c.action do |global_options, options, args|
|
58
|
+
Rgc::Init.new(global_options, options, args)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def init_clean
|
64
|
+
desc('encrypt content of STDIN and write to STDOUT')
|
65
|
+
|
66
|
+
command(:clean) do |c|
|
67
|
+
|
68
|
+
c.action do |global_options, options, args|
|
69
|
+
Rgc::Clean.new(global_options, options, args)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def init_smudge
|
75
|
+
desc('decrypt content of STDIN and write to STDOUT')
|
76
|
+
|
77
|
+
command(:smudge) do |c|
|
78
|
+
|
79
|
+
c.action do |global_options, options, args|
|
80
|
+
Rgc::Smudge.new(global_options, options, args)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def init_encrypt
|
86
|
+
desc('set files for encryption')
|
87
|
+
|
88
|
+
command(:encrypt) do |c|
|
89
|
+
|
90
|
+
c.flag [:yaml, :y], desc: "yaml values to encrypt"
|
91
|
+
|
92
|
+
c.action do |global_options, options, args|
|
93
|
+
Rgc::Encrypt.new(global_options, options, args)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/rgc/clean.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rgc
|
2
|
+
class Clean
|
3
|
+
include Rgc::KeyFile
|
4
|
+
|
5
|
+
def initialize(global_options, options, args)
|
6
|
+
load_key
|
7
|
+
|
8
|
+
print(encrypt(ARGF.read))
|
9
|
+
end
|
10
|
+
|
11
|
+
def encrypt(content)
|
12
|
+
@aes = OpenSSL::Cipher.new("AES-128-CBC")
|
13
|
+
@aes.encrypt
|
14
|
+
@aes.key = @key
|
15
|
+
# TODO: consinder to set @aes.iv
|
16
|
+
|
17
|
+
Base64.encode64(@aes.update(content) + @aes.final)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/rgc/encrypt.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module Rgc
|
2
|
+
class Encrypt
|
3
|
+
CONFIG = '.rgc.yml'
|
4
|
+
|
5
|
+
def initialize(global_options, options, args)
|
6
|
+
load_rgc_config
|
7
|
+
|
8
|
+
determine_encryption(args, options)
|
9
|
+
|
10
|
+
save_new_config
|
11
|
+
|
12
|
+
update_git_attributes
|
13
|
+
end
|
14
|
+
|
15
|
+
def determine_encryption(args, options)
|
16
|
+
args.each do |arg|
|
17
|
+
@encrypt[arg] = options.select do |k, v|
|
18
|
+
k == :yaml && v != nil
|
19
|
+
end
|
20
|
+
|
21
|
+
@encrypt[arg] = if @encrypt[arg].empty?
|
22
|
+
""
|
23
|
+
else
|
24
|
+
a = []
|
25
|
+
|
26
|
+
@encrypt[arg].each do |k,v|
|
27
|
+
a << "--#{k} #{v}"
|
28
|
+
end
|
29
|
+
|
30
|
+
a.join(" ")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def load_rgc_config
|
36
|
+
unless File.exists?(CONFIG)
|
37
|
+
abort "#{CONFIG} not found. Please run `rgc init` first."
|
38
|
+
end
|
39
|
+
|
40
|
+
@encrypt = YAML.load_file(CONFIG)
|
41
|
+
end
|
42
|
+
|
43
|
+
def save_new_config
|
44
|
+
f = File.open(CONFIG, 'w') do |f|
|
45
|
+
YAML::dump(@encrypt, f)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def update_git_attributes
|
50
|
+
unless File.exists?('.gitattributes')
|
51
|
+
abort '.gitattributes file not found. Please run `rgc init` first.'
|
52
|
+
end
|
53
|
+
|
54
|
+
File.open('.gitattributes', 'a') do |f|
|
55
|
+
@encrypt.each do |k, v|
|
56
|
+
f.puts("#{k} filter=rgc diff=rgc")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/rgc/init.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Rgc
|
2
|
+
class Init
|
3
|
+
def initialize(global_options, options, args)
|
4
|
+
abort "Key file must be given!" if (@key_file = args.first).nil?
|
5
|
+
|
6
|
+
begin
|
7
|
+
@secret = File.read(@key_file)
|
8
|
+
rescue
|
9
|
+
abort "Cannot read key file #{@key_file}"
|
10
|
+
end
|
11
|
+
|
12
|
+
begin
|
13
|
+
stdout, stderr, status = Open3.capture3("git status -uno --porcelain")
|
14
|
+
rescue Errno::ENOENT
|
15
|
+
abort "Cannot run `git status -uno --porcelain`."
|
16
|
+
end
|
17
|
+
|
18
|
+
unless status.exitstatus == 0
|
19
|
+
abort "git status failed - is this a git repository?"
|
20
|
+
end
|
21
|
+
|
22
|
+
unless stdout.length == 0
|
23
|
+
$stderr.puts "Working directory not clean"
|
24
|
+
abort "Please commit your changes or 'git stash' them."
|
25
|
+
end
|
26
|
+
|
27
|
+
init_rgc_config_file
|
28
|
+
|
29
|
+
unless File.exist?('.gitattributes')
|
30
|
+
begin
|
31
|
+
File.open('.gitattributes', 'w') {}
|
32
|
+
rescue Errno::EACCES
|
33
|
+
abort "Cannot open .gitattributes for writing."
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
add_git_config_options
|
38
|
+
end
|
39
|
+
|
40
|
+
def init_rgc_config_file
|
41
|
+
@config = Rgc::Encrypt::CONFIG
|
42
|
+
|
43
|
+
if File.exists?(@config)
|
44
|
+
validate_config_file(@config)
|
45
|
+
else
|
46
|
+
File.open(@config, 'w') { |f| YAML::dump({ rgc_key_file: @key_file }, f) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate_config_file
|
51
|
+
begin
|
52
|
+
raise unless YAML.load_file(@config).is_a?(Hash)
|
53
|
+
rescue
|
54
|
+
abort("Invalid rgc config file (#{@config}). Delete it or fix it.")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_git_config_options
|
59
|
+
smudge = "git config filter.smudge rgc smudge"
|
60
|
+
stdout, stderr, status_smudge = Open3.capture3(smudge)
|
61
|
+
|
62
|
+
clean = "git config filter.clean rgc clean"
|
63
|
+
stdout, stderr, status_clean = Open3.capture3(clean)
|
64
|
+
|
65
|
+
if [0, 0] != [status_smudge, status_clean]
|
66
|
+
abort "Cannot configure git."
|
67
|
+
end
|
68
|
+
rescue Errno::ENOENT
|
69
|
+
abort "Cannot configure git."
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/rgc/key_file.rb
ADDED
data/lib/rgc/keygen.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Rgc
|
2
|
+
class Keygen
|
3
|
+
def initialize(global_options, options, args)
|
4
|
+
if File.exists?(path = args.first)
|
5
|
+
abort "Key file already exists."
|
6
|
+
end
|
7
|
+
|
8
|
+
begin
|
9
|
+
File.open(path, 'w') do |f|
|
10
|
+
f.write(generate_secure_key)
|
11
|
+
end
|
12
|
+
rescue
|
13
|
+
abort "Cannot open #{path} for writing."
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def generate_secure_key
|
19
|
+
OpenSSL::Cipher.new("AES-128-CBC").random_key
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/rgc/smudge.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Rgc
|
2
|
+
class Smudge
|
3
|
+
include Rgc::KeyFile
|
4
|
+
|
5
|
+
def initialize(global_options, options, args)
|
6
|
+
load_key
|
7
|
+
|
8
|
+
print(decrypt(ARGF.read))
|
9
|
+
end
|
10
|
+
|
11
|
+
def decrypt(content)
|
12
|
+
@aes = OpenSSL::Cipher.new("AES-128-CBC")
|
13
|
+
@aes.decrypt
|
14
|
+
@aes.key = @key
|
15
|
+
|
16
|
+
@aes.update(Base64.decode64(content)) + @aes.final
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/rgc/version.rb
CHANGED
data/lib/rgc.rb
CHANGED
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Jiri Chara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
@@ -14,128 +14,136 @@ dependencies:
|
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '10.1'
|
20
20
|
type: :development
|
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: '
|
26
|
+
version: '10.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rdoc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4.1'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '4.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: aruba
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '0.5'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '0.5'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '2.14'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '2.14'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: faker
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1.2'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '1.2'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: gli
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 2.8
|
89
|
+
version: '2.8'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 2.8
|
97
|
-
description:
|
98
|
-
email:
|
96
|
+
version: '2.8'
|
97
|
+
description: rgc is a tool for encrypting certain files in a git repository.
|
98
|
+
email: jirik.chara@gmail.com
|
99
99
|
executables:
|
100
100
|
- rgc
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files:
|
103
103
|
- README.rdoc
|
104
|
+
- LICENCE.txt
|
104
105
|
- rgc.rdoc
|
105
106
|
files:
|
107
|
+
- LICENCE.txt
|
108
|
+
- README.rdoc
|
106
109
|
- bin/rgc
|
107
|
-
- lib/rgc/version.rb
|
108
110
|
- lib/rgc.rb
|
109
|
-
-
|
111
|
+
- lib/rgc/arg_parser.rb
|
112
|
+
- lib/rgc/clean.rb
|
113
|
+
- lib/rgc/encrypt.rb
|
114
|
+
- lib/rgc/init.rb
|
115
|
+
- lib/rgc/key_file.rb
|
116
|
+
- lib/rgc/keygen.rb
|
117
|
+
- lib/rgc/smudge.rb
|
118
|
+
- lib/rgc/version.rb
|
110
119
|
- rgc.rdoc
|
111
|
-
homepage:
|
112
|
-
licenses:
|
120
|
+
homepage: https://github.com/JiriChara/rgc
|
121
|
+
licenses:
|
122
|
+
- MIT
|
113
123
|
metadata: {}
|
114
124
|
post_install_message:
|
115
125
|
rdoc_options:
|
116
|
-
- --title
|
126
|
+
- "--title"
|
117
127
|
- rgc
|
118
|
-
- --main
|
128
|
+
- "--main"
|
119
129
|
- README.rdoc
|
120
|
-
- -ri
|
130
|
+
- "-ri"
|
121
131
|
require_paths:
|
122
132
|
- lib
|
123
|
-
- lib
|
124
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
125
134
|
requirements:
|
126
|
-
- -
|
135
|
+
- - ">="
|
127
136
|
- !ruby/object:Gem::Version
|
128
137
|
version: '0'
|
129
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
139
|
requirements:
|
131
|
-
- -
|
140
|
+
- - ">="
|
132
141
|
- !ruby/object:Gem::Version
|
133
142
|
version: '0'
|
134
143
|
requirements: []
|
135
144
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.
|
145
|
+
rubygems_version: 2.2.1
|
137
146
|
signing_key:
|
138
147
|
specification_version: 4
|
139
|
-
summary:
|
148
|
+
summary: Tool for encrypting files in a git repository.
|
140
149
|
test_files: []
|
141
|
-
has_rdoc: true
|