encrypt_env 1.4.0 → 1.4.3

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
  SHA256:
3
- metadata.gz: 47ed1b7d3725d52b1133c37516eab8702c1423616f48ab2f0fd7b47a55ee5906
4
- data.tar.gz: dfbd255526aaa28824891d8774852c970036a36c693725bd95b14f4af530afbc
3
+ metadata.gz: d213624f3c092fe27cacc37d05b07822891de9dd3f1b773715eb05cb18aa9d23
4
+ data.tar.gz: c1299d1d43226300c905da7d21b912247f6c4a9f1f26d3a22eecfba16c054e31
5
5
  SHA512:
6
- metadata.gz: 2eb7ec510ce70ea0faecd43de3e2e15c28b1e80d6589042f6ede5321af837b052c288d23d88cbf7fb369b13016c521549d4ac38025e7e8db1c1ad58bfc984b80
7
- data.tar.gz: 68ada1002c808cb83d9035e94ea1927734db3bd684f9789be4dfe4125415d862da21103e4111d2e492cd4c471957d44f23a92eb51e288e12afe669c49cf1094b
6
+ metadata.gz: 0efd3a27ab1218edc29e785e3049736568662715306a16a9a86e51c4899071ab29976003de9e3442751dfeedc39291b764b8b152d1f3c732742d3aeb84cc8bdc
7
+ data.tar.gz: 73edcef93e90abdedf6f78e8000bd6654f59a8a6bdd5d91a4caa7380cdd4d624077d9246534b1ade5fd4281083b8b2f84490ce75a1cbc81ba732d7eaae297f14
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Version
4
- VERSION = '1.4.0'
4
+ VERSION = '1.4.3'
5
5
  end
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"].any?
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
@@ -216,6 +218,7 @@ class EncryptEnv
216
218
  system("vim #{f.path}")
217
219
  encrypt(File.read(f.path), env)
218
220
  @decrypted = nil
221
+ @result = nil
219
222
  end
220
223
  rescue StandardError => e
221
224
  puts e.message
@@ -333,6 +336,7 @@ class EncryptEnv
333
336
  value[key] = new_value
334
337
  encrypt(value.to_hash.to_yaml, env || current_env)
335
338
  @decrypted = nil
339
+ @result = nil
336
340
  puts "#{key}\t=>\t#{value[key]}"
337
341
  end
338
342
 
@@ -373,13 +377,18 @@ class EncryptEnv
373
377
  value[key] = new_value
374
378
  encrypt(value.to_hash.to_yaml, env || current_env)
375
379
  @decrypted = nil
380
+ @result = nil
376
381
  end
377
382
 
378
383
  puts "#{key}\t=>\t#{value[key]}"
379
384
  end
380
385
 
381
386
  def self.secrets
382
- ActiveSupport::OrderedOptions[hash_secrets.deep_symbolize_keys]
387
+ return @result if @result
388
+
389
+ @result = ActiveSupport::OrderedOptions[hash_secrets.deep_symbolize_keys]
390
+
391
+ @result
383
392
  end
384
393
 
385
394
  def self.method_missing(key, *_args)
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.0
4
+ version: 1.4.3
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-16 00:00:00.000000000 Z
11
+ date: 2022-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -30,6 +30,26 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.9.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '5.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 5.0.7
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '5.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 5.0.7
33
53
  description: Encrypts and decrypts environment variables
34
54
  email: nhutan2001@gmail.com
35
55
  executables: