dropkick 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.
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'dropkick/command'
3
+ require 'dropkick/command_result'
@@ -0,0 +1,26 @@
1
+ require 'benchmark'
2
+ require 'open3'
3
+ class Command
4
+ def self.secure_exec(command, arguments = [])
5
+ stdout = nil
6
+ stderr = nil
7
+ exit_code = 100
8
+
9
+ command_array = arguments.unshift(command)
10
+
11
+ duration = Benchmark.realtime do
12
+ begin
13
+ Open3.popen3(*command_array) do |stdin, out, err, wait_thr|
14
+ stdout = out.read
15
+ stderr = err.read
16
+ exit_code = wait_thr.value.exitstatus
17
+ end
18
+ rescue Exception => error
19
+ stdout = '' if stdout.nil?
20
+ stderr = error.message
21
+ end
22
+ end
23
+
24
+ CommandResult.new(stdout, stderr, exit_code, duration)
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ class CommandResult
2
+ attr_accessor :stdout, :stderr, :duration
3
+
4
+ def initialize(stdout, stderr, exit_code, duration)
5
+ @stdout = stdout
6
+ @stderr = stderr
7
+ @exit_code = exit_code
8
+ @duration = duration
9
+ end
10
+
11
+ def output
12
+ @stdout
13
+ end
14
+
15
+ def errors
16
+ @stderr
17
+ end
18
+
19
+ def successful?
20
+ @exit_code == 0
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dropkick
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jesse R. Adams
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Friendly wrappers to Open3#popen3 aiming for secure command execution
15
+ email: jesse@techno-geek.sorg
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/dropkick/command.rb
21
+ - lib/dropkick/command_result.rb
22
+ - lib/dropkick.rb
23
+ homepage: https://github.com/jesseadams/dropkick
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.24
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: Secure command execution
47
+ test_files: []