dev_secrets 0.1.0 → 0.2.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 +4 -4
- data/lib/dev_secrets.rb +36 -1
- data/lib/dev_secrets/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b74233873f6fc682157fceb6b886260c95df36fe
|
4
|
+
data.tar.gz: e72f90e0fd23ca963f9fc4b53b647a3b4eae21ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5468a44e3db5aa82f0b5bd3a7f40e142bd1745ef5a27dda851db372deb74728d78c7a765134282dcfe302ab01e777d352ce15df4e3a3d45d877ead205ce1ae5e
|
7
|
+
data.tar.gz: f5039fec8f3125c5e9690bfad2653be61004a21590b6af469a3b7025d7c85b762079f9e7efc50eb20c5b3fe91d8660a987f50979e7de62a390ef8fb17b4f4f01
|
data/lib/dev_secrets.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module DevSecrets
|
2
|
+
GLOB = "secrets*.yml{,.enc}"
|
3
|
+
GLOB_ENC = "secrets*.yml.enc"
|
2
4
|
class Railtie < ::Rails::Railtie
|
3
5
|
initializer "dev_secrets.set_secrets_glob_pattern" do |app|
|
4
|
-
app.config.paths["config/secrets"].glob =
|
6
|
+
app.config.paths["config/secrets"].glob = DevSecrets::GLOB
|
5
7
|
end
|
6
8
|
end
|
7
9
|
end
|
@@ -39,8 +41,41 @@ module Rails
|
|
39
41
|
alias parse_original parse
|
40
42
|
alias parse _dev_secrets_parse
|
41
43
|
|
44
|
+
def _dev_secrets_read_for_editing
|
45
|
+
path, contents = _dev_secrets_read_first
|
46
|
+
tmp_path = File.join(Dir.tmpdir, File.basename(path))
|
47
|
+
IO.binwrite(tmp_path, contents)
|
48
|
+
|
49
|
+
puts "Editing #{path}"
|
50
|
+
yield tmp_path
|
51
|
+
|
52
|
+
_dev_secrets_write(path, File.read(tmp_path))
|
53
|
+
ensure
|
54
|
+
FileUtils.rm(tmp_path) if File.exist?(tmp_path)
|
55
|
+
end
|
56
|
+
|
57
|
+
alias read_for_editing_original read_for_editing
|
58
|
+
alias read_for_editing _dev_secrets_read_for_editing
|
59
|
+
|
42
60
|
private
|
43
61
|
|
62
|
+
def _dev_secrets_read_first
|
63
|
+
return_val = nil
|
64
|
+
Dir.glob(@root.join("config", DevSecrets::GLOB_ENC)).each do |path|
|
65
|
+
begin
|
66
|
+
return_val = [path, decrypt(IO.binread(path))]
|
67
|
+
break
|
68
|
+
rescue ActiveSupport::MessageEncryptor::InvalidMessage
|
69
|
+
end
|
70
|
+
end
|
71
|
+
return_val or raise ActiveSupport::MessageEncryptor::InvalidMessage # Nothing decrypted correctly
|
72
|
+
end
|
73
|
+
|
74
|
+
def _dev_secrets_write(path, contents)
|
75
|
+
IO.binwrite("#{path}.tmp", encrypt(contents))
|
76
|
+
FileUtils.mv("#{path}.tmp", path)
|
77
|
+
end
|
78
|
+
|
44
79
|
def _dev_secrets_parse_file(path, env, all_secrets)
|
45
80
|
require "erb"
|
46
81
|
secrets = YAML.load(ERB.new(preprocess(path)).result) || {}
|
data/lib/dev_secrets/version.rb
CHANGED