ironment 0.0.1 → 0.0.2
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/Gemfile.lock +18 -4
- data/README.md +8 -0
- data/Rakefile +1 -1
- data/bin/iron +27 -14
- data/ironment.gemspec +15 -5
- data/lib/ironment.rb +7 -0
- data/lib/ironment/config.rb +64 -0
- data/lib/ironment/finder.rb +2 -2
- data/lib/ironment/populator.rb +5 -6
- data/lib/ironment/runcom.rb +41 -0
- data/lib/ironment/truster.rb +44 -0
- data/lib/ironment/version.rb +1 -1
- data/test/config_test.rb +71 -0
- data/test/finder_test.rb +4 -6
- data/test/ironment_test.rb +11 -6
- data/test/populator_test.rb +5 -34
- data/test/runcom_test.rb +86 -0
- data/test/test_helper.rb +7 -0
- data/test/truster_test.rb +70 -0
- metadata +50 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81b877fd7435f4cc6689bee20a99ab1092aadca7
|
4
|
+
data.tar.gz: ce2dcb7c10a2024bd489095362b97a1540d22046
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93ec5f6c900641ec715ef4d6d87e1f562c5bd8b881a0af12045701a6be1fef65d68c6324fde66451f380db8d9308af5e7b019f70b927a17b07786ab36fb6b529
|
7
|
+
data.tar.gz: 36ef3945d5821e96364e3fd59a41f72f87bd9007172e2786e91591a78db96e55e6d0a4eeab2310216e4602517c313fa3e6ed0ed9a6a5de032e3ac2214be952f7
|
data/Gemfile.lock
CHANGED
@@ -1,20 +1,34 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ironment (0.0.
|
4
|
+
ironment (0.0.2)
|
5
|
+
commander (= 4.3.4)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
8
9
|
specs:
|
10
|
+
codeclimate-test-reporter (0.4.7)
|
11
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
12
|
+
commander (4.3.4)
|
13
|
+
highline (~> 1.7.2)
|
14
|
+
docile (1.1.5)
|
9
15
|
fakefs (0.6.7)
|
16
|
+
highline (1.7.2)
|
17
|
+
json (1.8.2)
|
10
18
|
minitest (5.5.1)
|
11
19
|
rake (10.4.2)
|
20
|
+
simplecov (0.10.0)
|
21
|
+
docile (~> 1.1.0)
|
22
|
+
json (~> 1.8)
|
23
|
+
simplecov-html (~> 0.10.0)
|
24
|
+
simplecov-html (0.10.0)
|
12
25
|
|
13
26
|
PLATFORMS
|
14
27
|
ruby
|
15
28
|
|
16
29
|
DEPENDENCIES
|
17
|
-
|
30
|
+
codeclimate-test-reporter (= 0.4.7)
|
31
|
+
fakefs (= 0.6.7)
|
18
32
|
ironment!
|
19
|
-
minitest
|
20
|
-
rake
|
33
|
+
minitest (= 5.5.1)
|
34
|
+
rake (= 10.4.2)
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@ Ironment
|
|
2
2
|
========
|
3
3
|
|
4
4
|
[](https://travis-ci.org/badeball/ironment)
|
5
|
+
[](https://codeclimate.com/github/badeball/ironment)
|
6
|
+
[](https://codeclimate.com/github/badeball/ironment/coverage)
|
5
7
|
|
6
8
|
Ironment is a simple command line utility for populating the environment of a
|
7
9
|
command by reading particular environment files and then exec-ing. Such
|
@@ -21,6 +23,12 @@ FOO=bar
|
|
21
23
|
|
22
24
|
## Changelog
|
23
25
|
|
26
|
+
### 0.0.2
|
27
|
+
|
28
|
+
* Adding a concept of trust. A file that has never been seen will no longer
|
29
|
+
uncritically be used to populate the environment. Instead, the user will be
|
30
|
+
prompted with its sha1sum and asked if they really want to trust it.
|
31
|
+
|
24
32
|
### 0.0.1
|
25
33
|
|
26
34
|
* Initial version. Contains basic support for wrapping commands and populating
|
data/Rakefile
CHANGED
data/bin/iron
CHANGED
@@ -1,26 +1,39 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "commander/import"
|
4
4
|
require "ironment"
|
5
|
+
require "ironment/version"
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
program :name, "Ironment"
|
8
|
+
program :version, Ironment::VERSION
|
9
|
+
program :description, "Environment populator & command wrapper utility."
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
command :exec do |c|
|
12
|
+
c.syntax = "exec [files..]"
|
13
|
+
c.description = "create a new environment (default)"
|
14
|
+
c.action do |args|
|
15
|
+
Ironment::CL.new.exec_with_environment *args
|
12
16
|
end
|
17
|
+
end
|
13
18
|
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
command :trust do |c|
|
20
|
+
c.syntax = "trust [files..]"
|
21
|
+
c.description = "add a file as trusted"
|
22
|
+
c.action do |args|
|
23
|
+
args.each do |file|
|
24
|
+
Ironment::CL.new.trust file
|
25
|
+
end
|
17
26
|
end
|
18
27
|
end
|
19
28
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
29
|
+
command :untrust do |c|
|
30
|
+
c.syntax = "untrust [files..]"
|
31
|
+
c.description = "remove a file as trusted"
|
32
|
+
c.action do |args|
|
33
|
+
args.each do |file|
|
34
|
+
Ironment::CL.new.untrust file
|
35
|
+
end
|
36
|
+
end
|
24
37
|
end
|
25
38
|
|
26
|
-
|
39
|
+
default_command :exec
|
data/ironment.gemspec
CHANGED
@@ -4,9 +4,9 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.name = "ironment"
|
5
5
|
s.version = Ironment::VERSION
|
6
6
|
s.license = "MIT"
|
7
|
-
s.date = "2015-
|
7
|
+
s.date = "2015-06-04"
|
8
8
|
|
9
|
-
s.summary = "
|
9
|
+
s.summary = "Environment populator & command wrapper utility."
|
10
10
|
s.description = "Ironment populates environment variables with runcoms and executes commands."
|
11
11
|
|
12
12
|
s.authors = ["Jonas Amundsen"]
|
@@ -25,16 +25,26 @@ Gem::Specification.new do |s|
|
|
25
25
|
bin/iron
|
26
26
|
ironment.gemspec
|
27
27
|
lib/ironment.rb
|
28
|
+
lib/ironment/config.rb
|
28
29
|
lib/ironment/executor.rb
|
29
30
|
lib/ironment/finder.rb
|
30
31
|
lib/ironment/populator.rb
|
32
|
+
lib/ironment/runcom.rb
|
33
|
+
lib/ironment/truster.rb
|
31
34
|
lib/ironment/version.rb
|
35
|
+
test/config_test.rb
|
32
36
|
test/finder_test.rb
|
33
37
|
test/ironment_test.rb
|
34
38
|
test/populator_test.rb
|
39
|
+
test/runcom_test.rb
|
40
|
+
test/test_helper.rb
|
41
|
+
test/truster_test.rb
|
35
42
|
]
|
36
43
|
|
37
|
-
s.
|
38
|
-
|
39
|
-
s.add_development_dependency("
|
44
|
+
s.add_dependency("commander", "4.3.4")
|
45
|
+
|
46
|
+
s.add_development_dependency("codeclimate-test-reporter", "0.4.7")
|
47
|
+
s.add_development_dependency("fakefs", "0.6.7")
|
48
|
+
s.add_development_dependency("minitest", "5.5.1")
|
49
|
+
s.add_development_dependency("rake", "10.4.2")
|
40
50
|
end
|
data/lib/ironment.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
require "ironment/cl"
|
2
|
+
require "ironment/config"
|
1
3
|
require "ironment/finder"
|
2
4
|
require "ironment/populator"
|
5
|
+
require "ironment/cl/prompter"
|
3
6
|
require "ironment/executor"
|
7
|
+
require "ironment/runcom"
|
8
|
+
require "ironment/truster"
|
4
9
|
|
5
10
|
class Ironment
|
6
11
|
class << self
|
@@ -16,6 +21,7 @@ class Ironment
|
|
16
21
|
end
|
17
22
|
|
18
23
|
def initialize(options = {})
|
24
|
+
@truster = options[:truster] || Truster.new
|
19
25
|
@finder = options[:finder] || Finder.new
|
20
26
|
@populator = options[:populator] || Populator.new
|
21
27
|
@executor = options[:executor] || Executor.new
|
@@ -28,6 +34,7 @@ class Ironment
|
|
28
34
|
|
29
35
|
def load_environment
|
30
36
|
@finder.find.each do |runcom|
|
37
|
+
@truster.validate runcom
|
31
38
|
@populator.populate_with runcom
|
32
39
|
end
|
33
40
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class Hash
|
2
|
+
def except(*keys)
|
3
|
+
dup.except!(*keys)
|
4
|
+
end
|
5
|
+
|
6
|
+
def except!(*keys)
|
7
|
+
keys.each { |key| delete(key) }
|
8
|
+
self
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Ironment
|
13
|
+
class Config
|
14
|
+
class << self
|
15
|
+
attr_writer :config_path
|
16
|
+
|
17
|
+
def config_path
|
18
|
+
@config_path || default_config_path
|
19
|
+
end
|
20
|
+
|
21
|
+
def default_config_path
|
22
|
+
File.join(Dir.home, ".config", "ironment", "config")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def [](key)
|
27
|
+
read_pairs[key]
|
28
|
+
end
|
29
|
+
|
30
|
+
def []=(key, value)
|
31
|
+
if value.nil?
|
32
|
+
write_pairs read_pairs.except(key)
|
33
|
+
else
|
34
|
+
write_pairs read_pairs.merge(key => value)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def read_pairs
|
41
|
+
if File.exist?(file)
|
42
|
+
Hash[*File.read(file).split(/\n/).map { |line|
|
43
|
+
line.split(/=/)
|
44
|
+
}.flatten]
|
45
|
+
else
|
46
|
+
{}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def write_pairs(pairs)
|
51
|
+
dir = Pathname.new(file).dirname
|
52
|
+
|
53
|
+
unless dir.exist?
|
54
|
+
dir.mkpath
|
55
|
+
end
|
56
|
+
|
57
|
+
File.write(file, pairs.map { |k, v| "#{k}=#{v}" }.join("\n"))
|
58
|
+
end
|
59
|
+
|
60
|
+
def file
|
61
|
+
self.class.config_path
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/ironment/finder.rb
CHANGED
data/lib/ironment/populator.rb
CHANGED
@@ -4,12 +4,11 @@ class Ironment
|
|
4
4
|
@env = options[:env] || ENV
|
5
5
|
end
|
6
6
|
|
7
|
-
def populate_with(
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
7
|
+
def populate_with(runcom)
|
8
|
+
enum = runcom.each_pair
|
9
|
+
|
10
|
+
loop do
|
11
|
+
@env.[]= *enum.next
|
13
12
|
end
|
14
13
|
end
|
15
14
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "digest/sha1"
|
2
|
+
|
3
|
+
class Ironment
|
4
|
+
class Runcom
|
5
|
+
attr_reader :file
|
6
|
+
|
7
|
+
def initialize(file)
|
8
|
+
@file = File.expand_path file
|
9
|
+
end
|
10
|
+
|
11
|
+
def sha1sum
|
12
|
+
Digest::SHA1.hexdigest(content)
|
13
|
+
end
|
14
|
+
|
15
|
+
def each_pair
|
16
|
+
if block_given?
|
17
|
+
read_pairs.each &Proc.new
|
18
|
+
else
|
19
|
+
read_pairs.each
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def ==(other)
|
24
|
+
@file == other.file
|
25
|
+
end
|
26
|
+
|
27
|
+
def content
|
28
|
+
@content ||= File.read(file)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def read_pairs
|
34
|
+
Hash[*content.split(/\n/).reject { |line|
|
35
|
+
/^\s*#/ =~line
|
36
|
+
}.map { |line|
|
37
|
+
line.split(/=/)
|
38
|
+
}.flatten]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "digest/sha1"
|
2
|
+
|
3
|
+
class Ironment
|
4
|
+
class Truster
|
5
|
+
class RuncomError < StandardError
|
6
|
+
attr_reader :runcom
|
7
|
+
|
8
|
+
def initialize(runcom)
|
9
|
+
@runcom = runcom
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class NotTrusted < RuncomError; end
|
14
|
+
class Modified < RuncomError; end
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
@config = options[:config] || Config.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate(runcom)
|
21
|
+
expected_sha1sum = @config[runcom.file]
|
22
|
+
|
23
|
+
if expected_sha1sum.nil?
|
24
|
+
raise NotTrusted, runcom
|
25
|
+
end
|
26
|
+
|
27
|
+
real_sha1sum = runcom.sha1sum
|
28
|
+
|
29
|
+
unless expected_sha1sum == real_sha1sum
|
30
|
+
raise Modified, runcom
|
31
|
+
end
|
32
|
+
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
def trust(runcom)
|
37
|
+
@config[runcom.file] = runcom.sha1sum
|
38
|
+
end
|
39
|
+
|
40
|
+
def untrust(runcom)
|
41
|
+
@config[runcom.file] = nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/ironment/version.rb
CHANGED
data/test/config_test.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe Ironment::Config do
|
4
|
+
before :each do
|
5
|
+
Ironment::Config.config_path = "/config"
|
6
|
+
FakeFS.activate!
|
7
|
+
end
|
8
|
+
|
9
|
+
after :each do
|
10
|
+
FakeFS::FileSystem.clear
|
11
|
+
FakeFS.deactivate!
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#[]" do
|
15
|
+
it "should return the configuration value if it exist" do
|
16
|
+
File.write "/config", "FOO=1"
|
17
|
+
|
18
|
+
assert_equal "1", Ironment::Config.new["FOO"]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return nil if the configuration value doesn't exist" do
|
22
|
+
File.write "/config", "FOO=1"
|
23
|
+
|
24
|
+
assert_nil Ironment::Config.new["BAR"]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return nil if the configuration file doesn't exist" do
|
28
|
+
begin
|
29
|
+
File.delete "/config"
|
30
|
+
rescue Errno::ENOENT
|
31
|
+
# Noop
|
32
|
+
end
|
33
|
+
|
34
|
+
assert_nil Ironment::Config.new["BAR"]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#[]=" do
|
39
|
+
it "should write a configuration value to the file" do
|
40
|
+
File.write "/config", ""
|
41
|
+
|
42
|
+
Ironment::Config.new["FOO"] = 1
|
43
|
+
|
44
|
+
assert_equal "FOO=1", File.read("/config")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should overwrite an existing configuration value" do
|
48
|
+
File.write "/config", "FOO=1"
|
49
|
+
|
50
|
+
Ironment::Config.new["FOO"] = 2
|
51
|
+
|
52
|
+
assert_equal "FOO=2", File.read("/config")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should create the directory if missing" do
|
56
|
+
Ironment::Config.config_path = "/foo/bar/config"
|
57
|
+
|
58
|
+
Ironment::Config.new["FOO"] = 1
|
59
|
+
|
60
|
+
assert_equal true, File.exist?("/foo/bar/config")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should delete the configuration value when set to nil" do
|
64
|
+
File.write "/config", "FOO=1"
|
65
|
+
|
66
|
+
Ironment::Config.new["FOO"] = nil
|
67
|
+
|
68
|
+
assert_equal "", File.read("/config")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/test/finder_test.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
require "
|
2
|
-
require "fakefs/safe"
|
3
|
-
require "ironment"
|
1
|
+
require "test_helper"
|
4
2
|
|
5
3
|
module FakeFS
|
6
4
|
class Pathname
|
@@ -26,7 +24,7 @@ describe Ironment::Finder do
|
|
26
24
|
FileUtils.touch "/foo/bar/.envrc"
|
27
25
|
|
28
26
|
Dir.chdir "/foo/bar" do
|
29
|
-
assert_includes Ironment::Finder.new.find, "/foo/bar/.envrc"
|
27
|
+
assert_includes Ironment::Finder.new.find, Ironment::Runcom.new("/foo/bar/.envrc")
|
30
28
|
end
|
31
29
|
end
|
32
30
|
|
@@ -34,7 +32,7 @@ describe Ironment::Finder do
|
|
34
32
|
FileUtils.touch "/foo/.envrc"
|
35
33
|
|
36
34
|
Dir.chdir "/foo/bar" do
|
37
|
-
assert_includes Ironment::Finder.new.find, "/foo/.envrc"
|
35
|
+
assert_includes Ironment::Finder.new.find, Ironment::Runcom.new("/foo/.envrc")
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
@@ -42,7 +40,7 @@ describe Ironment::Finder do
|
|
42
40
|
FileUtils.touch "/.envrc"
|
43
41
|
|
44
42
|
Dir.chdir "/foo/bar" do
|
45
|
-
assert_includes Ironment::Finder.new.find, "/.envrc"
|
43
|
+
assert_includes Ironment::Finder.new.find, Ironment::Runcom.new("/.envrc")
|
46
44
|
end
|
47
45
|
end
|
48
46
|
end
|
data/test/ironment_test.rb
CHANGED
@@ -1,25 +1,30 @@
|
|
1
|
-
require "
|
2
|
-
require "ironment"
|
1
|
+
require "test_helper"
|
3
2
|
|
4
3
|
describe Ironment do
|
5
4
|
describe "#exec_with_environment" do
|
6
|
-
it "find all runcoms, populate with their data and exec the command" do
|
5
|
+
it "find all runcoms, verify them, populate with their data and exec the command" do
|
6
|
+
runcom = Ironment::Runcom.new("/foo/.ironment")
|
7
|
+
|
7
8
|
finder = Minitest::Mock.new
|
8
|
-
finder.expect :find, [
|
9
|
+
finder.expect :find, [runcom].to_enum
|
10
|
+
|
11
|
+
truster = Minitest::Mock.new
|
12
|
+
truster.expect :validate, true, [runcom]
|
9
13
|
|
10
14
|
populator = Minitest::Mock.new
|
11
|
-
populator.expect :populate_with, true, [
|
15
|
+
populator.expect :populate_with, true, [runcom]
|
12
16
|
|
13
17
|
executor = Minitest::Mock.new
|
14
18
|
executor.expect :exec, true, ["some-command"]
|
15
19
|
|
16
20
|
Ironment.new({
|
21
|
+
truster: truster,
|
17
22
|
finder: finder,
|
18
23
|
populator: populator,
|
19
24
|
executor: executor
|
20
25
|
}).exec_with_environment "some-command"
|
21
26
|
|
22
|
-
[finder, populator, executor].each &:verify
|
27
|
+
[finder, truster, populator, executor].each &:verify
|
23
28
|
end
|
24
29
|
end
|
25
30
|
end
|
data/test/populator_test.rb
CHANGED
@@ -1,22 +1,9 @@
|
|
1
|
-
require "
|
2
|
-
require "fakefs/safe"
|
3
|
-
require "ironment"
|
1
|
+
require "test_helper"
|
4
2
|
|
5
3
|
describe Ironment::Populator do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
after :each do
|
11
|
-
FakeFS::FileSystem.clear
|
12
|
-
FakeFS.deactivate!
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should read a file and populate the environment with its content" do
|
16
|
-
File.write("/foo", <<-DAT.gsub(/^\s+/, ""))
|
17
|
-
BAR=1
|
18
|
-
BAZ=2
|
19
|
-
DAT
|
4
|
+
it "should populate the environment with the runcom's key-value pairs" do
|
5
|
+
runcom = Minitest::Mock.new
|
6
|
+
runcom.expect :each_pair, {"BAR" => "1", "BAZ" => "2"}.each
|
20
7
|
|
21
8
|
env = Minitest::Mock.new
|
22
9
|
env.expect :[]=, "1", ["BAR", "1"]
|
@@ -24,23 +11,7 @@ describe Ironment::Populator do
|
|
24
11
|
|
25
12
|
Ironment::Populator.new(
|
26
13
|
env: env
|
27
|
-
).populate_with
|
28
|
-
|
29
|
-
env.verify
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should ignore comment lines" do
|
33
|
-
File.write("/foo", <<-DAT.gsub(/^\s+/, ""))
|
34
|
-
# This is a comment
|
35
|
-
DAT
|
36
|
-
|
37
|
-
env = Minitest::Mock.new
|
38
|
-
|
39
|
-
# Expect no invokations
|
40
|
-
|
41
|
-
Ironment::Populator.new(
|
42
|
-
env: env
|
43
|
-
).populate_with "/foo"
|
14
|
+
).populate_with runcom
|
44
15
|
|
45
16
|
env.verify
|
46
17
|
end
|
data/test/runcom_test.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe Ironment::Runcom do
|
4
|
+
before :each do
|
5
|
+
FakeFS.activate!
|
6
|
+
end
|
7
|
+
|
8
|
+
after :each do
|
9
|
+
FakeFS::FileSystem.clear
|
10
|
+
FakeFS.deactivate!
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#initialize" do
|
14
|
+
it "should expand the given path" do
|
15
|
+
Dir.mkdir "/foo"
|
16
|
+
|
17
|
+
Dir.chdir "/foo" do
|
18
|
+
expanded_path = Ironment::Runcom.new(".envrc").file
|
19
|
+
|
20
|
+
assert_equal "/foo/.envrc", expanded_path
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#sha1sum" do
|
26
|
+
it "should return the sha1sum of the runcom" do
|
27
|
+
File.write(".envrc", "FOO=1")
|
28
|
+
|
29
|
+
# The sha1sum of "FOO=1"
|
30
|
+
assert_equal "67364d1a7020017cf162d2751680b0f89f51da70", Ironment::Runcom.new(".envrc").sha1sum
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should cache the file content on first read" do
|
34
|
+
File.write(".envrc", "FOO=1")
|
35
|
+
|
36
|
+
runcom = Ironment::Runcom.new(".envrc")
|
37
|
+
|
38
|
+
runcom.sha1sum
|
39
|
+
|
40
|
+
File.delete(".envrc")
|
41
|
+
|
42
|
+
# The sha1sum of "FOO=1"
|
43
|
+
assert_equal "67364d1a7020017cf162d2751680b0f89f51da70", runcom.sha1sum
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#each_pair" do
|
48
|
+
it "should return an enumerator for each key-value pair" do
|
49
|
+
File.write ".envrc", <<-DAT.gsub(/^\s+/, "")
|
50
|
+
BAR=1
|
51
|
+
BAZ=2
|
52
|
+
DAT
|
53
|
+
|
54
|
+
enum = Ironment::Runcom.new(".envrc").each_pair
|
55
|
+
|
56
|
+
assert_equal enum.next, ["BAR", "1"]
|
57
|
+
assert_equal enum.next, ["BAZ", "2"]
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should ignore comment lines" do
|
61
|
+
File.write(".envrc", <<-DAT.gsub(/^\s+/, ""))
|
62
|
+
# This is a comment
|
63
|
+
DAT
|
64
|
+
|
65
|
+
enum = Ironment::Runcom.new(".envrc").each_pair
|
66
|
+
|
67
|
+
assert_equal 0, enum.size
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#==" do
|
72
|
+
it "should return true for two runcoms of same file" do
|
73
|
+
one = Ironment::Runcom.new ".envrc"
|
74
|
+
two = Ironment::Runcom.new ".envrc"
|
75
|
+
|
76
|
+
assert_equal true, one == two
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return false for two runcoms of different file" do
|
80
|
+
one = Ironment::Runcom.new "foo/.envrc"
|
81
|
+
two = Ironment::Runcom.new "bar/.envrc"
|
82
|
+
|
83
|
+
assert_equal false, one == two
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe Ironment::Truster do
|
4
|
+
describe "#validate" do
|
5
|
+
it "should raise NotTrusted if the file is untrusted" do
|
6
|
+
config = Minitest::Mock.new
|
7
|
+
config.expect :[], nil, [".envrc"]
|
8
|
+
|
9
|
+
runcom = Minitest::Mock.new
|
10
|
+
runcom.expect :file, ".envrc"
|
11
|
+
|
12
|
+
assert_raises Ironment::Truster::NotTrusted do
|
13
|
+
Ironment::Truster.new(config: config).validate(runcom)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise Modified if the file is trusted, but modified" do
|
18
|
+
config = Minitest::Mock.new
|
19
|
+
config.expect :[], "da39a3ee5e6b4b0d3255bfef95601890afd80709", [".envrc"]
|
20
|
+
|
21
|
+
runcom = Minitest::Mock.new
|
22
|
+
runcom.expect :file, ".envrc"
|
23
|
+
runcom.expect :sha1sum, "94b720c5eafb6205d7e0399a41d2ea78f69c653c"
|
24
|
+
|
25
|
+
assert_raises Ironment::Truster::Modified do
|
26
|
+
Ironment::Truster.new(config: config).validate(runcom)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return true if the file is trusted" do
|
31
|
+
config = Minitest::Mock.new
|
32
|
+
config.expect :[], "67364d1a7020017cf162d2751680b0f89f51da70", [".envrc"]
|
33
|
+
|
34
|
+
runcom = Minitest::Mock.new
|
35
|
+
runcom.expect :file, ".envrc"
|
36
|
+
runcom.expect :sha1sum, "67364d1a7020017cf162d2751680b0f89f51da70"
|
37
|
+
|
38
|
+
assert_equal true, Ironment::Truster.new(config: config).validate(runcom)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#trust" do
|
43
|
+
it "should mark it and its sha1 as trusted" do
|
44
|
+
config = Minitest::Mock.new
|
45
|
+
config.expect :[]=, nil, [".envrc", "67364d1a7020017cf162d2751680b0f89f51da70"]
|
46
|
+
|
47
|
+
runcom = Minitest::Mock.new
|
48
|
+
runcom.expect :file, ".envrc"
|
49
|
+
runcom.expect :sha1sum, "67364d1a7020017cf162d2751680b0f89f51da70"
|
50
|
+
|
51
|
+
Ironment::Truster.new(config: config).trust(runcom)
|
52
|
+
|
53
|
+
config.verify
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#untrust" do
|
58
|
+
it "should remove the trust mark of the file" do
|
59
|
+
config = Minitest::Mock.new
|
60
|
+
config.expect :[]=, nil, [".envrc", nil]
|
61
|
+
|
62
|
+
runcom = Minitest::Mock.new
|
63
|
+
runcom.expect :file, ".envrc"
|
64
|
+
|
65
|
+
Ironment::Truster.new(config: config).untrust(runcom)
|
66
|
+
|
67
|
+
config.verify
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
metadata
CHANGED
@@ -1,57 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ironment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Amundsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: commander
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.3.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.3.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: codeclimate-test-reporter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.4.7
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.4.7
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: fakefs
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
16
44
|
requirements:
|
17
|
-
- -
|
45
|
+
- - '='
|
18
46
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
47
|
+
version: 0.6.7
|
20
48
|
type: :development
|
21
49
|
prerelease: false
|
22
50
|
version_requirements: !ruby/object:Gem::Requirement
|
23
51
|
requirements:
|
24
|
-
- -
|
52
|
+
- - '='
|
25
53
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
54
|
+
version: 0.6.7
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: minitest
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
|
-
- -
|
59
|
+
- - '='
|
32
60
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
61
|
+
version: 5.5.1
|
34
62
|
type: :development
|
35
63
|
prerelease: false
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
37
65
|
requirements:
|
38
|
-
- -
|
66
|
+
- - '='
|
39
67
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
68
|
+
version: 5.5.1
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rake
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
|
-
- -
|
73
|
+
- - '='
|
46
74
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
75
|
+
version: 10.4.2
|
48
76
|
type: :development
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
|
-
- -
|
80
|
+
- - '='
|
53
81
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
82
|
+
version: 10.4.2
|
55
83
|
description: Ironment populates environment variables with runcoms and executes commands.
|
56
84
|
email:
|
57
85
|
- jonasba+gem@gmail.com
|
@@ -69,13 +97,20 @@ files:
|
|
69
97
|
- bin/iron
|
70
98
|
- ironment.gemspec
|
71
99
|
- lib/ironment.rb
|
100
|
+
- lib/ironment/config.rb
|
72
101
|
- lib/ironment/executor.rb
|
73
102
|
- lib/ironment/finder.rb
|
74
103
|
- lib/ironment/populator.rb
|
104
|
+
- lib/ironment/runcom.rb
|
105
|
+
- lib/ironment/truster.rb
|
75
106
|
- lib/ironment/version.rb
|
107
|
+
- test/config_test.rb
|
76
108
|
- test/finder_test.rb
|
77
109
|
- test/ironment_test.rb
|
78
110
|
- test/populator_test.rb
|
111
|
+
- test/runcom_test.rb
|
112
|
+
- test/test_helper.rb
|
113
|
+
- test/truster_test.rb
|
79
114
|
homepage: https://github.com/badeball/ironment
|
80
115
|
licenses:
|
81
116
|
- MIT
|
@@ -99,5 +134,5 @@ rubyforge_project:
|
|
99
134
|
rubygems_version: 2.4.5
|
100
135
|
signing_key:
|
101
136
|
specification_version: 4
|
102
|
-
summary:
|
137
|
+
summary: Environment populator & command wrapper utility.
|
103
138
|
test_files: []
|