envme 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.
- checksums.yaml +7 -0
- data/README.md +1 -0
- data/lib/envme/configuration.rb +11 -0
- data/lib/envme/version.rb +3 -0
- data/lib/envme.rb +72 -0
- data/spec/configuration_spec.rb +47 -0
- data/spec/envme_spec.rb +83 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a3052fe63f3a3b65b898a3fc23089e9671db5373
|
4
|
+
data.tar.gz: bc6b327fa19d441d6697d44cc8c3b2e12cff2cf6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52a53b0b576ff88edb8ba5637eab68c9b94038d2719ff8b1596c37f4bc473d229c089c9391cd68d4cd6eb24e6a7ff98088d8a84f8b5b0093a7fa9c800235bdb0
|
7
|
+
data.tar.gz: 1c808565647356435befe744e45b9d1c4e33b79f1954c340dfeac3eba1888d6f854d50ddf365ab7be3f4dfa3f19f0196b4091c6dc36b51fdf3891363b1fdbc32
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Envme
|
data/lib/envme.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Envme
|
2
|
+
class << self
|
3
|
+
attr_accessor :configuration
|
4
|
+
attr_accessor :lib_path
|
5
|
+
|
6
|
+
def require_libs(*libs)
|
7
|
+
libs.each do |lib|
|
8
|
+
require "#{lib_path}/#{lib}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
self.lib_path = File.expand_path "../envme", __FILE__
|
15
|
+
require_libs "configuration"
|
16
|
+
self.configuration ||= Envme::Configuration.new
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def configure
|
20
|
+
self.configuration ||= Envme::Configuration.new
|
21
|
+
yield(configuration)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_vars(prefix, *search_strings)
|
25
|
+
env_vars = get_env_vars(prefix)
|
26
|
+
|
27
|
+
limit_to_search(env_vars, search_strings)
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_env_vars(prefix)
|
31
|
+
run_cmd(prefix).split("\n")
|
32
|
+
end
|
33
|
+
|
34
|
+
def limit_to_search(vars, search_strings)
|
35
|
+
vars.select do |var|
|
36
|
+
search_strings.any? do |match|
|
37
|
+
var.split("=")[0].include?(match.upcase)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def sanitize_vars(vars, search)
|
43
|
+
search = search.upcase
|
44
|
+
|
45
|
+
vars.collect do |var|
|
46
|
+
if var.split("=")[0].match(/^#{search}_/)
|
47
|
+
var.gsub("#{search}_",'')
|
48
|
+
else
|
49
|
+
var
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_exports(var_collection)
|
55
|
+
var_collection.collect{ |var| "export #{var}"}.join("\n")
|
56
|
+
end
|
57
|
+
|
58
|
+
def file_builder(var_collection, filename)
|
59
|
+
var_collection.collect{ |var| "echo #{var} >> #{filename}"}.join("\n")
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def run_cmd(prefix)
|
64
|
+
token = 'anonymous' || self.configuration.acl_token
|
65
|
+
|
66
|
+
`envconsul -once \
|
67
|
+
-consul #{self.configuration.url} \
|
68
|
+
-prefix #{prefix} -upcase \
|
69
|
+
-token #{token} -sanitize env`
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require './lib/envme/configuration.rb'
|
2
|
+
|
3
|
+
describe "Envme" do
|
4
|
+
describe "configuration" do
|
5
|
+
before(:each) do
|
6
|
+
expect(Envme.configuration).to_not be_nil
|
7
|
+
expect(Envme.configuration).to be_a Envme::Configuration
|
8
|
+
Envme.configuration = Envme::Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has configuration block" do
|
12
|
+
expect { |b| Envme.configure(&b) }.to yield_control
|
13
|
+
end
|
14
|
+
|
15
|
+
context "Default" do
|
16
|
+
let(:config) { Envme.configuration }
|
17
|
+
|
18
|
+
it "Returns a Diplmant::Configuration" do
|
19
|
+
expect(config).to be_a Envme::Configuration
|
20
|
+
end
|
21
|
+
|
22
|
+
it "Returns a default URL" do
|
23
|
+
expect(config.url).to_not be_nil
|
24
|
+
expect(config.url.length).to be > 0
|
25
|
+
end
|
26
|
+
|
27
|
+
it "Returns an empty options hash" do
|
28
|
+
expect(config.options).to be_a(Hash)
|
29
|
+
expect(config.options).to be_empty
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "Custom Configuration" do
|
34
|
+
it "Sets the correct configuration" do
|
35
|
+
Envme.configure do |config|
|
36
|
+
config.url = "google.com"
|
37
|
+
config.acl_token = "f45cbd0b-5022-47ab-8640-4eaa7c1f40f1"
|
38
|
+
config.options = {ssl: { verify: true }}
|
39
|
+
end
|
40
|
+
|
41
|
+
expect(Envme.configuration.url).to eq("google.com")
|
42
|
+
expect(Envme.configuration.acl_token).to eq("f45cbd0b-5022-47ab-8640-4eaa7c1f40f1")
|
43
|
+
expect(Envme.configuration.options).to eq({ssl: { verify: true }})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/envme_spec.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require './lib/envme.rb'
|
2
|
+
|
3
|
+
describe Envme do
|
4
|
+
before(:each) do
|
5
|
+
envconsul_data = [
|
6
|
+
"COMPONENT_PARAM1=first_param",
|
7
|
+
"COMPONENT_PARAM2=second PaRam",
|
8
|
+
"ENVVAR_PARAM3=env var"
|
9
|
+
].join("\n")
|
10
|
+
|
11
|
+
allow(Envme).to receive(:run_cmd) { envconsul_data }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "#get_env_vars" do
|
15
|
+
it "calls run_cmd and returns an array" do
|
16
|
+
prefix = 'test/prefix'
|
17
|
+
expect(Envme).to receive(:run_cmd).with(prefix)
|
18
|
+
|
19
|
+
Envme.get_env_vars(prefix)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns an Array" do
|
23
|
+
prefix = 'test/prefix'
|
24
|
+
|
25
|
+
env_vars = Envme.get_env_vars(prefix)
|
26
|
+
expect(env_vars).to be_kind_of(Array)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "#get_vars" do
|
31
|
+
it "returns only the values matching search params" do
|
32
|
+
prefix = 'test/prefix'
|
33
|
+
|
34
|
+
vars = Envme.get_vars(prefix, 'ENVVAR')
|
35
|
+
expect(vars.size).to eq(1)
|
36
|
+
expect(vars[0]).to eq('ENVVAR_PARAM3=env var')
|
37
|
+
expect(vars).not_to include("COMPONENT_PARAM2=second PaRam")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "can accept multiple search strings" do
|
41
|
+
prefix = 'test/prefix'
|
42
|
+
|
43
|
+
vars = Envme.get_vars(prefix, 'ENVVAR', 'COMPONENT')
|
44
|
+
expect(vars.size).to eq(3)
|
45
|
+
expect(vars[0]).to eq('COMPONENT_PARAM1=first_param')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "#limit_to_search" do
|
50
|
+
it "limits to search" do
|
51
|
+
vars = [ 'VAR_ONE=one',
|
52
|
+
'VAR_TWO=two',
|
53
|
+
'VARTHREE=three' ]
|
54
|
+
results = Envme.limit_to_search(vars, ['VARTHREE'])
|
55
|
+
|
56
|
+
expect(results.size).to eq(1)
|
57
|
+
expect(results).not_to include(vars[0])
|
58
|
+
expect(results).not_to include(vars[1])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "#sanitize_vars" do
|
63
|
+
|
64
|
+
it "santitizes vars" do
|
65
|
+
vars = [ 'VAR_ONE=one',
|
66
|
+
'VAR_TWO=two',
|
67
|
+
'VARTHREE=three' ]
|
68
|
+
results = Envme.sanitize_vars(vars, 'VAR')
|
69
|
+
|
70
|
+
expect(results.size).to eq(3)
|
71
|
+
expect(results[0]).to eq('ONE=one')
|
72
|
+
expect(results[1]).to eq('TWO=two')
|
73
|
+
expect(results[2]).to eq('VARTHREE=three')
|
74
|
+
end
|
75
|
+
|
76
|
+
it "search string can be lowercase" do
|
77
|
+
vars = [ "VAR_ONE=one" ]
|
78
|
+
results = Envme.sanitize_vars(vars, 'var')
|
79
|
+
|
80
|
+
expect(results[0]).to eq('ONE=one')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: envme
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 'Reppard Walker '
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-14 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: gem-release
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.7'
|
69
|
+
description: Envme is a Ruby wrapper for envconsul with a few extras.
|
70
|
+
email:
|
71
|
+
- reppardwalker@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- README.md
|
77
|
+
- lib/envme.rb
|
78
|
+
- lib/envme/configuration.rb
|
79
|
+
- lib/envme/version.rb
|
80
|
+
- spec/configuration_spec.rb
|
81
|
+
- spec/envme_spec.rb
|
82
|
+
homepage: https://github.com/reppard/envme
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.2.2
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Envme is a Ruby wrapper for envconsul with a few extras.
|
106
|
+
test_files: []
|