sekrit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +50 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +42 -0
- data/LICENSE +21 -0
- data/README.md +39 -0
- data/Rakefile +10 -0
- data/exe/sekrit +4 -0
- data/lib/sekrit.rb +68 -0
- data/lib/sekrit/bundle.rb +15 -0
- data/lib/sekrit/config.rb +24 -0
- data/lib/sekrit/decoder.rb +35 -0
- data/lib/sekrit/encoder.rb +35 -0
- data/lib/sekrit/logger.rb +16 -0
- data/lib/sekrit/pull.rb +90 -0
- data/lib/sekrit/push.rb +94 -0
- data/lib/sekrit/runner.rb +115 -0
- data/lib/sekrit/version.rb +3 -0
- data/sekrit.gemspec +37 -0
- metadata +178 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ca7a1767ce6391f16d5e7fbc78d9ca0b4528f742f639502909e81c0f29858ebd
|
4
|
+
data.tar.gz: 84e081859f12864c52a8dbafb9dfa5c53d9dc52250ec734d023231f4878a8ec2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8bd5bcab88845cc63906ae2e1d0313c82a790c2280b6091154ccbc60d4ed2f3919c88d2d566bbbd88bb212dbdc5a4c219faa9bb39630cece4a0d62e4e53ca93d
|
7
|
+
data.tar.gz: 840290e27fa7cf242fc4c55422b62d1f3ea8c102819675f4e3c5980bd91c5af09279e0a94e4f3e0f338802a5988facd2aa89c15367e71359c9176e0490a009f7
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.3
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sekrit (0.1.0)
|
5
|
+
git (~> 1.5.0)
|
6
|
+
rainbow (~> 3.0.0)
|
7
|
+
terminal-table (~> 1.8.0)
|
8
|
+
thor (~> 0.20.3)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
byebug (11.0.1)
|
14
|
+
coderay (1.1.2)
|
15
|
+
git (1.5.0)
|
16
|
+
method_source (0.9.2)
|
17
|
+
minitest (5.11.3)
|
18
|
+
pry (0.12.2)
|
19
|
+
coderay (~> 1.1.0)
|
20
|
+
method_source (~> 0.9.0)
|
21
|
+
pry-byebug (3.7.0)
|
22
|
+
byebug (~> 11.0)
|
23
|
+
pry (~> 0.10)
|
24
|
+
rainbow (3.0.0)
|
25
|
+
rake (10.5.0)
|
26
|
+
terminal-table (1.8.0)
|
27
|
+
unicode-display_width (~> 1.1, >= 1.1.1)
|
28
|
+
thor (0.20.3)
|
29
|
+
unicode-display_width (1.6.0)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
bundler (~> 2.0)
|
36
|
+
minitest (~> 5.0)
|
37
|
+
pry-byebug (~> 3.7.0)
|
38
|
+
rake (~> 10.0)
|
39
|
+
sekrit!
|
40
|
+
|
41
|
+
BUNDLED WITH
|
42
|
+
2.0.2
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Fourty Two
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Sekrit
|
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/sekrit`. 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 'sekrit'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install sekrit
|
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 test` 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]/sekrit.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/exe/sekrit
ADDED
data/lib/sekrit.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'git'
|
2
|
+
require 'rainbow'
|
3
|
+
require 'sekrit/bundle'
|
4
|
+
require 'sekrit/config'
|
5
|
+
require 'sekrit/decoder'
|
6
|
+
require 'sekrit/encoder'
|
7
|
+
require 'sekrit/logger'
|
8
|
+
require "sekrit/pull"
|
9
|
+
require "sekrit/push"
|
10
|
+
require "sekrit/runner"
|
11
|
+
require "sekrit/version"
|
12
|
+
require 'terminal-table'
|
13
|
+
require 'thor'
|
14
|
+
|
15
|
+
module Sekrit
|
16
|
+
class Error < StandardError; end
|
17
|
+
|
18
|
+
class CLI < Thor
|
19
|
+
class_option :verbose, aliases: :v, type: :boolean, default: false
|
20
|
+
|
21
|
+
desc 'push --config <path to Sekritfile> --git_ref <branch>', 'Encrypts and pushes files according to the contents of `Sekritfile`'
|
22
|
+
option :bundle_id, aliases: :b, type: :string
|
23
|
+
option :config, aliases: :c, type: :string, default: "#{ENV['PWD']}/Sekritfile"
|
24
|
+
option :git_ref, aliases: :g, type: :string, default: 'master'
|
25
|
+
option :passphrase, aliases: :p, type: :string
|
26
|
+
option :working_directory, aliases: :d, type: :string, default: '.'
|
27
|
+
def push
|
28
|
+
configure_logger(verbose: options[:verbose])
|
29
|
+
driver = lambda do |bundle_id, config, passphrase|
|
30
|
+
Push.new(
|
31
|
+
bundle_id: bundle_id,
|
32
|
+
config: config,
|
33
|
+
passphrase: passphrase
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
runner = Runner.new(name: "Push", options: options, driver: driver)
|
38
|
+
runner.run
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'pull --config <path to Sekritfile> --git_ref <branch>', 'Pulls and decrypts files according to the contents of `Sekritfile`'
|
42
|
+
option :bundle_id, aliases: :b, type: :string
|
43
|
+
option :config, aliases: :c, type: :string, default: "#{ENV['PWD']}/Sekritfile"
|
44
|
+
option :git_ref, aliases: :g, type: :string, default: 'master'
|
45
|
+
option :passphrase, aliases: :p, type: :string
|
46
|
+
option :working_directory, aliases: :d, type: :string, default: '.'
|
47
|
+
def pull
|
48
|
+
configure_logger(verbose: options[:verbose])
|
49
|
+
driver = lambda do |bundle_id, config, passphrase|
|
50
|
+
Pull.new(
|
51
|
+
bundle_id: bundle_id,
|
52
|
+
config: config,
|
53
|
+
passphrase: passphrase
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
runner = Runner.new(name: "Pull", options: options, driver: driver)
|
58
|
+
runner.run
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def configure_logger(verbose: Boolean)
|
64
|
+
log.level = verbose ? Logger::DEBUG : Logger::INFO
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Sekrit
|
4
|
+
|
5
|
+
class Config
|
6
|
+
attr_reader :bundles
|
7
|
+
attr_reader :shared_files
|
8
|
+
attr_reader :bundled_files
|
9
|
+
attr_reader :passphrase
|
10
|
+
attr_reader :repo
|
11
|
+
attr_reader :raw
|
12
|
+
|
13
|
+
def initialize(path: 'Sekritfile')
|
14
|
+
@raw = File.read(path)
|
15
|
+
config = YAML::load_file(path)
|
16
|
+
@bundled_files = Bundle.new(hash: config['bundled_files']) unless config['bundled_files'].nil?
|
17
|
+
@bundles = (config['bundles'] || []).map { |b| Bundle.new(hash: b) }
|
18
|
+
@passphrase = config['passphrase']
|
19
|
+
@repo = config['repo']
|
20
|
+
@shared_files = Bundle.new(hash: config['shared_files']) unless config['shared_files'].nil?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'openssl'
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
module Sekrit
|
6
|
+
|
7
|
+
class Decoder
|
8
|
+
|
9
|
+
def initialize(password: String)
|
10
|
+
@password = password
|
11
|
+
end
|
12
|
+
|
13
|
+
# [bsarrazin] July 20th, 2019
|
14
|
+
# Stolen from Fastlane, as I am not an expert on encryption/decryption.
|
15
|
+
# If you have experience and want to help, please submit a pull request :)
|
16
|
+
#
|
17
|
+
# > We encrypt with MD5 because that was the most common default value in older fastlane versions which used the local OpenSSL installation
|
18
|
+
# > A more secure key and IV generation is needed in the future, IV should be randomly generated and provided unencrypted
|
19
|
+
# > salt should be randomly generated and provided unencrypted (like in the current implementation)
|
20
|
+
# > key should be generated with OpenSSL::KDF::pbkdf2_hmac with properly chosen parameters
|
21
|
+
# > Short explanation about salt and IV: https://stackoverflow.com/a/1950674/6324550
|
22
|
+
def decode(string: String)
|
23
|
+
data = Base64.decode64(string)
|
24
|
+
salt = data[8..15]
|
25
|
+
data = data[16..-1]
|
26
|
+
|
27
|
+
decipher = OpenSSL::Cipher.new('AES-256-CBC')
|
28
|
+
decipher.decrypt
|
29
|
+
decipher.pkcs5_keyivgen(@password, salt, 1, "MD5")
|
30
|
+
|
31
|
+
decipher.update(data) + decipher.final
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'openssl'
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
module Sekrit
|
6
|
+
|
7
|
+
class Encoder
|
8
|
+
|
9
|
+
def initialize(password: String)
|
10
|
+
@password = password
|
11
|
+
end
|
12
|
+
|
13
|
+
# [bsarrazin] July 20th, 2019
|
14
|
+
# Stolen from Fastlane, as I am not an expert on encryption/decryption.
|
15
|
+
# If you have experience and want to help, please submit a pull request :)
|
16
|
+
#
|
17
|
+
# > We encrypt with MD5 because that was the most common default value in older fastlane versions which used the local OpenSSL installation
|
18
|
+
# > A more secure key and IV generation is needed in the future, IV should be randomly generated and provided unencrypted
|
19
|
+
# > salt should be randomly generated and provided unencrypted (like in the current implementation)
|
20
|
+
# > key should be generated with OpenSSL::KDF::pbkdf2_hmac with properly chosen parameters
|
21
|
+
# > Short explanation about salt and IV: https://stackoverflow.com/a/1950674/6324550
|
22
|
+
def encode(string: String)
|
23
|
+
|
24
|
+
salt = SecureRandom.random_bytes(8)
|
25
|
+
|
26
|
+
cipher = OpenSSL::Cipher.new('AES-256-CBC')
|
27
|
+
cipher.encrypt
|
28
|
+
cipher.pkcs5_keyivgen(@password, salt, 1, "MD5")
|
29
|
+
data = "Salted__" + salt + cipher.update(string) + cipher.final
|
30
|
+
|
31
|
+
Base64.encode64(data)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/lib/sekrit/pull.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'rainbow'
|
2
|
+
|
3
|
+
module Sekrit
|
4
|
+
|
5
|
+
class Pull
|
6
|
+
|
7
|
+
def initialize(bundle_id: String, config: Config, passphrase: String)
|
8
|
+
@bundle_id = bundle_id
|
9
|
+
@config = config
|
10
|
+
@decoder = Decoder.new(password: passphrase)
|
11
|
+
|
12
|
+
raise Thor::Error, Rainbow("Bundle id cannot be nil").red if @bundle_id.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
def bundle
|
16
|
+
@config.bundles.select { |b| b.id == @bundle_id }.first
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy_bundled_files(dir: String)
|
20
|
+
raise Thor::Error, Rainbow("Cannot find bundle with id '#{@bundle_id}' in Sekritfile").red if bundle.nil?
|
21
|
+
|
22
|
+
config_bundled_files = @config.bundled_files.nil? ? [] : @config.bundled_files.files
|
23
|
+
config_bundled_files += bundle.files
|
24
|
+
config_bundled_files.each do |f|
|
25
|
+
src = "#{dir}/#{bundle.id}/#{f}"
|
26
|
+
file_path = "#{Dir.pwd}/#{f}"
|
27
|
+
if File.exist?(src)
|
28
|
+
log.debug Rainbow("Preparing to copy '#{src}' to '#{file_path}'").purple
|
29
|
+
FileUtils.cp(src, f)
|
30
|
+
log.debug Rainbow("Copied '#{src}' to '#{file_path}'").purple
|
31
|
+
else
|
32
|
+
log.warn(Rainbow("Could not find file at path '#{src}'").yellow)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
config_encrypted_files = @config.bundled_files.nil? ? [] : @config.bundled_files.encrypted
|
37
|
+
config_encrypted_files += bundle.encrypted
|
38
|
+
config_encrypted_files.each do |f|
|
39
|
+
src = "#{dir}/#{bundle.id}/#{f}"
|
40
|
+
file_path = "#{Dir.pwd}/#{f}"
|
41
|
+
if File.exist?(src)
|
42
|
+
log.debug Rainbow("Preparing to decrypt and copy '#{src}' to '#{file_path}'").purple
|
43
|
+
FileUtils.cp(src, f)
|
44
|
+
log.debug Rainbow("Copied '#{src}' to '#{file_path}'").purple
|
45
|
+
|
46
|
+
log.debug Rainbow("Preparing to decrypt '#{file_path}'").purple
|
47
|
+
File.write(file_path, @decoder.decode(string: File.read(file_path)))
|
48
|
+
log.debug Rainbow("Decrypted '#{file_path}'").purple
|
49
|
+
else
|
50
|
+
log.warn(Rainbow("Could not find file at path '#{src}'").yellow)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def copy_shared_files(dir: String)
|
56
|
+
config_shared_files = @config.shared_files.nil? ? [] : @config.shared_files.files
|
57
|
+
config_shared_files += bundle.files
|
58
|
+
config_shared_files.each do |f|
|
59
|
+
src = "#{dir}/shared/#{f}"
|
60
|
+
file_path = "#{Dir.pwd}/#{f}"
|
61
|
+
if File.exist?(src)
|
62
|
+
log.debug Rainbow("Preparing to copy '#{src}' to '#{file_path}'").purple
|
63
|
+
FileUtils.cp(src, f)
|
64
|
+
log.debug Rainbow("Copied '#{src}' to '#{file_path}'").purple
|
65
|
+
else
|
66
|
+
log.warn(Rainbow("Could not find file at path '#{src}'").yellow)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
config_encrypted_files = @config.shared_files.nil? ? [] : @config.shared_files.encrypted
|
71
|
+
config_encrypted_files += bundle.encrypted
|
72
|
+
config_encrypted_files.each do |f|
|
73
|
+
src = "#{dir}/shared/#{f}"
|
74
|
+
file_path = "#{Dir.pwd}/#{f}"
|
75
|
+
if File.exist?(src)
|
76
|
+
log.debug Rainbow("Preparing to decrypt and copy '#{src}' to '#{file_path}'").purple
|
77
|
+
FileUtils.cp(src, f)
|
78
|
+
log.debug Rainbow("Copied '#{src}' to '#{file_path}'").purple
|
79
|
+
|
80
|
+
log.debug Rainbow("Preparing to decrypt '#{file_path}'").purple
|
81
|
+
File.write(file_path, @decoder.decode(string: File.read(file_path)))
|
82
|
+
log.debug Rainbow("Decrypted '#{file_path}'").purple
|
83
|
+
else
|
84
|
+
log.warn(Rainbow("Could not find file at path '#{src}'").yellow)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
data/lib/sekrit/push.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'rainbow'
|
2
|
+
|
3
|
+
module Sekrit
|
4
|
+
|
5
|
+
class Push
|
6
|
+
|
7
|
+
def initialize(bundle_id: String, config: Config, passphrase: String)
|
8
|
+
@bundle_id = bundle_id
|
9
|
+
@config = config
|
10
|
+
@encoder = Encoder.new(password: passphrase)
|
11
|
+
|
12
|
+
raise Thor::Error, Rainbow("Bundle id cannot be nil").red if @bundle_id.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
def bundle
|
16
|
+
@config.bundles.select { |b| b.id == @bundle_id }.first
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy_bundled_files(dir: String)
|
20
|
+
raise Thor::Error, Rainbow("Cannot find bundle with id '#{@bundle_id}' in Sekritfile").red if bundle.nil?
|
21
|
+
|
22
|
+
config_bundled_files = @config.bundled_files.nil? ? [] : @config.bundled_files.files
|
23
|
+
config_bundled_files += bundle.files
|
24
|
+
config_bundled_files.each do |f|
|
25
|
+
dest = "#{dir}/#{bundle.id}/#{f}"
|
26
|
+
file_path = "#{Dir.pwd}/#{f}"
|
27
|
+
if File.exist?(file_path)
|
28
|
+
log.debug Rainbow("Preparing to copy '#{file_path}' to '#{dest}'").purple
|
29
|
+
FileUtils.mkdir_p(File.dirname(dest))
|
30
|
+
FileUtils.cp(f, dest)
|
31
|
+
log.debug Rainbow("Copied '#{file_path}' to '#{dest}'").purple
|
32
|
+
else
|
33
|
+
log.warn(Rainbow("Could not find file at path '#{file_path}'").yellow)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
config_encrypted_files = @config.bundled_files.nil? ? [] : @config.bundled_files.encrypted
|
38
|
+
config_encrypted_files += bundle.encrypted
|
39
|
+
config_encrypted_files.each do |f|
|
40
|
+
dest = "#{dir}/#{bundle.id}/#{f}"
|
41
|
+
file_path = "#{Dir.pwd}/#{f}"
|
42
|
+
if File.exist?(file_path)
|
43
|
+
log.debug Rainbow("Preparing to encrypt and copy '#{file_path}' to '#{dest}'").purple
|
44
|
+
FileUtils.mkdir_p(File.dirname(dest))
|
45
|
+
FileUtils.cp(f, dest)
|
46
|
+
log.debug Rainbow("Copied '#{file_path}' to '#{dest}'").purple
|
47
|
+
|
48
|
+
log.debug Rainbow("Preparing to encrypt '#{dest}'").purple
|
49
|
+
File.write(dest, @encoder.encode(string: File.read(dest)))
|
50
|
+
log.debug Rainbow("Encrypted '#{dest}'").purple
|
51
|
+
else
|
52
|
+
log.warn(Rainbow("Could not find file at path '#{file_path}'").yellow)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def copy_shared_files(dir: String)
|
58
|
+
config_shared_files = @config.shared_files.nil? ? [] : @config.shared_files.files
|
59
|
+
config_shared_files += bundle.files
|
60
|
+
config_shared_files.each do |f|
|
61
|
+
dest = "#{dir}/shared/#{f}"
|
62
|
+
file_path = "#{Dir.pwd}/#{f}"
|
63
|
+
if File.exist?(file_path)
|
64
|
+
log.debug Rainbow("Preparing to copy '#{file_path}' to '#{dest}'").purple
|
65
|
+
FileUtils.mkdir_p(File.dirname(dest))
|
66
|
+
FileUtils.cp(f, dest)
|
67
|
+
log.debug Rainbow("Copied '#{file_path}' to '#{dest}'").purple
|
68
|
+
else
|
69
|
+
log.warn(Rainbow("Could not find file at path '#{file_path}'").yellow)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
config_encrypted_files = @config.shared_files.nil? ? [] : @config.shared_files.encrypted
|
74
|
+
config_encrypted_files += bundle.encrypted
|
75
|
+
config_encrypted_files.each do |f|
|
76
|
+
dest = "#{dir}/shared/#{f}"
|
77
|
+
file_path = "#{Dir.pwd}/#{f}"
|
78
|
+
if File.exist?(file_path)
|
79
|
+
log.debug Rainbow("Preparing to encrypt and copy '#{file_path}' to '#{dest}'").purple
|
80
|
+
FileUtils.mkdir_p(File.dirname(dest))
|
81
|
+
FileUtils.cp(f, dest)
|
82
|
+
log.debug Rainbow("Copied '#{file_path}' to '#{dest}'").purple
|
83
|
+
|
84
|
+
log.debug Rainbow("Preparing to encrypt '#{dest}'").purple
|
85
|
+
File.write(dest, @encoder.encode(string: File.read(dest)))
|
86
|
+
log.debug Rainbow("Encrypted '#{dest}'").purple
|
87
|
+
else
|
88
|
+
log.warn(Rainbow("Could not find file at path '#{file_path}'").yellow)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
module Sekrit
|
2
|
+
|
3
|
+
class Runner
|
4
|
+
|
5
|
+
def initialize(name: String, options: Hash, driver: lambda)
|
6
|
+
@name = name
|
7
|
+
@options = options
|
8
|
+
@driver = driver
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
delete_sekrit_dir_if_exist?
|
13
|
+
|
14
|
+
begin
|
15
|
+
print_command_config(name: @name)
|
16
|
+
|
17
|
+
raise Thor::Error, Rainbow("Cannot find Sekritfile at #{@options[:config]}").red unless File.exist?(@options[:config])
|
18
|
+
|
19
|
+
@config = Sekrit::Config.new(path: @options[:config])
|
20
|
+
bundle_id = @options[:bundle_id] || @config.bundles.first.id
|
21
|
+
|
22
|
+
print_sekrit_config(bundle_id: bundle_id)
|
23
|
+
|
24
|
+
@passphrase = @options[:passphrase] || ENV[@config.passphrase]
|
25
|
+
raise Thor::Error, Rainbow("passphrase cannot be nil").red if @passphrase.nil?
|
26
|
+
raise Thor::Error, Rainbow("passphrase cannot be empty").red if @passphrase.empty?
|
27
|
+
|
28
|
+
git_name = @config.repo.split('/').last.chomp('.git')
|
29
|
+
git = Git.clone(@config.repo, git_name, path: sekrit_dir, log: log)
|
30
|
+
begin
|
31
|
+
git.checkout(@options[:git_ref])
|
32
|
+
log.info Rainbow("Checking out #{@options[:git_ref]}").blue
|
33
|
+
rescue
|
34
|
+
git.branch(@options[:git_ref]).checkout
|
35
|
+
log.info Rainbow("Creating new branch #{@options[:git_ref]}").blue
|
36
|
+
end
|
37
|
+
|
38
|
+
directory = "#{working_directory}/#{git_name}"
|
39
|
+
driver = @driver.call(bundle_id, @config, @passphrase)
|
40
|
+
driver.copy_bundled_files(dir: directory)
|
41
|
+
driver.copy_shared_files(dir: directory)
|
42
|
+
|
43
|
+
if driver.class == Push
|
44
|
+
log.info Rainbow("git adding...").green
|
45
|
+
git.add
|
46
|
+
log.info Rainbow("git committing...").green
|
47
|
+
git.commit "[Sekrit] Updating files for #{bundle_id}"
|
48
|
+
log.info Rainbow("git pushing...").green
|
49
|
+
git.push(git.remote('origin'), git.branch(@options[:git_ref]))
|
50
|
+
log.info Rainbow("git completed!").green
|
51
|
+
end
|
52
|
+
|
53
|
+
rescue => error
|
54
|
+
log.warn Rainbow("git repo at `#{sekrit_dir}/#{git_name}` was not deleted").yellow
|
55
|
+
raise Thor::Error, Rainbow(error.full_message).red
|
56
|
+
end
|
57
|
+
|
58
|
+
delete_sekrit_dir_if_exist?
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def print_command_config(name: String)
|
64
|
+
title = Rainbow("Sekrit #{name}").green
|
65
|
+
headings = ['Option', 'Value']
|
66
|
+
rows = []
|
67
|
+
rows << ['config file', @options[:config]]
|
68
|
+
rows << ['git reference (branch)', @options[:git_ref]]
|
69
|
+
rows << ['working directory', @options[:working_directory]]
|
70
|
+
table = Terminal::Table.new(title: title, headings: headings, rows: rows)
|
71
|
+
puts("\n" + table.to_s + "\n")
|
72
|
+
end
|
73
|
+
|
74
|
+
def print_sekrit_config(bundle_id: String)
|
75
|
+
title = Rainbow('Sekrit Config').green
|
76
|
+
headings = ['Option', 'Value']
|
77
|
+
rows = []
|
78
|
+
rows << ['bundle_id', bundle_id]
|
79
|
+
rows << ['repo', @config.repo]
|
80
|
+
rows << ['passphrase key', @config.passphrase]
|
81
|
+
rows << ['bundles', @config.bundles.map { |b| '- ' + b.id }.join("\n") ]
|
82
|
+
|
83
|
+
if @config.shared_files.nil?
|
84
|
+
rows << ['shared_files', '<does not exist in Sekritfile>']
|
85
|
+
else
|
86
|
+
rows << ['shared_files', @config.shared_files.files.nil? ? '<none>' : @config.shared_files.files.map { |f| '- ' + f }.join("\n")]
|
87
|
+
rows << ['shared_encrypted', @config.shared_files.encrypted.nil? ? '<none>' : @config.shared_files.encrypted.map { |f| '- ' + f }.join("\n")]
|
88
|
+
end
|
89
|
+
|
90
|
+
if @config.bundled_files.nil?
|
91
|
+
rows << ['bundled_files', '<does not exist in Sekritfile>']
|
92
|
+
else
|
93
|
+
rows << ['bundled_files', @config.bundled_files.files.nil? ? '<none>' : @config.bundled_files.files.map { |f| '- ' + f }.join("\n")]
|
94
|
+
rows << ['bundled_encrypted', @config.bundled_files.encrypted.nil? ? '<none>' : @config.bundled_files.encrypted.map { |f| '- ' + f }.join("\n")]
|
95
|
+
end
|
96
|
+
|
97
|
+
rows << ['Sekrifile', @config.raw]
|
98
|
+
|
99
|
+
table = Terminal::Table.new(title: title, headings: headings, rows: rows, style: { all_separators: true })
|
100
|
+
puts("\n" + table.to_s + "\n")
|
101
|
+
end
|
102
|
+
|
103
|
+
def sekrit_dir
|
104
|
+
'.sekrit'
|
105
|
+
end
|
106
|
+
|
107
|
+
def working_directory
|
108
|
+
"#{@options[:working_directory]}/#{sekrit_dir}"
|
109
|
+
end
|
110
|
+
|
111
|
+
def delete_sekrit_dir_if_exist?
|
112
|
+
FileUtils.remove_dir(working_directory) if Dir.exist?(working_directory)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
data/sekrit.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "sekrit/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "sekrit"
|
7
|
+
spec.version = Sekrit::VERSION
|
8
|
+
spec.authors = ["Ben Sarrazin"]
|
9
|
+
spec.email = ["b@srz.io"]
|
10
|
+
|
11
|
+
spec.summary = %q{A gem for encrypting/decrypting files for your projects.}
|
12
|
+
spec.description = %q{Register files to encrypt/decrypt and store them in a separate git repository.}
|
13
|
+
spec.homepage = "https://github.com/fourtytwohq/sekrit"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/fourtytwohq/sekrit"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/fourtytwohq/sekrit"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
30
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.7.0'
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
33
|
+
spec.add_runtime_dependency 'git', '~> 1.5.0'
|
34
|
+
spec.add_runtime_dependency 'rainbow', '~> 3.0.0'
|
35
|
+
spec.add_runtime_dependency 'terminal-table', '~> 1.8.0'
|
36
|
+
spec.add_runtime_dependency 'thor', '~> 0.20.3'
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sekrit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Sarrazin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry-byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.7.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.7.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: git
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.5.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.5.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rainbow
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: terminal-table
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.8.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.8.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: thor
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.20.3
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.20.3
|
125
|
+
description: Register files to encrypt/decrypt and store them in a separate git repository.
|
126
|
+
email:
|
127
|
+
- b@srz.io
|
128
|
+
executables:
|
129
|
+
- sekrit
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".ruby-version"
|
135
|
+
- Gemfile
|
136
|
+
- Gemfile.lock
|
137
|
+
- LICENSE
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- exe/sekrit
|
141
|
+
- lib/sekrit.rb
|
142
|
+
- lib/sekrit/bundle.rb
|
143
|
+
- lib/sekrit/config.rb
|
144
|
+
- lib/sekrit/decoder.rb
|
145
|
+
- lib/sekrit/encoder.rb
|
146
|
+
- lib/sekrit/logger.rb
|
147
|
+
- lib/sekrit/pull.rb
|
148
|
+
- lib/sekrit/push.rb
|
149
|
+
- lib/sekrit/runner.rb
|
150
|
+
- lib/sekrit/version.rb
|
151
|
+
- sekrit.gemspec
|
152
|
+
homepage: https://github.com/fourtytwohq/sekrit
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata:
|
156
|
+
homepage_uri: https://github.com/fourtytwohq/sekrit
|
157
|
+
source_code_uri: https://github.com/fourtytwohq/sekrit
|
158
|
+
changelog_uri: https://github.com/fourtytwohq/sekrit
|
159
|
+
post_install_message:
|
160
|
+
rdoc_options: []
|
161
|
+
require_paths:
|
162
|
+
- lib
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
requirements: []
|
174
|
+
rubygems_version: 3.0.4
|
175
|
+
signing_key:
|
176
|
+
specification_version: 4
|
177
|
+
summary: A gem for encrypting/decrypting files for your projects.
|
178
|
+
test_files: []
|