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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b78f4806d12bd235d5f3aea9f6630a58e79b02a1
4
- data.tar.gz: d18595b35cb9de8e7e113d88af83d655411af440
3
+ metadata.gz: 10e6bcd4fd2315011afab684c5cdf0a5d312e323
4
+ data.tar.gz: a6ac1ebe0132ab81ce7b54a518ae70d9b2604f8c
5
5
  SHA512:
6
- metadata.gz: 6fde66600f0e000e2f6154575726140ebe68eb4ea9c8307b1e6fdef66c5e3a06aac70c6743fb4337a920f7febaf96939eff7a010d0ee9d306635dcb74b9c0a87
7
- data.tar.gz: c6cfcab36d74a6ef1e90693aa3c27556b79d111b04cfd6548ea7c7d5a6c032a513d1da9dc5496d45d3e394a9f99afeeb3559a6433cab60532eeb6e34749fc8a3
6
+ metadata.gz: f4c306aa7c74847060d4e7087b4f729efcb074eb7a863cc45e5f52a7184fce3a156473e153d2c6516ce6990fcb615f743f6949a63fba00738554f9c74431058c
7
+ data.tar.gz: 99be5b26009749a9a4a3a429418a2878a4b1fb009fc37c12e61d949fe6c29f190c9eea4352a70c16d6c7927ee8eef3123724524d9135d3356dd338a1a209747a
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
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
- return err
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
- ffi_lib File.expand_path('../../ext/envkey.so', File.dirname(__FILE__))
8
- attach_function :EnvJson, [:string], :string
9
-
10
- def self.load_env
11
- return if ENV['@@ENVKEY_LOADED_ENV']
12
- Dotenv.load
13
-
14
- if ENV["ENVKEY"]
15
- json = EnvJson(ENV["ENVKEY"])
16
- if json.present?
17
- envs = JSON.parse(json)
18
- envs.each do |k,v|
19
- var = k.upcase
20
- ENV[var] = v unless ENV[var]
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
@@ -1,3 +1,3 @@
1
1
  module Envkey
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/envkey.rb CHANGED
@@ -1,12 +1,8 @@
1
1
  require "envkey/version"
2
2
 
3
- begin
4
- require "spring/commands"
5
- Spring.after_fork do
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.0
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-17 00:00:00.000000000 Z
11
+ date: 2017-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler