envred 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/bin/envred +87 -51
- data/envred.gemspec +1 -0
- data/lib/envred.rb +22 -34
- data/lib/envred/version.rb +2 -2
- data/spec/{loader_spec.rb → envred_spec.rb} +22 -20
- metadata +17 -5
- data/spec/setter_spec.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97af96bcff96f52e3fc3e7187baf47ce0ceb7ed8
|
4
|
+
data.tar.gz: 2c060c0b6fddb7de2edf675af9a733f9f2d1372b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69ae0ee5f98509150b515b84a590d099d1aa1b0a46af7321e37228e4025a34586fbfb3500baff4255048bb21dcf38f589665d4e74af113956030a93ff616eb2d
|
7
|
+
data.tar.gz: a36fa4a1fb622b70adb4a659a1cd6f210f7c0ef17f0d22df6324fe39ec2847ea39176b3e56f4e6680c4fe97e2a8779200f8f870500aeeaa4928e8abd57ce194b
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Install via rubygems:
|
|
16
16
|
|
17
17
|
Set some variables first:
|
18
18
|
|
19
|
-
$ envred localhost:6379/0/~myapp
|
19
|
+
$ envred localhost:6379/0/~myapp set FOO 1 BAR 2 BAZ 3
|
20
20
|
|
21
21
|
The `localhost:6379` is host anf port of Redis server, `0` is the number of
|
22
22
|
the database to load stuff from, finally, `myapp` is the key which keeps
|
@@ -24,16 +24,16 @@ the data as hash.
|
|
24
24
|
|
25
25
|
Now you can run any application with environment loaded from Redis server:
|
26
26
|
|
27
|
-
$ envred localhost:6379/0/~myapp myapp --do something
|
27
|
+
$ envred localhost:6379/0/~myapp wrap myapp --do something
|
28
28
|
|
29
29
|
To list all your variables use:
|
30
30
|
|
31
|
-
$ envred localhost:6379/0/~myapp
|
31
|
+
$ envred localhost:6379/0/~myapp list
|
32
32
|
|
33
33
|
You can remove specific keys or purge all config:
|
34
34
|
|
35
|
-
$ envred localhost:6379/0/~myapp
|
36
|
-
$ envred localhost:6379/0/~myapp
|
35
|
+
$ envred localhost:6379/0/~myapp unset FOO BAR
|
36
|
+
$ envred localhost:6379/0/~myapp purge
|
37
37
|
|
38
38
|
## Hacking
|
39
39
|
|
data/bin/envred
CHANGED
@@ -2,69 +2,105 @@
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'envred'
|
5
|
+
require 'gli'
|
5
6
|
|
6
|
-
|
7
|
+
include GLI::App
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
program_desc "Environment configuration backed with Redis."
|
10
|
+
|
11
|
+
desc "The URL of central env server."
|
12
|
+
flag [:c, :central], :default_value => ENV['ENVRED_CENTRAL']
|
13
|
+
|
14
|
+
pre do |globals, command, options, args|
|
15
|
+
$envred = Envred.new(globals[:central])
|
13
16
|
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
desc "Wrap command with loaded env variables."
|
19
|
+
long_desc "Executes given command previously setting all loaded env variables."
|
20
|
+
command :wrap do |c|
|
21
|
+
c.action do |globals, options, args|
|
22
|
+
if args.empty?
|
23
|
+
help_now!('you must specify command to run')
|
24
|
+
end
|
25
|
+
|
26
|
+
$envred.apply do
|
27
|
+
exit(system(args.join(" ")))
|
28
|
+
end
|
29
|
+
end
|
20
30
|
end
|
21
31
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
puts "Ok!"
|
32
|
+
desc "List variables."
|
33
|
+
long_desc "Display list of stored variables."
|
34
|
+
command :list do |c|
|
35
|
+
c.action do |globals, options, args|
|
36
|
+
print "Loading all variables..."
|
37
|
+
|
38
|
+
all = $envred.load
|
39
|
+
|
40
|
+
print "\r" + (" " * 40) + "\r"
|
41
|
+
|
42
|
+
if all.empty?
|
43
|
+
puts "No variables to show!"
|
44
|
+
else
|
45
|
+
all.each do |key, val|
|
46
|
+
puts "#{key}=#{val.inspect}"
|
47
|
+
end
|
48
|
+
end
|
40
49
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Set env variables."
|
53
|
+
long_desc "Assigns values to one or more env variale."
|
54
|
+
command :set do |c|
|
55
|
+
c.action do |globals, options, args|
|
56
|
+
if args.size % 2 != 0
|
57
|
+
help_now!("mismatched number of key-value pair arguments")
|
58
|
+
elsif args.size < 2
|
59
|
+
help_now!("you must specify at leat one key-value pair")
|
60
|
+
end
|
61
|
+
|
62
|
+
print "Saving variables... "
|
63
|
+
|
64
|
+
$envred.set(*args)
|
65
|
+
|
46
66
|
puts "Ok!"
|
47
67
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
68
|
+
end
|
69
|
+
|
70
|
+
desc "Remove variables."
|
71
|
+
long_desc "Removes one or more env variable."
|
72
|
+
command :unset do |c|
|
73
|
+
c.action do |globals, options, args|
|
74
|
+
if args.empty?
|
75
|
+
help_now!("you must specify at leat one key to remove")
|
54
76
|
end
|
77
|
+
|
78
|
+
print "Removing variables... "
|
79
|
+
|
80
|
+
$envred.unset(*args)
|
81
|
+
|
82
|
+
puts "Ok!"
|
55
83
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
84
|
+
end
|
85
|
+
|
86
|
+
desc "Delete all variables."
|
87
|
+
long_desc "Removes all stored variables from the project."
|
88
|
+
command :purge do |c|
|
89
|
+
c.action do |globals, options, args|
|
90
|
+
print "Purging variables list... "
|
91
|
+
|
92
|
+
$envred.purge
|
93
|
+
|
61
94
|
puts "Ok!"
|
62
95
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
96
|
+
end
|
97
|
+
|
98
|
+
desc "Display current version."
|
99
|
+
long_desc "Displays current version number."
|
100
|
+
command :version do |c|
|
101
|
+
c.action do |globals, options, args|
|
102
|
+
puts "envred v#{Envred::VERSION}"
|
69
103
|
end
|
70
104
|
end
|
105
|
+
|
106
|
+
exit run(ARGV)
|
data/envred.gemspec
CHANGED
data/lib/envred.rb
CHANGED
@@ -1,49 +1,37 @@
|
|
1
1
|
require "envred/version"
|
2
2
|
require "redis"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@redis = Redis.new(url: "redis://#{@server}")
|
9
|
-
end
|
4
|
+
class Envred
|
5
|
+
def initialize(central)
|
6
|
+
@server, @app = central.split("/~")
|
7
|
+
@redis = Redis.new(url: "redis://#{@server}")
|
10
8
|
end
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def each(*args, &block)
|
18
|
-
load.each(*args, &block)
|
19
|
-
end
|
10
|
+
def load
|
11
|
+
@redis.hgetall(@app) or []
|
12
|
+
end
|
20
13
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
14
|
+
def apply
|
15
|
+
load.each do |key, val|
|
16
|
+
if val == ''
|
17
|
+
ENV.delete(key)
|
18
|
+
else
|
19
|
+
ENV[key] = val if ENV[key] === nil
|
28
20
|
end
|
29
|
-
|
30
|
-
yield if block_given?
|
31
21
|
end
|
22
|
+
|
23
|
+
yield if block_given?
|
32
24
|
end
|
33
25
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
26
|
+
def set(*values)
|
27
|
+
@redis.hmset(@app, *values)
|
28
|
+
end
|
38
29
|
|
39
|
-
|
40
|
-
|
41
|
-
end
|
30
|
+
def unset(*keys)
|
31
|
+
@redis.hdel(@app, keys)
|
42
32
|
end
|
43
33
|
|
44
|
-
|
45
|
-
|
46
|
-
@redis.del(@app)
|
47
|
-
end
|
34
|
+
def purge
|
35
|
+
@redis.del(@app)
|
48
36
|
end
|
49
37
|
end
|
data/lib/envred/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
class Envred
|
2
|
+
VERSION = "0.2.0"
|
3
3
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path("../spec_helper.rb", __FILE__)
|
2
2
|
|
3
|
-
describe Envred
|
3
|
+
describe Envred do
|
4
4
|
let(:server) do
|
5
5
|
ENV['REDIS_URL'].split('redis://').last.split('/').first
|
6
6
|
end
|
@@ -18,26 +18,13 @@ describe Envred::Loader do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
before do
|
21
|
+
redis.flushdb()
|
21
22
|
redis.mapped_hmset("test", setenv)
|
22
23
|
end
|
23
24
|
|
24
25
|
describe "#load" do
|
25
26
|
it "loads list of set variables" do
|
26
|
-
all = Envred
|
27
|
-
all.should have(2).items
|
28
|
-
all['foo'].should == '1'
|
29
|
-
all['bar'].should == '2'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "#load" do
|
34
|
-
it "loads list of set variables and produces an iterator for it" do
|
35
|
-
all = {}
|
36
|
-
|
37
|
-
Envred::Loader.new(central).each do |key, val|
|
38
|
-
all[key] = val
|
39
|
-
end
|
40
|
-
|
27
|
+
all = Envred.new(central).load
|
41
28
|
all.should have(2).items
|
42
29
|
all['foo'].should == '1'
|
43
30
|
all['bar'].should == '2'
|
@@ -53,7 +40,7 @@ describe Envred::Loader do
|
|
53
40
|
it "should load proper configuration and set env" do
|
54
41
|
env = nil
|
55
42
|
|
56
|
-
Envred
|
43
|
+
Envred.new(central).apply do
|
57
44
|
env = ENV
|
58
45
|
end
|
59
46
|
|
@@ -64,7 +51,7 @@ describe Envred::Loader do
|
|
64
51
|
it "should property pass env to commands" do
|
65
52
|
res = nil
|
66
53
|
|
67
|
-
Envred
|
54
|
+
Envred.new(central).apply do
|
68
55
|
res = `echo $foo $bar`.strip
|
69
56
|
end
|
70
57
|
|
@@ -84,7 +71,7 @@ describe Envred::Loader do
|
|
84
71
|
it "should not change existing keys" do
|
85
72
|
res = nil
|
86
73
|
|
87
|
-
Envred
|
74
|
+
Envred.new(central).apply do
|
88
75
|
res = `echo $foo $bar`.strip
|
89
76
|
end
|
90
77
|
|
@@ -94,7 +81,7 @@ describe Envred::Loader do
|
|
94
81
|
it "should remove key if value is empty" do
|
95
82
|
res = nil
|
96
83
|
|
97
|
-
Envred
|
84
|
+
Envred.new(central).apply do
|
98
85
|
res = `echo $foo $bar $baz`.strip
|
99
86
|
end
|
100
87
|
|
@@ -103,4 +90,19 @@ describe Envred::Loader do
|
|
103
90
|
end
|
104
91
|
end
|
105
92
|
end
|
93
|
+
|
94
|
+
describe "#set" do
|
95
|
+
it "should save given variable if non empty" do
|
96
|
+
Envred.new(central).set("foo", 1)
|
97
|
+
redis.hget("test", "foo").should == "1"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#unset" do
|
102
|
+
it "should save given variable if non empty" do
|
103
|
+
Envred.new(central).set("foo", 1)
|
104
|
+
Envred.new(central).unset("foo")
|
105
|
+
redis.hget("test", "foo").should == nil
|
106
|
+
end
|
107
|
+
end
|
106
108
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envred
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Kovalik
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: gli
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.9'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.9'
|
69
83
|
description: This is a tool/wrapper for the apps that set env configuration from given
|
70
84
|
redis machine.
|
71
85
|
email:
|
@@ -84,8 +98,7 @@ files:
|
|
84
98
|
- envred.gemspec
|
85
99
|
- lib/envred.rb
|
86
100
|
- lib/envred/version.rb
|
87
|
-
- spec/
|
88
|
-
- spec/setter_spec.rb
|
101
|
+
- spec/envred_spec.rb
|
89
102
|
- spec/spec_helper.rb
|
90
103
|
- wercker.yml
|
91
104
|
homepage: https://github.com/kkvlk/envred
|
@@ -113,6 +126,5 @@ signing_key:
|
|
113
126
|
specification_version: 4
|
114
127
|
summary: Redis backend env setup proxy.
|
115
128
|
test_files:
|
116
|
-
- spec/
|
117
|
-
- spec/setter_spec.rb
|
129
|
+
- spec/envred_spec.rb
|
118
130
|
- spec/spec_helper.rb
|
data/spec/setter_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require File.expand_path("../spec_helper.rb", __FILE__)
|
2
|
-
|
3
|
-
describe Envred::Setter do
|
4
|
-
let(:server) do
|
5
|
-
ENV['REDIS_URL'].split('redis://').last.split('/').first
|
6
|
-
end
|
7
|
-
|
8
|
-
let(:central) do
|
9
|
-
"#{server}/0/~test"
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:redis) do
|
13
|
-
Redis.new(url: "redis://#{server}/0")
|
14
|
-
end
|
15
|
-
|
16
|
-
before do
|
17
|
-
redis.flushdb()
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "#set" do
|
21
|
-
it "should save given variable if non empty" do
|
22
|
-
Envred::Setter.new(central).set("foo", 1)
|
23
|
-
redis.hget("test", "foo").should == "1"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#unset" do
|
28
|
-
it "should save given variable if non empty" do
|
29
|
-
Envred::Setter.new(central).set("foo", 1)
|
30
|
-
Envred::Setter.new(central).unset("foo")
|
31
|
-
redis.hget("test", "foo").should == nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|