encrypt_env 1.4.0 → 1.4.1
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 +4 -4
- data/lib/encrypt_env/version.rb +1 -1
- data/lib/encrypt_env.rb +13 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c2be77fd3504dd29034cbfc8c8fd64b337357bbb297f5510faf53805d46d8d2
|
4
|
+
data.tar.gz: a21a92c449fb73c43e66907837428026674b55d784242e8946e301727a0a0340
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3419ab5edeff49a4f40bd559f6da219630ebf8c7c3c44aa7ea5cf612a3bbb8e7223ef1bfb4c018a4ad21de1c7d83667f51de33c3275c3f3908035edbe975a3d
|
7
|
+
data.tar.gz: c2e59193da968fadaa428171b18844f58d2f80f966e779908cd28bb267cb22bc6d2b1b6409baf88f426f6dd5573837226dd9c8997188c87b8c5e1aeda42b0603
|
data/lib/encrypt_env/version.rb
CHANGED
data/lib/encrypt_env.rb
CHANGED
@@ -20,7 +20,7 @@ class EncryptEnv
|
|
20
20
|
puts '2. Generate master.key and encrypted file for each environment'
|
21
21
|
|
22
22
|
loop do
|
23
|
-
@opt = gets.chomp.to_i
|
23
|
+
@opt = $stdin.gets.chomp.to_i
|
24
24
|
break if @opt == 1 || @opt == 2
|
25
25
|
|
26
26
|
puts "Please enter '1' or '2'!"
|
@@ -30,9 +30,9 @@ class EncryptEnv
|
|
30
30
|
end
|
31
31
|
|
32
32
|
private_class_method def self.load_curr_opt
|
33
|
-
if File.file?("#{@root_path}/config/secrets.yml.enc")
|
33
|
+
if File.file?("#{@root_path}/config/encrypt_enc/secrets.yml.enc")
|
34
34
|
@opt = 1
|
35
|
-
elsif Dir["#{@root_path}/config/secrets_*.yml.enc"].length.positive?
|
35
|
+
elsif Dir["#{@root_path}/config/encrypt_enc/secrets_*.yml.enc"].length.positive?
|
36
36
|
@opt = 2
|
37
37
|
else
|
38
38
|
raise 'You must setup first to encrypt file!'
|
@@ -49,7 +49,7 @@ class EncryptEnv
|
|
49
49
|
|
50
50
|
private_class_method def self.check_key_existence(env = nil)
|
51
51
|
file_name = env.nil? ? 'master.key' : "master_#{env}.key"
|
52
|
-
return if File.file?("#{@root_path}/config/#{file_name}")
|
52
|
+
return if File.file?("#{@root_path}/config/master_key/#{file_name}")
|
53
53
|
return if ENV.key?('MASTER_KEY')
|
54
54
|
|
55
55
|
message = env ? "Missing key of #{env} environment!" : 'Missing master key!'
|
@@ -63,7 +63,7 @@ class EncryptEnv
|
|
63
63
|
raise e.message
|
64
64
|
end
|
65
65
|
|
66
|
-
file_path = env ? "#{@root_path}/config/master_#{env}.key" : "#{@root_path}/config/master.key"
|
66
|
+
file_path = env ? "#{@root_path}/config/master_key/master_#{env}.key" : "#{@root_path}/config/master_key/master.key"
|
67
67
|
key = File.file?(file_path) ? File.read(file_path).strip : ENV['MASTER_KEY']
|
68
68
|
@master_key = [key].pack('H*')
|
69
69
|
end
|
@@ -71,13 +71,13 @@ class EncryptEnv
|
|
71
71
|
private_class_method def self.generate_keys
|
72
72
|
if @opt == 1
|
73
73
|
key = OpenSSL::Random.random_bytes(16)
|
74
|
-
File.open("#{@root_path}/config/master.key", 'w') { |file| file.write(key.unpack('H*')[0]) }
|
74
|
+
File.open("#{@root_path}/config/master_key/master.key", 'w') { |file| file.write(key.unpack('H*')[0]) }
|
75
75
|
else
|
76
76
|
to_hash_type(@content_to_encrypt).each_key do |env|
|
77
77
|
next if env == 'default'
|
78
78
|
|
79
79
|
key = OpenSSL::Random.random_bytes(16)
|
80
|
-
File.open("#{@root_path}/config/master_#{env}.key", 'w') { |file| file.write(key.unpack('H*')[0]) }
|
80
|
+
File.open("#{@root_path}/config/master_key/master_#{env}.key", 'w') { |file| file.write(key.unpack('H*')[0]) }
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -92,7 +92,7 @@ class EncryptEnv
|
|
92
92
|
end
|
93
93
|
|
94
94
|
private_class_method def self.load_encrypted_data(env = nil)
|
95
|
-
file_path = env ? "#{@root_path}/config/secrets_#{env}.yml.enc" : "#{@root_path}/config/secrets.yml.enc"
|
95
|
+
file_path = env ? "#{@root_path}/config/encrypt_enc/secrets_#{env}.yml.enc" : "#{@root_path}/config/encrypt_enc/secrets.yml.enc"
|
96
96
|
hex_string = File.read(file_path)
|
97
97
|
raw_data = [hex_string].pack('H*')
|
98
98
|
|
@@ -103,7 +103,7 @@ class EncryptEnv
|
|
103
103
|
end
|
104
104
|
|
105
105
|
private_class_method def self.encrypt(content, typ = nil)
|
106
|
-
file_path = typ ? "#{@root_path}/config/secrets_#{typ}.yml.enc" : "#{@root_path}/config/secrets.yml.enc"
|
106
|
+
file_path = typ ? "#{@root_path}/config/encrypt_enc/secrets_#{typ}.yml.enc" : "#{@root_path}/config/encrypt_enc/secrets.yml.enc"
|
107
107
|
cipher = OpenSSL::Cipher.new('aes-128-gcm')
|
108
108
|
cipher.encrypt
|
109
109
|
cipher.key = @master_key
|
@@ -141,7 +141,7 @@ class EncryptEnv
|
|
141
141
|
|
142
142
|
private_class_method def self.all_decrypted_object
|
143
143
|
obj = {}
|
144
|
-
env_lst = Dir["#{@root_path}/config/secrets_*.yml.enc"].map do |path|
|
144
|
+
env_lst = Dir["#{@root_path}/config/encrypt_enc/secrets_*.yml.enc"].map do |path|
|
145
145
|
path.scan(/secrets_(.*)\.yml\.enc/).flatten.first
|
146
146
|
end
|
147
147
|
env_lst.each do |e|
|
@@ -182,6 +182,8 @@ class EncryptEnv
|
|
182
182
|
def self.setup
|
183
183
|
define_option
|
184
184
|
load_content_to_encrypt
|
185
|
+
system("mkdir -p #{@root_path}/config/master_key")
|
186
|
+
system("mkdir -p #{@root_path}/config/encrypt_enc")
|
185
187
|
generate_keys
|
186
188
|
|
187
189
|
if @opt == 1
|
@@ -197,7 +199,7 @@ class EncryptEnv
|
|
197
199
|
end
|
198
200
|
|
199
201
|
File.rename("#{@root_path}/config/secrets.yml", "#{@root_path}/config/secrets.yml.old")
|
200
|
-
system("echo '/config/master*.key' >> #{@root_path}/.gitignore")
|
202
|
+
system("echo '/config/master_key/master*.key' >> #{@root_path}/.gitignore")
|
201
203
|
system("echo '/config/secrets.yml.old' >> #{@root_path}/.gitignore")
|
202
204
|
system("echo 'Set up complete!'")
|
203
205
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: encrypt_env
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nhu Tan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|