conferred 0.2.0 → 0.3.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/VERSION +1 -1
- data/conferred.gemspec +3 -3
- data/lib/conferred.rb +43 -4
- data/spec/conferred_spec.rb +99 -33
- 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: 7d42c798e9698f16e34098f2f240626a6f2528f2
|
4
|
+
data.tar.gz: fcea3291bb6d580ac49db5f7a0cd215d07d87c26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7325d9e08923b035096569225b5d1b024cf6bdfe94d149ac4c312f3a80e9f4aab5d93fc575881ad3dd4d27ad8c4f2d8c9e98d8af0c35bc880b2e7f48c7313304
|
7
|
+
data.tar.gz: f6dead5553dbe6c3cde1d1cb41045c5a71df70378884272953451f1ab1183327510af95304ef631dc8b49136ce5be6112b88326d59368546dfb0bc64cf6ba459
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/conferred.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: conferred 0.
|
5
|
+
# stub: conferred 0.3.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "conferred"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.3.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Ian Kenney"]
|
14
|
-
s.date = "2015-
|
14
|
+
s.date = "2015-12-05"
|
15
15
|
s.description = "inspired by the 12 factor app http://12factor.net/config "
|
16
16
|
s.email = "ian@lostock.co.uk"
|
17
17
|
s.extra_rdoc_files = [
|
data/lib/conferred.rb
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
3
|
class Conferred
|
4
|
+
DEFAULT_ETCD_HOST = "172.17.42.1"
|
5
|
+
DEFAULT_ETCD_PORT = "2379"
|
6
|
+
DEFAULT_ETCD_SCHEME = "http"
|
7
|
+
|
4
8
|
@@provider = "env"
|
9
|
+
@@etcd_scheme = DEFAULT_ETCD_SCHEME
|
10
|
+
@@etcd_host = DEFAULT_ETCD_HOST
|
11
|
+
@@etcd_port = DEFAULT_ETCD_PORT
|
12
|
+
@@namespace = ""
|
13
|
+
|
5
14
|
class << self
|
15
|
+
# attr_writer :etcd_port, :etcd_scheme, :etcd_host
|
6
16
|
def provider=(value)
|
7
17
|
@@provider=value
|
8
18
|
end
|
@@ -16,11 +26,35 @@ class Conferred
|
|
16
26
|
end
|
17
27
|
|
18
28
|
def namespace
|
19
|
-
@@namespace || ENV["
|
29
|
+
@@namespace || ENV["CONFERRED_ETCD_NAMESPACE"] || ""
|
30
|
+
end
|
31
|
+
|
32
|
+
def etcd_host
|
33
|
+
# if not provided set host to default docker host ip from within a container
|
34
|
+
@@etcd_host || ENV["CONFERRED_ETCD_HOST"] || DEFAULT_ETCD_HOST
|
20
35
|
end
|
21
36
|
|
37
|
+
def etcd_port
|
38
|
+
@@etcd_port || ENV["CONFERRED_ETCD_PORT"] || DEFAULT_ETCD_PORT
|
39
|
+
end
|
40
|
+
|
41
|
+
def etcd_scheme
|
42
|
+
@@etcd_scheme || ENV["CONFERRED_ETCD_SCHEME"] || DEFAULT_ETCD_SCHEME
|
43
|
+
end
|
22
44
|
|
23
|
-
def
|
45
|
+
def etcd_port=(port)
|
46
|
+
@@etcd_port = port
|
47
|
+
end
|
48
|
+
|
49
|
+
def etcd_host=(host)
|
50
|
+
@@etcd_host = host
|
51
|
+
end
|
52
|
+
|
53
|
+
def etcd_scheme=(scheme)
|
54
|
+
@@etcd_scheme = scheme
|
55
|
+
end
|
56
|
+
|
57
|
+
def method_missing(setting, *args, &block)
|
24
58
|
super if setting =~ /#{provider}_setting_value/
|
25
59
|
method = :setting_value
|
26
60
|
method = :setting_value? if setting[-1] == "?"
|
@@ -33,7 +67,7 @@ class Conferred
|
|
33
67
|
end
|
34
68
|
|
35
69
|
def setting_value(key)
|
36
|
-
#raise "
|
70
|
+
#raise "Conferred: Undefined provider (#{@@provider})" unless self.responds_to setting_method_name
|
37
71
|
self.send(setting_method_name, key)
|
38
72
|
end
|
39
73
|
|
@@ -45,6 +79,10 @@ class Conferred
|
|
45
79
|
self.setting_value(key) || raise("#{self.setting_name(key)} missing from environment")
|
46
80
|
end
|
47
81
|
|
82
|
+
def etcd_setting_prefix
|
83
|
+
"#{self.etcd_scheme}://#{self.etcd_host}:#{self.etcd_port}/#{etcd_setting_namespace}"
|
84
|
+
end
|
85
|
+
|
48
86
|
private
|
49
87
|
|
50
88
|
def env_setting_value(key)
|
@@ -61,7 +99,7 @@ class Conferred
|
|
61
99
|
end
|
62
100
|
|
63
101
|
def etcd_setting_endpoint(key)
|
64
|
-
URI("
|
102
|
+
URI("#{self.etcd_setting_prefix}#{key}")
|
65
103
|
end
|
66
104
|
|
67
105
|
def etcd_setting_namespace
|
@@ -70,6 +108,7 @@ class Conferred
|
|
70
108
|
"#{self.namespace}/"
|
71
109
|
end
|
72
110
|
|
111
|
+
|
73
112
|
def setting_method_name
|
74
113
|
"#{self.provider}_setting_value".to_sym
|
75
114
|
end
|
data/spec/conferred_spec.rb
CHANGED
@@ -70,62 +70,128 @@ describe "Conferred" do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
|
73
|
+
context "provider: etcd" do
|
74
74
|
before do
|
75
75
|
Conferred.provider = "etcd"
|
76
76
|
end
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
describe "#namespace" do
|
79
|
+
context "configured namespace" do
|
80
|
+
before do
|
81
|
+
Conferred.namespace = nil
|
82
|
+
end
|
83
|
+
|
84
|
+
it "defaults to empty namespace" do
|
85
|
+
expect(Conferred.namespace).to eq ""
|
86
|
+
end
|
87
|
+
|
88
|
+
it "sets a namespace" do
|
89
|
+
Conferred.namespace = "section"
|
90
|
+
expect(Conferred.namespace).to eq "section"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "reads from environment" do
|
94
|
+
set_envs "CONFERRED_ETCD_NAMESPACE" => "xyz"
|
95
|
+
expect(Conferred.namespace).to eq "xyz"
|
96
|
+
end
|
81
97
|
end
|
82
98
|
|
83
|
-
|
84
|
-
|
85
|
-
|
99
|
+
context "inferred namespace" do
|
100
|
+
before do
|
101
|
+
set_envs "CONFERRED_ETCD_NAMESPACE" => "monty"
|
102
|
+
end
|
86
103
|
|
104
|
+
it "defers to the environment" do
|
105
|
+
expect(Conferred.namespace).to eq "monty"
|
106
|
+
end
|
87
107
|
|
88
|
-
|
89
|
-
|
90
|
-
.
|
91
|
-
|
108
|
+
it "configured value overides environment" do
|
109
|
+
Conferred.namespace = "sect"
|
110
|
+
expect(Conferred.namespace).to eq "sect"
|
111
|
+
end
|
92
112
|
end
|
93
113
|
end
|
94
114
|
|
95
|
-
|
115
|
+
describe "#etcd_host" do
|
96
116
|
before do
|
97
|
-
|
117
|
+
Conferred.etcd_host = nil
|
118
|
+
end
|
119
|
+
|
120
|
+
it "defaults to docker host" do
|
121
|
+
expect(Conferred.etcd_host).to eq "172.17.42.1"
|
98
122
|
end
|
99
123
|
|
100
|
-
it "
|
101
|
-
|
124
|
+
it "reads from CONFERRED_ETCD_HOST environment" do
|
125
|
+
set_envs "CONFERRED_ETCD_HOST" => "myhost"
|
126
|
+
expect(Conferred.etcd_host).to eq "myhost"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "#etcd_port" do
|
131
|
+
before do
|
132
|
+
Conferred.etcd_port = nil
|
102
133
|
end
|
134
|
+
it "defaults to 2379" do
|
135
|
+
expect(Conferred.etcd_port).to eq "2379"
|
136
|
+
end
|
137
|
+
|
138
|
+
it "reads environment" do
|
139
|
+
set_envs "CONFERRED_ETCD_PORT" => "1234"
|
140
|
+
expect(Conferred.etcd_port).to eq "1234"
|
141
|
+
end
|
103
142
|
|
104
|
-
it "
|
105
|
-
Conferred.
|
106
|
-
expect(Conferred.
|
143
|
+
it "allows assignment" do
|
144
|
+
Conferred.etcd_port = "4321"
|
145
|
+
expect(Conferred.etcd_port).to eq "4321"
|
107
146
|
end
|
108
147
|
end
|
109
|
-
end
|
110
148
|
|
111
|
-
|
112
|
-
|
113
|
-
|
149
|
+
describe "#etcd_scheme" do
|
150
|
+
before do
|
151
|
+
Conferred.etcd_scheme = nil
|
152
|
+
end
|
153
|
+
it "defaults to http" do
|
154
|
+
expect(Conferred.etcd_scheme).to eq "http"
|
155
|
+
end
|
156
|
+
|
157
|
+
it "reads environment" do
|
158
|
+
set_envs "CONFERRED_ETCD_SCHEME" => "sftp"
|
159
|
+
expect(Conferred.etcd_scheme).to eq "sftp"
|
160
|
+
end
|
161
|
+
|
162
|
+
it "allows assignment" do
|
163
|
+
Conferred.etcd_scheme = "https"
|
164
|
+
expect(Conferred.etcd_scheme).to eq "https"
|
165
|
+
end
|
114
166
|
end
|
115
167
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
168
|
+
|
169
|
+
|
170
|
+
describe "#etc_setting_prefix" do
|
171
|
+
it "uses the provided settings" do
|
172
|
+
Conferred.etcd_scheme = "https"
|
173
|
+
Conferred.etcd_host = "etcd.host"
|
174
|
+
Conferred.etcd_port = "2222"
|
175
|
+
Conferred.namespace = "my-section"
|
176
|
+
expect(Conferred.etcd_setting_prefix).to eq "https://etcd.host:2222/my-section/"
|
177
|
+
end
|
121
178
|
end
|
122
179
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
180
|
+
describe "value lookup" do
|
181
|
+
it "calls the correct lookup function based on provider" do
|
182
|
+
allow(Net::HTTP).to receive(:get)
|
183
|
+
.with(URI("#{Conferred.etcd_setting_prefix}secret"))
|
184
|
+
.and_return('{"action":"get","node":{"key":"/secret","value":"foo","modifiedIndex":2962,"createdIndex":2962}}')
|
185
|
+
expect(Conferred.secret).to eq "foo"
|
186
|
+
end
|
187
|
+
|
188
|
+
it "falls back to the environment" do
|
189
|
+
ENV["EXTRA_SECRET"] = "shh"
|
190
|
+
allow(Net::HTTP).to receive(:get)
|
191
|
+
.with(URI("#{Conferred.etcd_setting_prefix}extra_secret"))
|
192
|
+
.and_return("")
|
193
|
+
expect(Conferred.extra_secret).to eq "shh"
|
194
|
+
end
|
129
195
|
end
|
130
196
|
end
|
131
197
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conferred
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Kenney
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|