jackal 0.3.2 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aad960864456381c1973a63d0410dea7200be1fc
4
- data.tar.gz: 43787842bebae529547b90613402f0f84f77eab0
3
+ metadata.gz: 765568d3e3823dc7b7ebbc36532af60b3fa16cbb
4
+ data.tar.gz: 8029a241f1207de9f34d0ff8dad9412c02a8d3e6
5
5
  SHA512:
6
- metadata.gz: 3edc50f45995b3154e0c6726b85c44a41403ef3b4f7a020321a802a29a076c9ef5a7fee9af6596f15d2272fa92273d4057a9ab917ac3228720f03f270733b217
7
- data.tar.gz: 46d2b9a99c0fac02cbd7bff500b840a778389b3484d867df4ee1d5fe3db9624a22f78c4a4baeeb422f446a3a7cbb261e982def6c3191252bc148b35fed109751
6
+ metadata.gz: 05cc094b95877e7b0f11438f11d55a2a3e4a05c45a99d67002a4006533defe935d1cb533303f10c26b539c766449e98d0ec7c2b484cc022e5cd6c5826f97a823
7
+ data.tar.gz: 5d54e7aa1462f7685dd574212bd727b22e417b8075178951f7d86cb184cd4c4f1e339daf36c3b0ab2fa8dcc0c783b704f47dbe9b21ddb441195e918b5ec32b78
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # v0.3.4
2
+ * Scrub environment prior to shelling out
3
+ * Add service registration helper
4
+ * Extract payload directly if provided via source
5
+
1
6
  # v0.3.2
2
7
  * Add support for `pre` and `post` formatters
3
8
 
data/jackal.gemspec CHANGED
@@ -10,9 +10,10 @@ Gem::Specification.new do |s|
10
10
  s.description = 'Message processing helper'
11
11
  s.require_path = 'lib'
12
12
  s.license = 'Apache 2.0'
13
- s.add_dependency 'carnivore', '>= 0.3.0', '< 1.0.0'
13
+ s.add_dependency 'carnivore', '>= 0.3.12', '< 1.0.0'
14
+ s.add_dependency 'bogo', '>= 0.1.24', '< 1.0.0'
14
15
  s.add_dependency 'bogo-cli', '~> 0.1'
15
- s.add_dependency 'bogo-config', '>= 0.1.6', '< 1.0.0'
16
+ s.add_dependency 'bogo-config', '>= 0.1.20', '< 1.0.0'
16
17
  s.add_dependency 'childprocess'
17
18
  s.files = Dir['{lib,bin}/**/**/*'] + %w(jackal.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
18
19
  s.executables << 'jackal'
data/lib/jackal.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'carnivore'
2
+ require 'bogo-config'
2
3
 
3
4
  module Jackal
4
5
  autoload :Cli, 'jackal/cli'
@@ -7,6 +8,57 @@ module Jackal
7
8
  autoload :Formatter, 'jackal/formatter'
8
9
  autoload :Utils, 'jackal/utils'
9
10
  autoload :Loader, 'jackal/loader'
11
+
12
+ class ServiceInformation < Bogo::Config
13
+ class Configuration < Bogo::Config
14
+ attribute :name, Symbol, :required => true, :coerce => lambda{|v| v.to_sym}
15
+ attribute :type, Symbol, :required => true, :default => :string, :allowed_values => [:string, :hash, :number, :boolean]
16
+ attribute :description, String
17
+ attribute :public, [TrueClass, FalseClass], :default => true, :required => true
18
+ end
19
+
20
+ attribute :name, Symbol, :required => true, :coerce => lambda{|v| v.to_sym}
21
+ attribute :description, String
22
+ attribute :configuration, Configuration, :multiple => true, :default => [], :coerce => lambda{|v|
23
+ Smash.new(
24
+ :bogo_multiple => v.map{|name, hsh|
25
+ Configuration.new(hsh.merge(:name => name))
26
+ }
27
+ )
28
+ }
29
+ end
30
+
31
+ # Add service information
32
+ #
33
+ # @param name [String, Symbol] name of service
34
+ # @param args [Hash] service information
35
+ # @option args [String] :description
36
+ # @option args [Hash] :configuration
37
+ # @return [NilClass]
38
+ def self.service(name, args={})
39
+ name = name.to_s
40
+ if(@services[name])
41
+ new_config = ServiceInformation.new(args.merge(:name => name))
42
+ @services[name] = ServiceInformation.new(
43
+ @services[name].data.merge(
44
+ :configuration => (
45
+ @services[name].data[:configuration] |
46
+ new_config.data[:configuration]
47
+ )
48
+ )
49
+ )
50
+ else
51
+ @services[name] = ServiceInformation.new(args.merge(:name => name))
52
+ end
53
+ nil
54
+ end
55
+
56
+ # @return [Smash] registered service info
57
+ def self.service_info
58
+ @services.to_smash
59
+ end
60
+
61
+ @services = Smash.new
10
62
  end
11
63
 
12
64
  require 'jackal/version'
@@ -25,8 +25,12 @@ module Jackal
25
25
  # @param message [Carnivore::Message]
26
26
  # @return [Smash]
27
27
  def unpack(message)
28
- msg = message[:message].to_smash
29
- result = msg.fetch(:payload, msg)
28
+ if(message[:content])
29
+ result = message[:content].to_smash
30
+ else
31
+ msg = message[:message].to_smash
32
+ result = msg.fetch(:payload, msg)
33
+ end
30
34
  if(respond_to?(:pre_formatters) && (pre_formatters && !pre_formatters.empty?))
31
35
  pre_formatters.each do |formatter|
32
36
  begin
@@ -11,6 +11,9 @@ module Jackal
11
11
  # Default path for IO tmp files
12
12
  DEFAULT_STORAGE_DIRECTORY = '/tmp/jackal-process-manager'
13
13
 
14
+ # Environment variables that should be removed from process environment
15
+ BLACKLISTED_ENV = ['GIT_DIR']
16
+
14
17
  # @return [Smash] manager configuration
15
18
  attr_reader :configuration
16
19
  # @return [String] storage directory path
@@ -21,6 +24,7 @@ module Jackal
21
24
  # @param config [Smash] process manager configuration
22
25
  # @return [self]
23
26
  def initialize(config={})
27
+ @base_env = ENV.to_hash
24
28
  @configuration = config.to_smash
25
29
  @storage_directory = configuration.fetch(
26
30
  :storage_directory, DEFAULT_STORAGE_DIRECTORY
@@ -33,21 +37,26 @@ module Jackal
33
37
  # @param identifier [String] command identifier (compat argument)
34
38
  # @param command [String] command in single string or splatted array
35
39
  # @yieldparam [ChildProcess]
36
- # @return [TrueClass]
40
+ # @return [ChildProcess] allows for result inspection if desired
37
41
  def process(identifier, *command)
42
+ _proc = nil
38
43
  if(command.size == 1)
39
44
  command = Shellwords.shellsplit(command.first)
40
45
  end
41
46
  if(block_given?)
42
47
  if(configuration[:spawn])
43
- yield ChildProcess::Unix::PosixSpawnProcess.new(command)
48
+ _proc = clean_env!{ ChildProcess::Unix::PosixSpawnProcess.new(command) }
49
+ scrub_env(_proc.environment)
50
+ clean_env!{ yield _proc }
44
51
  else
45
- yield ChildProcess.build(*command)
52
+ _proc = clean_env!{ ChildProcess.build(*command) }
53
+ scrub_env(_proc.environment)
54
+ clean_env!{ yield _proc }
46
55
  end
47
56
  else
48
57
  raise ArgumentError.new('Expecting block but no block provided!')
49
58
  end
50
- true
59
+ _proc
51
60
  end
52
61
 
53
62
  # Temporary IO for logging
@@ -62,6 +71,37 @@ module Jackal
62
71
  t_file
63
72
  end
64
73
 
74
+ private
75
+
76
+ # Remove environment variables that are known should _NOT_ be set
77
+ #
78
+ # @yield execute block within scrubbed environment
79
+ def clean_env!
80
+ ENV.replace(@base_env.dup)
81
+ scrub_env(ENV)
82
+ if(defined?(Bundler))
83
+ Bundler.with_clean_env{ yield }
84
+ else
85
+ yield
86
+ end
87
+ end
88
+
89
+ # Scrubs configured keys from hash
90
+ #
91
+ # @param env [Hash] hash to scrub
92
+ # @return [TrueClass]
93
+ def scrub_env(env)
94
+ [
95
+ BLACKLISTED_ENV,
96
+ Carnivore::Config.get(
97
+ :jackal, :utils, :process_manager, :blacklisted_env
98
+ )
99
+ ].flatten.compact.each do |key|
100
+ env.delete(key)
101
+ end
102
+ true
103
+ end
104
+
65
105
  end
66
106
  end
67
107
  end
@@ -1,4 +1,4 @@
1
1
  module Jackal
2
2
  # Current library version
3
- VERSION = Gem::Version.new('0.3.2')
3
+ VERSION = Gem::Version.new('0.3.4')
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jackal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-04 00:00:00.000000000 Z
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carnivore
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.0
19
+ version: 0.3.12
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: 1.0.0
@@ -26,7 +26,27 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.3.0
29
+ version: 0.3.12
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bogo
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.1.24
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: 1.0.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.1.24
30
50
  - - "<"
31
51
  - !ruby/object:Gem::Version
32
52
  version: 1.0.0
@@ -50,7 +70,7 @@ dependencies:
50
70
  requirements:
51
71
  - - ">="
52
72
  - !ruby/object:Gem::Version
53
- version: 0.1.6
73
+ version: 0.1.20
54
74
  - - "<"
55
75
  - !ruby/object:Gem::Version
56
76
  version: 1.0.0
@@ -60,7 +80,7 @@ dependencies:
60
80
  requirements:
61
81
  - - ">="
62
82
  - !ruby/object:Gem::Version
63
- version: 0.1.6
83
+ version: 0.1.20
64
84
  - - "<"
65
85
  - !ruby/object:Gem::Version
66
86
  version: 1.0.0
@@ -136,4 +156,3 @@ signing_key:
136
156
  specification_version: 4
137
157
  summary: Message processing helper
138
158
  test_files: []
139
- has_rdoc: