envred 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f00ca1e95e16ed62ffb274022b449eb90889b99c
4
+ data.tar.gz: 2003ad3e0932adc11a839867f39f2ec2f9139527
5
+ SHA512:
6
+ metadata.gz: b18f757f9c4beacf403a2c30564df0ff10e35ad5e0a7e3da181b15c2877c48f4870525965a1629b39192ccfe0bcd077195fef4f7e428bcbf3f2f3ca7439acf3d
7
+ data.tar.gz: 7309507e424ad2190145566d4318339e54bda3eb9d5781041951355d7e223f612b21485262eabc3a855ecbefdf80a65c908f471b2316f9a3430718207362e6f3
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ \#*
19
+ .\#*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in envred.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kris Kovalik
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # envred
2
+
3
+ **Environment config loader backed by Redis**
4
+
5
+ This is a simple tool in flavor of `envdir` from daemontools package. Instead of
6
+ loading environment from directory, it loads it for redis hash specified in
7
+ the central url. See examples section for details.
8
+
9
+ ## Installation
10
+
11
+ Install via rubygems:
12
+
13
+ $ gem install envred
14
+
15
+ ## Usage
16
+
17
+ Run application with environment loaded from Redis server:
18
+
19
+ $ envred localhost:6379/0/~myapp myapp --do something
20
+
21
+ The `localhost:6379` is host anf port of Redis server, `0` is the number of
22
+ the database to load stuff from, finally, `myapp` is the key which keeps
23
+ the data as hash.
24
+
25
+ ## Hacking
26
+
27
+ If you wanna hack on the repo for some reason, first clone it, then run:
28
+
29
+ $ bundle install
30
+
31
+ Now you should be able to run tests:
32
+
33
+ $ rake
34
+
35
+ ## Contributing
36
+
37
+ 1. Work on your changes in a feature branch.
38
+ 2. Make sure that tests are passing.
39
+ 3. Send a pull request.
40
+ 4. Wait for feedback.
41
+
42
+ ## Copyrights
43
+
44
+ Copyright (c) by Kris Kovalik <hi@kkvlk.me>
45
+
46
+ Released under MIT License. Check [LICENSE.txt](LICENSE.txt) for details.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'envred'
5
+
6
+ case ARGV[0]
7
+ when "-h", "--help"
8
+ puts "usage: envred [-h|--help] [CENTRAL] [COMMAND]"
9
+ exit
10
+ when "-v", "--version"
11
+ puts "envred v#{Envred::VERSION}"
12
+ exit
13
+ end
14
+
15
+ if ARGV.size < 2
16
+ $stderr.write("ERROR: Invalid parameters. Run with `-h' flag for help.\n")
17
+ exit(1)
18
+ end
19
+
20
+ Envred.wrap(ARGV.shift, ARGV.join(" "))
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'envred/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "envred"
8
+ spec.version = Envred::VERSION
9
+ spec.authors = ["Kris Kovalik"]
10
+ spec.email = ["hi@kkvlk.me"]
11
+ spec.description = %q{This is a tool/wrapper for the apps that set env configuration from given redis machine.}
12
+ spec.summary = %q{Redis backend env setup proxy.}
13
+ spec.homepage = "https://github.com/kkvlk/envred"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rspec", "~> 2.5"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_dependency "redis", "~> 3.0"
25
+ end
@@ -0,0 +1,29 @@
1
+ require "envred/version"
2
+ require "redis"
3
+
4
+ module Envred
5
+ class Wrapper
6
+ def initialize(central)
7
+ @server, @app = central.split("/~")
8
+ @redis = Redis.new(url: "redis://#{@server}")
9
+
10
+ load and yield if block_given?
11
+ end
12
+
13
+ def load
14
+ vars = @redis.hgetall(@app) and vars.each do |key, val|
15
+ if ENV[key] === nil
16
+ ENV[key] ||= val
17
+ elsif val == ""
18
+ ENV.delete(key)
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ def self.wrap(central, command)
25
+ Wrapper.new(central) do
26
+ system command
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Envred
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,81 @@
1
+ require File.expand_path("../spec_helper.rb", __FILE__)
2
+
3
+ describe Envred 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
+ describe Envred::Wrapper do
17
+ let(:setenv) do
18
+ { foo: 1, bar: 2 }
19
+ end
20
+
21
+ before do
22
+ ENV.delete('foo')
23
+ ENV.delete('bar')
24
+
25
+ redis.mapped_hmset("test", setenv)
26
+ end
27
+
28
+ it "should load proper configuration and set env" do
29
+ env = nil
30
+
31
+ Envred::Wrapper.new(central) do
32
+ env = ENV
33
+ end
34
+
35
+ env['foo'].should == '1'
36
+ env['bar'].should == '2'
37
+ end
38
+
39
+ it "should property pass env to commands" do
40
+ res = nil
41
+
42
+ Envred::Wrapper.new(central) do
43
+ res = `echo $foo $bar`.strip
44
+ end
45
+
46
+ res.should == "1 2"
47
+ end
48
+
49
+ context do
50
+ let(:setenv) do
51
+ { foo: 1, bar: 2, baz: "" }
52
+ end
53
+
54
+ before do
55
+ ENV['foo'] = '10'
56
+ ENV['baz'] = '20'
57
+ end
58
+
59
+ it "should not change existing keys" do
60
+ res = nil
61
+
62
+ Envred::Wrapper.new(central) do
63
+ res = `echo $foo $bar`.strip
64
+ end
65
+
66
+ res.should == "10 2"
67
+ end
68
+
69
+ it "should remove key if value is empty" do
70
+ res = nil
71
+
72
+ Envred::Wrapper.new(central) do
73
+ res = `echo $foo $bar $baz`.strip
74
+ end
75
+
76
+ res.should == "10 2"
77
+
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'envred'
3
+
4
+ ENV['REDIS_URL'] ||= 'redis://localhost:6379/'
5
+
6
+ RSpec.configure do |rspec|
7
+ end
@@ -0,0 +1,25 @@
1
+ box: wercker/rvm
2
+ services:
3
+ - wercker/redis@0
4
+ build:
5
+ steps:
6
+ - rvm-use:
7
+ version: 2.1.0
8
+ - bundle-install
9
+ - script:
10
+ name: rspec
11
+ code: |
12
+ bundle exec rspec
13
+ deploy:
14
+ steps:
15
+ - rvm-use:
16
+ version: 2.1.0
17
+ - bundle-install
18
+ - script:
19
+ name: rubygems-release
20
+ code: |
21
+ echo ":rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials
22
+ chmod 0600 ~/.gem/credentials
23
+ rm -rf pkg
24
+ bundle exec rake build
25
+ ls -1 pkg/*.gem | xargs gem push
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: envred
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kris Kovalik
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redis
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: This is a tool/wrapper for the apps that set env configuration from given
70
+ redis machine.
71
+ email:
72
+ - hi@kkvlk.me
73
+ executables:
74
+ - envred
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/envred
84
+ - envred.gemspec
85
+ - lib/envred.rb
86
+ - lib/envred/version.rb
87
+ - spec/envred_spec.rb
88
+ - spec/spec_helper.rb
89
+ - wercker.yml
90
+ homepage: https://github.com/kkvlk/envred
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Redis backend env setup proxy.
114
+ test_files:
115
+ - spec/envred_spec.rb
116
+ - spec/spec_helper.rb