envred 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/README.md +15 -9
- data/bin/envred +12 -1
- data/lib/envred.rb +3 -3
- data/lib/envred/version.rb +1 -1
- data/spec/envred_spec.rb +13 -9
- 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: f3ee6678715c0bd19243e5232a651a9108d68034
|
4
|
+
data.tar.gz: eb891088a7f599f4d0fca331bb426ced301af346
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29226a5a0c2fd8d1b441288d932db0ecebc35494aaa8870b64ab424dc03c4b153cd8ebc6bad980fe041924296882900f7d70e0603e75e5c90b93848b408358ab
|
7
|
+
data.tar.gz: 073d098e0da64f28020857a047aa973589f30e3857fa8bc75569fa3ccea0dcc0dd1ac0ec240c4c4fb8e41f5baeef22e4615053bcafeb536a7dd3021f941b3087
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
**Environment config loader backed by Redis**
|
4
4
|
|
5
|
+

|
6
|
+
|
5
7
|
This is a simple tool in flavor of `envdir` from daemontools package. Instead of
|
6
8
|
loading environment from directory, it loads it for redis hash specified in
|
7
9
|
the central url. See examples section for details.
|
@@ -16,24 +18,28 @@ Install via rubygems:
|
|
16
18
|
|
17
19
|
Set some variables first:
|
18
20
|
|
19
|
-
$ envred localhost:6379/0
|
21
|
+
$ envred -c localhost:6379/0 -a myapp set FOO 1 BAR 2 BAZ 3
|
20
22
|
|
21
|
-
The `localhost:6379` is host
|
22
|
-
|
23
|
-
the data as hash.
|
23
|
+
The `localhost:6379/0` is host, port and number of Redis database to load
|
24
|
+
stuff from, and `myapp` is the key which keeps the data as hash.
|
24
25
|
|
25
26
|
Now you can run any application with environment loaded from Redis server:
|
26
27
|
|
27
|
-
$ envred localhost:6379/0
|
28
|
+
$ envred -c localhost:6379/0 -a myapp wrap myapp --do something
|
28
29
|
|
29
30
|
To list all your variables use:
|
30
31
|
|
31
|
-
$ envred localhost:6379/0
|
32
|
+
$ envred -c localhost:6379/0~myapp list
|
32
33
|
|
33
34
|
You can remove specific keys or purge all config:
|
34
35
|
|
35
|
-
$ envred localhost:6379/0
|
36
|
-
$ envred localhost:6379/0
|
36
|
+
$ envred -c localhost:6379/0 -a myapp unset FOO BAR
|
37
|
+
$ envred -c localhost:6379/0 -a myapp purge
|
38
|
+
|
39
|
+
Note! Instead of specifying central url all the time, you can store it in
|
40
|
+
`ENVRED_CENTRAL` env variable:
|
41
|
+
|
42
|
+
$ export ENVRED_CENTRAL=localhost:6379/0
|
37
43
|
|
38
44
|
## Hacking
|
39
45
|
|
@@ -54,6 +60,6 @@ Now you should be able to run tests:
|
|
54
60
|
|
55
61
|
## Copyrights
|
56
62
|
|
57
|
-
Copyright (c) by Kris Kovalik
|
63
|
+
Copyright (c) by Kris Kovalik <<hi@kkvlk.me>>
|
58
64
|
|
59
65
|
Released under MIT License. Check [LICENSE.txt](LICENSE.txt) for details.
|
data/bin/envred
CHANGED
@@ -11,8 +11,19 @@ program_desc "Environment configuration backed with Redis."
|
|
11
11
|
desc "The URL of central env server."
|
12
12
|
flag [:c, :central], :default_value => ENV['ENVRED_CENTRAL']
|
13
13
|
|
14
|
+
desc "The name of the app."
|
15
|
+
flag [:a, :app]
|
16
|
+
|
14
17
|
pre do |globals, command, options, args|
|
15
|
-
|
18
|
+
unless globals[:app]
|
19
|
+
help_now!("you must specify a name of the app")
|
20
|
+
end
|
21
|
+
|
22
|
+
unless globals[:central]
|
23
|
+
help_now!("you must specify address of the central server")
|
24
|
+
end
|
25
|
+
|
26
|
+
$envred = Envred.new(globals[:central], globals[:app])
|
16
27
|
end
|
17
28
|
|
18
29
|
desc "Wrap command with loaded env variables."
|
data/lib/envred.rb
CHANGED
@@ -2,9 +2,9 @@ require "envred/version"
|
|
2
2
|
require "redis"
|
3
3
|
|
4
4
|
class Envred
|
5
|
-
def initialize(central)
|
6
|
-
@
|
7
|
-
@redis = Redis.new(url: "redis://#{@
|
5
|
+
def initialize(central, app)
|
6
|
+
@central, @app = central, app
|
7
|
+
@redis = Redis.new(url: "redis://#{@central}")
|
8
8
|
end
|
9
9
|
|
10
10
|
def load
|
data/lib/envred/version.rb
CHANGED
data/spec/envred_spec.rb
CHANGED
@@ -6,7 +6,11 @@ describe Envred do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
let(:central) do
|
9
|
-
"#{server}/0
|
9
|
+
"#{server}/0"
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:app) do
|
13
|
+
"test"
|
10
14
|
end
|
11
15
|
|
12
16
|
let(:redis) do
|
@@ -24,7 +28,7 @@ describe Envred do
|
|
24
28
|
|
25
29
|
describe "#load" do
|
26
30
|
it "loads list of set variables" do
|
27
|
-
all = Envred.new(central).load
|
31
|
+
all = Envred.new(central, app).load
|
28
32
|
all.should have(2).items
|
29
33
|
all['foo'].should == '1'
|
30
34
|
all['bar'].should == '2'
|
@@ -40,7 +44,7 @@ describe Envred do
|
|
40
44
|
it "should load proper configuration and set env" do
|
41
45
|
env = nil
|
42
46
|
|
43
|
-
Envred.new(central).apply do
|
47
|
+
Envred.new(central, app).apply do
|
44
48
|
env = ENV
|
45
49
|
end
|
46
50
|
|
@@ -51,7 +55,7 @@ describe Envred do
|
|
51
55
|
it "should property pass env to commands" do
|
52
56
|
res = nil
|
53
57
|
|
54
|
-
Envred.new(central).apply do
|
58
|
+
Envred.new(central, app).apply do
|
55
59
|
res = `echo $foo $bar`.strip
|
56
60
|
end
|
57
61
|
|
@@ -71,7 +75,7 @@ describe Envred do
|
|
71
75
|
it "should not change existing keys" do
|
72
76
|
res = nil
|
73
77
|
|
74
|
-
Envred.new(central).apply do
|
78
|
+
Envred.new(central, app).apply do
|
75
79
|
res = `echo $foo $bar`.strip
|
76
80
|
end
|
77
81
|
|
@@ -81,7 +85,7 @@ describe Envred do
|
|
81
85
|
it "should remove key if value is empty" do
|
82
86
|
res = nil
|
83
87
|
|
84
|
-
Envred.new(central).apply do
|
88
|
+
Envred.new(central, app).apply do
|
85
89
|
res = `echo $foo $bar $baz`.strip
|
86
90
|
end
|
87
91
|
|
@@ -93,15 +97,15 @@ describe Envred do
|
|
93
97
|
|
94
98
|
describe "#set" do
|
95
99
|
it "should save given variable if non empty" do
|
96
|
-
Envred.new(central).set("foo", 1)
|
100
|
+
Envred.new(central, app).set("foo", 1)
|
97
101
|
redis.hget("test", "foo").should == "1"
|
98
102
|
end
|
99
103
|
end
|
100
104
|
|
101
105
|
describe "#unset" do
|
102
106
|
it "should save given variable if non empty" do
|
103
|
-
Envred.new(central).set("foo", 1)
|
104
|
-
Envred.new(central).unset("foo")
|
107
|
+
Envred.new(central, app).set("foo", 1)
|
108
|
+
Envred.new(central, app).unset("foo")
|
105
109
|
redis.hget("test", "foo").should == nil
|
106
110
|
end
|
107
111
|
end
|