envkey 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/ext/envkey.go +3 -2
- data/ext/envkey.so +0 -0
- data/lib/envkey/core.rb +47 -18
- data/lib/envkey/rails.rb +19 -0
- data/lib/envkey/version.rb +1 -1
- data/lib/envkey.rb +3 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10e6bcd4fd2315011afab684c5cdf0a5d312e323
|
4
|
+
data.tar.gz: a6ac1ebe0132ab81ce7b54a518ae70d9b2604f8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4c306aa7c74847060d4e7087b4f729efcb074eb7a863cc45e5f52a7184fce3a156473e153d2c6516ce6990fcb615f743f6949a63fba00738554f9c74431058c
|
7
|
+
data.tar.gz: 99be5b26009749a9a4a3a429418a2878a4b1fb009fc37c12e61d949fe6c29f190c9eea4352a70c16d6c7927ee8eef3123724524d9135d3356dd338a1a209747a
|
data/.gitignore
CHANGED
data/ext/envkey.go
CHANGED
@@ -5,7 +5,6 @@ import (
|
|
5
5
|
"bytes"
|
6
6
|
"strings"
|
7
7
|
"net/http"
|
8
|
-
// "fmt"
|
9
8
|
"encoding/json"
|
10
9
|
"io/ioutil"
|
11
10
|
"log"
|
@@ -42,7 +41,8 @@ func EnvJson(envkey *C.char) *C.char {
|
|
42
41
|
func getJson(url string, target interface{}) error {
|
43
42
|
r, err := http.Get(url)
|
44
43
|
if err != nil {
|
45
|
-
|
44
|
+
log.Fatal(err)
|
45
|
+
return err
|
46
46
|
}
|
47
47
|
defer r.Body.Close()
|
48
48
|
|
@@ -55,6 +55,7 @@ func decrypt(cipher, privkey, pw string) (string, error) {
|
|
55
55
|
entityList, err := openpgp.ReadArmoredKeyRing(keyringFileBuffer)
|
56
56
|
if (err != nil){
|
57
57
|
log.Fatal(err)
|
58
|
+
return "", err
|
58
59
|
}
|
59
60
|
entity := entityList[0]
|
60
61
|
|
data/ext/envkey.so
CHANGED
Binary file
|
data/lib/envkey/core.rb
CHANGED
@@ -1,28 +1,57 @@
|
|
1
1
|
require 'ffi'
|
2
2
|
require 'dotenv'
|
3
3
|
require 'json'
|
4
|
+
require 'set'
|
4
5
|
|
5
6
|
module Envkey::Core
|
6
7
|
extend FFI::Library
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
Dotenv.load
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
8
|
+
|
9
|
+
def self.load_env spring_pre_fork_ts=nil,
|
10
|
+
overload_dotenv_vars=[],
|
11
|
+
overload_envkey_vars=[]
|
12
|
+
original_env = ENV.to_h
|
13
|
+
dotenv_vars = Dotenv.load
|
14
|
+
updated_dotenv_vars = dotenv_vars.keys.select do |k|
|
15
|
+
overload_dotenv_vars.include?(k) || original_env[k] == nil
|
16
|
+
end
|
17
|
+
overload_dotenv_vars.each do |k|
|
18
|
+
ENV[k] = dotenv_vars[k]
|
19
|
+
end
|
20
|
+
|
21
|
+
if (key = ENV["ENVKEY"])
|
22
|
+
reader, writer = IO.pipe
|
23
|
+
|
24
|
+
fork do
|
25
|
+
reader.close
|
26
|
+
|
27
|
+
ffi_lib File.expand_path('../../ext/envkey.so', File.dirname(__FILE__))
|
28
|
+
attach_function :EnvJson, [:pointer], :string
|
29
|
+
|
30
|
+
json = EnvJson(FFI::MemoryPointer.from_string(key))
|
31
|
+
writer.puts json
|
32
|
+
end
|
33
|
+
|
34
|
+
writer.close
|
35
|
+
while json = reader.gets
|
36
|
+
if json && json.gsub("\n","").gsub("\r", "") != ""
|
37
|
+
envs = JSON.parse(json)
|
38
|
+
updated_envkey_vars = []
|
39
|
+
envs.each do |k,v|
|
40
|
+
var = k.upcase
|
41
|
+
if !ENV[var] || overload_envkey_vars.include?(var)
|
42
|
+
updated_envkey_vars << var
|
43
|
+
ENV[var] = v
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# avoid printing success message twice in quick succession when using spring
|
48
|
+
if !spring_pre_fork_ts || (Time.now - spring_pre_fork_ts) > 3
|
49
|
+
puts "ENVKEY: vars loaded and decrypted - access with ENV['YOUR_VAR_NAME']"
|
50
|
+
end
|
51
|
+
return [Set.new(updated_dotenv_vars), Set.new(updated_envkey_vars)]
|
52
|
+
else
|
53
|
+
raise "Envkey invalid. Couldn't load env."
|
21
54
|
end
|
22
|
-
ENV['@@ENVKEY_LOADED_ENV'] = "true"
|
23
|
-
puts "ENVKEY: env loaded and decrypted - access via ENV"
|
24
|
-
else
|
25
|
-
raise "Envkey invalid. Couldn't load env."
|
26
55
|
end
|
27
56
|
end
|
28
57
|
end
|
data/lib/envkey/rails.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "envkey/core"
|
2
|
+
|
3
|
+
module Envkey
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
|
6
|
+
config.before_configuration do
|
7
|
+
begin
|
8
|
+
require "spring/commands"
|
9
|
+
ts = Time.now
|
10
|
+
overload_dotenv_vars, overload_envkey_vars = Envkey::Core.load_env
|
11
|
+
Spring.after_fork do
|
12
|
+
Envkey::Core.load_env(ts, overload_dotenv_vars, overload_envkey_vars)
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
Envkey::Core.load_env
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/envkey/version.rb
CHANGED
data/lib/envkey.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
require "envkey/version"
|
2
2
|
|
3
|
-
|
4
|
-
require "
|
5
|
-
|
6
|
-
require "envkey/core"
|
7
|
-
Envkey::Core.load_env
|
8
|
-
end
|
9
|
-
rescue LoadError
|
3
|
+
if defined?(Rails)
|
4
|
+
require "envkey/rails"
|
5
|
+
else
|
10
6
|
require "envkey/core"
|
11
7
|
Envkey::Core.load_env
|
12
8
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dane Schneider
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|