ironment 0.0.5 → 0.0.6
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 -0
- data/lib/ironment/cl.rb +38 -28
- data/lib/ironment/exec.rb +7 -0
- data/lib/ironment/executor.rb +13 -1
- data/lib/ironment/runcom.rb +4 -2
- data/lib/ironment/version.rb +1 -1
- data/lib/ironment.rb +6 -1
- data/test/cl_test.rb +11 -11
- data/test/executor_test.rb +27 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b98178e9d9b70dce2165e1db18355670ba75cbaf
|
4
|
+
data.tar.gz: a5d25fafd95d58888723bbd1c09f7728d8067c7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 736d4ac789d1e4780cc1ac93c5936f940f6ccec3c1a24b0ce9563eb665984eb2b2ae7cbee89e00023b01485f75292f8cedcd78b6dadbde2536f58936b83039aa
|
7
|
+
data.tar.gz: 05222e19c2b9ea8eba1db40aae476a03758e11e33f2515a3f3934b0e193c75b7483a76930ad5cad9db5c060d05d1a1842b88d51ef62d2553bc305b1ba1eb782b
|
data/README.md
CHANGED
@@ -43,6 +43,11 @@ $ yaourt -S ruby-ironment
|
|
43
43
|
|
44
44
|
## Changelog
|
45
45
|
|
46
|
+
### 0.0.6
|
47
|
+
|
48
|
+
* Correct an issue where an unreadable, untrusted runcom would cause a stacktrace.
|
49
|
+
* Errors now contain the file subject (eg. *ironment: foo: No such file or directory*).
|
50
|
+
|
46
51
|
### 0.0.5
|
47
52
|
|
48
53
|
* `iron exec` now handles EACCES, ENOENT & EISDIR like `iron trust` and `iron untrust` does.
|
data/lib/ironment/cl.rb
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
class Ironment
|
2
2
|
class CL
|
3
|
+
class << self
|
4
|
+
def rescue_common_exceptions(method_name)
|
5
|
+
new_name = "original_#{method_name}"
|
6
|
+
|
7
|
+
alias_method new_name, method_name
|
8
|
+
|
9
|
+
define_method method_name do |*args|
|
10
|
+
begin
|
11
|
+
send new_name, *args
|
12
|
+
rescue Ironment::AccessDenied => e
|
13
|
+
@err.puts "ironment: #{e.message}: Permission denied"
|
14
|
+
rescue Ironment::NoEntity=> e
|
15
|
+
@err.puts "ironment: #{e.message}: No such file or directory"
|
16
|
+
rescue Ironment::IsDirectory=> e
|
17
|
+
@err.puts "ironment: #{e.message}: Is a directory"
|
18
|
+
rescue Ironment::MalformedRuncom=> e
|
19
|
+
@err.puts "ironment: #{e.message}: Malformed runcom"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
3
25
|
def initialize(options = {})
|
4
26
|
@ironment = options[:ironment] || Ironment.new(options)
|
5
27
|
@prompter = options[:prompter] || Prompter.new
|
@@ -7,43 +29,31 @@ class Ironment
|
|
7
29
|
end
|
8
30
|
|
9
31
|
def exec_with_environment(command, *args)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
if @prompter.not_trusted e.runcom
|
21
|
-
exec_with_environment command, *args
|
22
|
-
end
|
23
|
-
rescue Truster::Modified => e
|
24
|
-
if @prompter.modified e.runcom
|
25
|
-
exec_with_environment command, *args
|
32
|
+
begin
|
33
|
+
@ironment.exec_with_environment command, *args
|
34
|
+
rescue Truster::NotTrusted => e
|
35
|
+
if @prompter.not_trusted e.runcom
|
36
|
+
exec_with_environment command, *args
|
37
|
+
end
|
38
|
+
rescue Truster::Modified => e
|
39
|
+
if @prompter.modified e.runcom
|
40
|
+
exec_with_environment command, *args
|
41
|
+
end
|
26
42
|
end
|
27
43
|
end
|
28
44
|
|
45
|
+
rescue_common_exceptions :exec_with_environment
|
46
|
+
|
29
47
|
def trust(file)
|
30
48
|
@ironment.trust file
|
31
|
-
rescue Errno::EACCES
|
32
|
-
@err.puts "ironment: Permission denied"
|
33
|
-
rescue Errno::ENOENT
|
34
|
-
@err.puts "ironment: No such file or directory"
|
35
|
-
rescue Errno::EISDIR
|
36
|
-
@err.puts "ironment: Is a directory"
|
37
49
|
end
|
38
50
|
|
51
|
+
rescue_common_exceptions :trust
|
52
|
+
|
39
53
|
def untrust(file)
|
40
54
|
@ironment.untrust file
|
41
|
-
rescue Errno::EACCES
|
42
|
-
@err.puts "ironment: Permission denied"
|
43
|
-
rescue Errno::ENOENT
|
44
|
-
@err.puts "ironment: No such file or directory"
|
45
|
-
rescue Errno::EISDIR
|
46
|
-
@err.puts "ironment: Is a directory"
|
47
55
|
end
|
56
|
+
|
57
|
+
rescue_common_exceptions :untrust
|
48
58
|
end
|
49
59
|
end
|
data/lib/ironment/executor.rb
CHANGED
@@ -1,7 +1,19 @@
|
|
1
|
+
require "ironment/exec"
|
2
|
+
|
1
3
|
class Ironment
|
2
4
|
class Executor
|
5
|
+
def initialize(options = {})
|
6
|
+
@exec = options[:exec] || Exec.new
|
7
|
+
end
|
8
|
+
|
3
9
|
def exec(command, *args)
|
4
|
-
|
10
|
+
@exec.exec command, *args
|
11
|
+
rescue Errno::EACCES
|
12
|
+
raise AccessDenied, command
|
13
|
+
rescue Errno::ENOENT
|
14
|
+
raise NoEntity, command
|
15
|
+
rescue Errno::EISDIR
|
16
|
+
raise IsDirectory, command
|
5
17
|
end
|
6
18
|
end
|
7
19
|
end
|
data/lib/ironment/runcom.rb
CHANGED
@@ -24,12 +24,14 @@ class Ironment
|
|
24
24
|
@file == other.file
|
25
25
|
end
|
26
26
|
|
27
|
+
private
|
28
|
+
|
27
29
|
def content
|
28
30
|
@content ||= File.read(file)
|
31
|
+
rescue Errno::EACCES
|
32
|
+
raise AccessDenied, file
|
29
33
|
end
|
30
34
|
|
31
|
-
private
|
32
|
-
|
33
35
|
def read_pairs
|
34
36
|
Hash[*content.split(/\n/).reject { |line|
|
35
37
|
/^\s*#/ =~line
|
data/lib/ironment/version.rb
CHANGED
data/lib/ironment.rb
CHANGED
@@ -8,7 +8,12 @@ require "ironment/runcom"
|
|
8
8
|
require "ironment/truster"
|
9
9
|
|
10
10
|
class Ironment
|
11
|
-
class
|
11
|
+
class IronmentError < StandardError; end
|
12
|
+
|
13
|
+
class MalformedRuncom < IronmentError; end
|
14
|
+
class AccessDenied < IronmentError; end
|
15
|
+
class NoEntity < IronmentError; end
|
16
|
+
class IsDirectory < IronmentError; end
|
12
17
|
|
13
18
|
class << self
|
14
19
|
attr_writer :runcom
|
data/test/cl_test.rb
CHANGED
@@ -5,7 +5,7 @@ def test_exception_handling(exception, message, method, *args)
|
|
5
5
|
ironment = Object.new
|
6
6
|
|
7
7
|
ironment.define_singleton_method method do |*|
|
8
|
-
raise exception
|
8
|
+
raise exception, args.first
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "upon receiving #{exception.inspect}" do
|
@@ -42,10 +42,10 @@ describe Ironment::CL do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
test_exception_handling
|
46
|
-
test_exception_handling
|
47
|
-
test_exception_handling
|
48
|
-
test_exception_handling Ironment::MalformedRuncom, "ironment: Malformed runcom", :exec_with_environment, "foo"
|
45
|
+
test_exception_handling Ironment::AccessDenied, "ironment: foo: Permission denied", :exec_with_environment, "foo"
|
46
|
+
test_exception_handling Ironment::NoEntity, "ironment: foo: No such file or directory", :exec_with_environment, "foo"
|
47
|
+
test_exception_handling Ironment::IsDirectory, "ironment: foo: Is a directory", :exec_with_environment, "foo"
|
48
|
+
test_exception_handling Ironment::MalformedRuncom, "ironment: foo: Malformed runcom", :exec_with_environment, "foo"
|
49
49
|
end
|
50
50
|
|
51
51
|
describe "#trust" do
|
@@ -62,9 +62,9 @@ describe Ironment::CL do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
test_exception_handling
|
66
|
-
test_exception_handling
|
67
|
-
test_exception_handling
|
65
|
+
test_exception_handling Ironment::AccessDenied, "ironment: .envrc: Permission denied", :trust, ".envrc"
|
66
|
+
test_exception_handling Ironment::NoEntity, "ironment: .envrc: No such file or directory", :trust, ".envrc"
|
67
|
+
test_exception_handling Ironment::IsDirectory, "ironment: .envrc: Is a directory", :trust, ".envrc"
|
68
68
|
end
|
69
69
|
|
70
70
|
describe "#untrust" do
|
@@ -81,8 +81,8 @@ describe Ironment::CL do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
test_exception_handling
|
85
|
-
test_exception_handling
|
86
|
-
test_exception_handling
|
84
|
+
test_exception_handling Ironment::AccessDenied, "ironment: .envrc: Permission denied", :untrust, ".envrc"
|
85
|
+
test_exception_handling Ironment::NoEntity, "ironment: .envrc: No such file or directory", :untrust, ".envrc"
|
86
|
+
test_exception_handling Ironment::IsDirectory, "ironment: .envrc: Is a directory", :untrust, ".envrc"
|
87
87
|
end
|
88
88
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
def test_exception_mapping(map)
|
4
|
+
from, to = map.flatten
|
5
|
+
|
6
|
+
describe "when exec raises #{from.to_s}" do
|
7
|
+
it "should raise #{to.to_s}" do
|
8
|
+
exec = Object.new.tap do |exec|
|
9
|
+
exec.define_singleton_method :exec do |*|
|
10
|
+
raise from
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
assert_raises to do
|
15
|
+
Ironment::Executor.new(exec: exec).exec "foo"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Ironment::Executor do
|
22
|
+
describe "#exec" do
|
23
|
+
test_exception_mapping Errno::EACCES => Ironment::AccessDenied
|
24
|
+
test_exception_mapping Errno::ENOENT => Ironment::NoEntity
|
25
|
+
test_exception_mapping Errno::EISDIR => Ironment::IsDirectory
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.6
|
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-10-
|
11
|
+
date: 2015-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/ironment/cl.rb
|
124
124
|
- lib/ironment/cl/prompter.rb
|
125
125
|
- lib/ironment/config.rb
|
126
|
+
- lib/ironment/exec.rb
|
126
127
|
- lib/ironment/executor.rb
|
127
128
|
- lib/ironment/finder.rb
|
128
129
|
- lib/ironment/populator.rb
|
@@ -131,6 +132,7 @@ files:
|
|
131
132
|
- lib/ironment/version.rb
|
132
133
|
- test/cl_test.rb
|
133
134
|
- test/config_test.rb
|
135
|
+
- test/executor_test.rb
|
134
136
|
- test/finder_test.rb
|
135
137
|
- test/ironment_test.rb
|
136
138
|
- test/populator_test.rb
|
@@ -162,6 +164,7 @@ signing_key:
|
|
162
164
|
specification_version: 4
|
163
165
|
summary: Environment populator & command wrapper utility.
|
164
166
|
test_files:
|
167
|
+
- test/executor_test.rb
|
165
168
|
- test/truster_test.rb
|
166
169
|
- test/runcom_test.rb
|
167
170
|
- test/cl_test.rb
|