keyth 0.0.1 → 0.1.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.
- data/lib/keyth/dotenv.rb +26 -0
- data/lib/keyth/yaml.rb +11 -0
- data/lib/keyth.rb +12 -10
- metadata +3 -1
data/lib/keyth/dotenv.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Monkey-patch DotEnv if in use to substitute keys when applying
|
3
|
+
module Dotenv
|
4
|
+
# The two apply functions are all that need to be overwritten
|
5
|
+
class Environment
|
6
|
+
def apply
|
7
|
+
each do |k, v|
|
8
|
+
if v =~ /^keyth\:(.*)/
|
9
|
+
ENV[k] = Keyth.get_key_safe(Regexp.last_match[1]) || ''
|
10
|
+
else
|
11
|
+
ENV[k] ||= v
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def apply
|
17
|
+
each do |k, v|
|
18
|
+
if v =~ /^keyth\:(.*)/
|
19
|
+
ENV[k] = Keyth.get_key_safe(Regexp.last_match[1]) || ''
|
20
|
+
else
|
21
|
+
ENV[k] = v
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/keyth/yaml.rb
ADDED
data/lib/keyth.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'yaml'
|
3
|
+
require 'keyth/yaml'
|
4
|
+
require 'keyth/dotenv'
|
3
5
|
|
4
6
|
# Keyhandling module with various functions for keeping keys
|
5
7
|
# out of configuration files.
|
@@ -45,7 +47,7 @@ module Keyth
|
|
45
47
|
|
46
48
|
def self.load_yaml(file)
|
47
49
|
load_keyfile unless @key_list
|
48
|
-
keys = YAML.
|
50
|
+
keys = YAML.pre_keyth_load(file)
|
49
51
|
fetch_keys(keys)
|
50
52
|
end
|
51
53
|
|
@@ -57,15 +59,19 @@ module Keyth
|
|
57
59
|
obj[k] = fetch_keys(v)
|
58
60
|
end
|
59
61
|
when obj.respond_to?(:each)
|
60
|
-
obj.
|
61
|
-
fetch_keys(v)
|
62
|
+
obj.each_with_index do |v, i|
|
63
|
+
obj[i] = fetch_keys(v)
|
62
64
|
end
|
63
65
|
when obj.is_a?(String)
|
64
|
-
obj.gsub
|
66
|
+
obj = obj.gsub(/^keyth\:(.*)/) { get_key(Regexp.last_match[1]) }
|
65
67
|
end
|
66
68
|
obj
|
67
69
|
end
|
68
70
|
|
71
|
+
class << self
|
72
|
+
alias_method(:apply_to, :fetch_keys)
|
73
|
+
end
|
74
|
+
|
69
75
|
def self.namespace(namespace)
|
70
76
|
@namespace = namespace
|
71
77
|
@keylist = nil
|
@@ -79,7 +85,7 @@ module Keyth
|
|
79
85
|
|
80
86
|
def self.load_keyfile
|
81
87
|
if File.file?(keyfile_location)
|
82
|
-
@key_list = YAML.
|
88
|
+
@key_list = YAML.pre_keyth_load(File.open(keyfile_location))
|
83
89
|
else
|
84
90
|
@key_list = {}
|
85
91
|
end
|
@@ -91,10 +97,6 @@ module Keyth
|
|
91
97
|
end
|
92
98
|
end
|
93
99
|
|
94
|
-
# puts Keyth.fetch_keys 'keyth:es-upbeat-home-dev/NEW_RELIC_LICENSE'
|
95
100
|
|
96
|
-
# keys = YAML.load(File.open('../my_deets.yml'))
|
97
|
-
# keys = Keyth.fetch_keys(keys)
|
98
|
-
# puts keys.to_s
|
99
101
|
|
100
|
-
|
102
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keyth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -19,6 +19,8 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- lib/keyth.rb
|
22
|
+
- lib/keyth/yaml.rb
|
23
|
+
- lib/keyth/dotenv.rb
|
22
24
|
- bin/keyth_admin
|
23
25
|
homepage: http://rubygems.org/gems/keyth
|
24
26
|
licenses:
|