leml 0.1.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +33 -0
- data/lib/leml.rb +3 -0
- data/lib/leml/core.rb +139 -0
- data/lib/leml/railtie.rb +10 -0
- data/lib/leml/version.rb +3 -0
- data/lib/tasks/leml_tasks.rake +18 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 835b190cfc6a22374bef64a72a7a1879bd4e9519
|
4
|
+
data.tar.gz: 3e8e4733d55da087884afd1e8ae32a19c7c9c87e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fcfc7e52d1413785bd69cf52de65bb0c4051f7fb97e2b616dc6b888dc899ce5afc3f52de72cf0d016398d1029a1a85f9e36f3117595d9d3748a7445f2ecf630d
|
7
|
+
data.tar.gz: 8cd17e2353b48da0544093932f888cc56ea9a8d886301036861b70be4386521b20acc15717a9a76b5725f58b068922b644353da7308479807a8f435b9d13bb1b
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 onunu
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Leml
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'leml'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install leml
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Leml'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
task default: :test
|
data/lib/leml.rb
ADDED
data/lib/leml/core.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module Leml
|
4
|
+
class Core
|
5
|
+
KEY = Rails.root.join('config', 'leml.key')
|
6
|
+
SECRETS = Rails.root.join('config', 'leml.yml')
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def setup
|
10
|
+
key_initialize
|
11
|
+
yaml_initialize
|
12
|
+
complete_message
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def key_initialize
|
18
|
+
confirm_initialize(KEY) if File.exist?(KEY)
|
19
|
+
File.open(KEY, 'w') do |file|
|
20
|
+
file.puts(SecureRandom.hex(16))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def yaml_initialize
|
25
|
+
confirm_initialize(SECRETS) if File.exist?(SECRETS)
|
26
|
+
File.open(SECRETS, 'w') do |file|
|
27
|
+
file.puts(yaml_template)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def confirm_initialize(file)
|
32
|
+
@confirm ||= get_confirm_from_stdin == 'Y'
|
33
|
+
abort unless @confirm
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_confirm_from_stdin
|
37
|
+
puts 'Already exist key or leml.yaml, in your project, continue initialize? [Y,n]'
|
38
|
+
loop do
|
39
|
+
print '>>'
|
40
|
+
stdin = $stdin.gets.chomp
|
41
|
+
return stdin if stdin =~ /^(Y|n)$/
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def yaml_template
|
46
|
+
<<~EOS
|
47
|
+
# leml is provide only leaf encrypted secrets
|
48
|
+
# only keys is readble, but value is no way.
|
49
|
+
# notation is same of secrets, needs environments
|
50
|
+
EOS
|
51
|
+
end
|
52
|
+
|
53
|
+
def complete_message
|
54
|
+
print <<~EOS
|
55
|
+
\e[32mComplete!
|
56
|
+
\e[32mcreate \e[0mconfig/leml.key
|
57
|
+
\e[32mcreate \e[0mconfig/leml.yml
|
58
|
+
|
59
|
+
\e[33mCaution \e[0mDon't forget add key file in gitignore
|
60
|
+
EOS
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def initialize
|
65
|
+
key = File.read(KEY).chop
|
66
|
+
@encryptor = ActiveSupport::MessageEncryptor.new(key, cipher: 'aes-256-cbc')
|
67
|
+
@secrets = YAML.load_file(SECRETS)
|
68
|
+
end
|
69
|
+
|
70
|
+
def merge_secrets
|
71
|
+
return unless File.exists?(KEY) && File.exists?(SECRETS)
|
72
|
+
Rails.application.secrets.merge!(decrypt(@secrets)[Rails.env].deep_symbolize_keys) if @secrets
|
73
|
+
end
|
74
|
+
|
75
|
+
def edit
|
76
|
+
no_editor if ENV['EDITOR'].blank?
|
77
|
+
Dir.mktmpdir do |dir|
|
78
|
+
tmp_file = create_decrypted_tmp_file(dir)
|
79
|
+
system("#{ENV['EDITOR']} #{tmp_file.to_s}")
|
80
|
+
reload_secrets_file(tmp_file)
|
81
|
+
puts 'OK, your secrets is encrypted.'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def show
|
86
|
+
return unless @secrets
|
87
|
+
print(decrypt(@secrets).to_yaml)
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def encrypt(raw_secret_hash)
|
93
|
+
raw_secret_hash.map do |key, value|
|
94
|
+
[
|
95
|
+
key,
|
96
|
+
value.kind_of?(Hash) ? encrypt(value) : encrypt_value(value)
|
97
|
+
]
|
98
|
+
end.to_h
|
99
|
+
end
|
100
|
+
|
101
|
+
def decrypt(secret_hash)
|
102
|
+
secret_hash.map do |key, value|
|
103
|
+
[
|
104
|
+
key,
|
105
|
+
value.kind_of?(Hash) ? decrypt(value) : decrypt_value(value)
|
106
|
+
]
|
107
|
+
end.to_h
|
108
|
+
end
|
109
|
+
|
110
|
+
def encrypt_value(value)
|
111
|
+
@encryptor.encrypt_and_sign(value)
|
112
|
+
end
|
113
|
+
|
114
|
+
def decrypt_value(value)
|
115
|
+
@encryptor.decrypt_and_verify(value)
|
116
|
+
end
|
117
|
+
|
118
|
+
def no_editor
|
119
|
+
puts 'No editor, please set environment variable.'
|
120
|
+
puts 'ex) EDITOR=vim bundle exec rake leml:edit'
|
121
|
+
abort
|
122
|
+
end
|
123
|
+
|
124
|
+
def create_decrypted_tmp_file(dir)
|
125
|
+
file = File.join(dir, 'tmp_leml.yml')
|
126
|
+
File.open(file, 'w') do |file|
|
127
|
+
file.puts(decrypt(@secrets).to_yaml) if @secrets
|
128
|
+
end
|
129
|
+
file
|
130
|
+
end
|
131
|
+
|
132
|
+
def reload_secrets_file(tmp_file)
|
133
|
+
raw_secrets = YAML.load_file(tmp_file)
|
134
|
+
File.open(SECRETS, 'w') do |file|
|
135
|
+
file.puts encrypt(raw_secrets).to_yaml
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/lib/leml/railtie.rb
ADDED
data/lib/leml/version.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'leml/core'
|
2
|
+
|
3
|
+
namespace :leml do
|
4
|
+
desc 'initialize secrets yaml'
|
5
|
+
task :init => :environment do
|
6
|
+
Leml::Core.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
desc 'edit encrypted yaml'
|
10
|
+
task :edit => :environment do
|
11
|
+
Leml::Core.new.edit
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'show encrypted yaml'
|
15
|
+
task :show => :environment do
|
16
|
+
Leml::Core.new.show
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: leml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- onunu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.1.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.1.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Merge your yaml to rails secrets, and it encrypted only leaf
|
42
|
+
email:
|
43
|
+
- riku.onuma@livesense.co.jp
|
44
|
+
- onunu@zeals.co.jp
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- MIT-LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- lib/leml.rb
|
53
|
+
- lib/leml/core.rb
|
54
|
+
- lib/leml/railtie.rb
|
55
|
+
- lib/leml/version.rb
|
56
|
+
- lib/tasks/leml_tasks.rake
|
57
|
+
homepage: https://github.com/onunu/leml
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.6.11
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Encrypt only leaf of your secrets yaml file
|
81
|
+
test_files: []
|