envme 0.0.3 → 0.1.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 +4 -4
- data/README.md +1 -1
- data/lib/envme.rb +1 -45
- data/lib/envme/command_runner.rb +17 -0
- data/lib/envme/vars.rb +35 -0
- data/lib/envme/version.rb +1 -1
- data/spec/command_runner_spec.rb +12 -0
- data/spec/envme_spec.rb +0 -93
- data/spec/spec_helper.rb +3 -1
- data/spec/vars_spec.rb +69 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a630505124ce7b8e4cca7011eeb0d59898882259
|
4
|
+
data.tar.gz: fc9b025a98d8b254b2906422aef6d9e33551b9a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e69cb05901b43ea8ae81e9f109fde9af3949d328b824c152f84b8d8a4ce09475060e989b29e9b436aa054bb9b75c483db3c1e77e112eab7c7a6b3255c3d5147d
|
7
|
+
data.tar.gz: e89ad457a19b860711e2e20ddd2f926d12baf1e0afadc88c8b1bca5575dca2ab7da8832d67a677f9bd6fad2d3e4768d4fb66431928ab349b49f78fa4657d176e
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
# Envme
|
2
2
|
[](http://badge.fury.io/rb/envme) [](https://circleci.com/gh/reppard/envme)
|
3
3
|
|
4
|
-
|
4
|
+
Inspired by [Diplomat](https://github.com/WeAreFarmGeek/diplomat)
|
data/lib/envme.rb
CHANGED
@@ -12,7 +12,7 @@ module Envme
|
|
12
12
|
end
|
13
13
|
|
14
14
|
self.lib_path = File.expand_path "../envme", __FILE__
|
15
|
-
require_libs "configuration"
|
15
|
+
require_libs "configuration", "command_runner", "vars"
|
16
16
|
self.configuration ||= Envme::Configuration.new
|
17
17
|
|
18
18
|
class << self
|
@@ -21,36 +21,6 @@ module Envme
|
|
21
21
|
yield(configuration)
|
22
22
|
end
|
23
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
24
|
def build_exports(var_collection)
|
55
25
|
var_collection.collect{ |var| "export #{var}"}.join("\n")
|
56
26
|
end
|
@@ -58,19 +28,5 @@ module Envme
|
|
58
28
|
def file_builder(var_collection, filename)
|
59
29
|
var_collection.collect{ |var| "echo #{var} >> #{filename}"}.join("\n")
|
60
30
|
end
|
61
|
-
|
62
|
-
def get_cmd(prefix)
|
63
|
-
[
|
64
|
-
"envconsul -once",
|
65
|
-
"-consul #{self.configuration.url}",
|
66
|
-
"-prefix #{prefix} -upcase",
|
67
|
-
"-token #{self.configuration.acl_token} -sanitize env"
|
68
|
-
].join(' ')
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
def run_cmd(prefix)
|
73
|
-
`#{get_cmd(prefix)}`
|
74
|
-
end
|
75
31
|
end
|
76
32
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Envme
|
2
|
+
class CommandRunner
|
3
|
+
def self.build_cmd(prefix)
|
4
|
+
[
|
5
|
+
"envconsul -once",
|
6
|
+
"-consul #{Envme.configuration.url}",
|
7
|
+
"-prefix #{prefix} -upcase",
|
8
|
+
"-token #{Envme.configuration.acl_token} -sanitize env"
|
9
|
+
].join(' ')
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def self.run(prefix)
|
14
|
+
`#{build_cmd(prefix)}`
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/envme/vars.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Envme
|
2
|
+
class Vars < Envme::CommandRunner
|
3
|
+
|
4
|
+
def self.get_all(prefix)
|
5
|
+
run(prefix).split("\n")
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.get_limited(prefix, *search_strings)
|
9
|
+
env_vars = get_all(prefix)
|
10
|
+
|
11
|
+
limit_to_search(env_vars, search_strings)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.sanitize(vars, search)
|
15
|
+
search = search.upcase
|
16
|
+
|
17
|
+
vars.collect do |var|
|
18
|
+
if var.split("=")[0].match(/^#{search}_/)
|
19
|
+
var.gsub("#{search}_",'')
|
20
|
+
else
|
21
|
+
var
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def self.limit_to_search(vars, search_strings)
|
28
|
+
vars.select do |var|
|
29
|
+
search_strings.any? do |match|
|
30
|
+
var.split("=")[0].include?(match.upcase)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/envme/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Envme::CommandRunner do
|
4
|
+
context "#build_cmd" do
|
5
|
+
it "returns a the expected command" do
|
6
|
+
command = Envme::CommandRunner.build_cmd('test/prefix')
|
7
|
+
expected = "envconsul -once -consul localhost:8500 -prefix test/prefix -upcase -token anonymous -sanitize env"
|
8
|
+
|
9
|
+
expect(command).to eq(expected)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/envme_spec.rb
CHANGED
@@ -1,85 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
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
|
-
it "santitizes vars" do
|
64
|
-
vars = [ 'VAR_ONE=one',
|
65
|
-
'VAR_TWO=two',
|
66
|
-
'VARTHREE=three' ]
|
67
|
-
results = Envme.sanitize_vars(vars, 'VAR')
|
68
|
-
|
69
|
-
expect(results.size).to eq(3)
|
70
|
-
expect(results[0]).to eq('ONE=one')
|
71
|
-
expect(results[1]).to eq('TWO=two')
|
72
|
-
expect(results[2]).to eq('VARTHREE=three')
|
73
|
-
end
|
74
|
-
|
75
|
-
it "search string can be lowercase" do
|
76
|
-
vars = [ "VAR_ONE=one" ]
|
77
|
-
results = Envme.sanitize_vars(vars, 'var')
|
78
|
-
|
79
|
-
expect(results[0]).to eq('ONE=one')
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
4
|
context "#build_exports" do
|
84
5
|
it "should take a collection and build a list of exports" do
|
85
6
|
data = [ 'VAR_ONE=one', 'VAR_TWO=two', 'VARTHREE=three' ]
|
@@ -88,18 +9,4 @@ describe Envme do
|
|
88
9
|
expect(Envme.build_exports(data)).to eq(expected)
|
89
10
|
end
|
90
11
|
end
|
91
|
-
|
92
|
-
context "#get_cmd" do
|
93
|
-
it "returns a the expected command" do
|
94
|
-
command = Envme.get_cmd('test/prefix')
|
95
|
-
expected = "envconsul -once -consul localhost:8500 -prefix test/prefix -upcase -token anonymous -sanitize env"
|
96
|
-
|
97
|
-
expect(command).to eq(expected)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context "#configure" do
|
102
|
-
it "returns a configuration" do
|
103
|
-
end
|
104
|
-
end
|
105
12
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/vars_spec.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Envme::Vars 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::CommandRunner).to receive(:run) { envconsul_data }
|
12
|
+
end
|
13
|
+
|
14
|
+
context "#get_all" do
|
15
|
+
it "calls run and returns an array" do
|
16
|
+
prefix = 'test/prefix'
|
17
|
+
expect(Envme::CommandRunner).to receive(:run).with(prefix)
|
18
|
+
|
19
|
+
Envme::Vars.get_all(prefix)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns an Array" do
|
23
|
+
prefix = 'test/prefix'
|
24
|
+
|
25
|
+
env_vars = Envme::Vars.get_all(prefix)
|
26
|
+
expect(env_vars).to be_kind_of(Array)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "#get_limited" do
|
31
|
+
it "returns only the values matching search params" do
|
32
|
+
prefix = 'test/prefix'
|
33
|
+
|
34
|
+
vars = Envme::Vars.get_limited(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::Vars.get_limited(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 "#sanitize" do
|
50
|
+
it "santitizes vars" do
|
51
|
+
vars = [ 'VAR_ONE=one',
|
52
|
+
'VAR_TWO=two',
|
53
|
+
'VARTHREE=three' ]
|
54
|
+
results = Envme::Vars.sanitize(vars, 'VAR')
|
55
|
+
|
56
|
+
expect(results.size).to eq(3)
|
57
|
+
expect(results[0]).to eq('ONE=one')
|
58
|
+
expect(results[1]).to eq('TWO=two')
|
59
|
+
expect(results[2]).to eq('VARTHREE=three')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "search string can be lowercase" do
|
63
|
+
vars = [ "VAR_ONE=one" ]
|
64
|
+
results = Envme::Vars.sanitize(vars, 'var')
|
65
|
+
|
66
|
+
expect(results[0]).to eq('ONE=one')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 'Reppard Walker '
|
@@ -89,11 +89,15 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- README.md
|
91
91
|
- lib/envme.rb
|
92
|
+
- lib/envme/command_runner.rb
|
92
93
|
- lib/envme/configuration.rb
|
94
|
+
- lib/envme/vars.rb
|
93
95
|
- lib/envme/version.rb
|
96
|
+
- spec/command_runner_spec.rb
|
94
97
|
- spec/configuration_spec.rb
|
95
98
|
- spec/envme_spec.rb
|
96
99
|
- spec/spec_helper.rb
|
100
|
+
- spec/vars_spec.rb
|
97
101
|
homepage: https://github.com/reppard/envme
|
98
102
|
licenses:
|
99
103
|
- MIT
|