foreman_hooks 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/foreman_hooks/util.rb +22 -2
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89ca0cd0fe9eea695a2ba74c390f3a7366191551
4
- data.tar.gz: 9d542ea2ef4121c46249bbc2d1f7c24b4574ad4d
3
+ metadata.gz: 4aa78594bdb6c2cc863097039b920bafe1b21b0e
4
+ data.tar.gz: 25fad3c59ce04be593118ac643f326c1daafe9c9
5
5
  SHA512:
6
- metadata.gz: 5c62797e52f6965700536068d6c782fcc65b835c36f5108d965459aa6195ac6167f3687c9feb7751649df2c055074eb1f47180189bae51dd6a42d2cfa8968568
7
- data.tar.gz: 4650f6a9156b8ef5d8d4628bfa52f2e44fd148155f26fe0bd7b00a01ebd440706e7d5d8a5c7a0968c58efd230b021fe0426b83a7c3b93a9c57b0233a79c07738
6
+ metadata.gz: 1fa4d89f00745e4cc5863988f5c9da6df9ed5a424abc549acfd0d5d6513b4f5a12646bd00cd2b735b20599289503a671130c0f2583c99224f050683e5cb7ed7a
7
+ data.tar.gz: f0ca3b8c45b66224bfa21e5e893d8a381a9cca95cbac135d1403fe420f3894b63c6313706522b70134511169126f1c3e2d83a125657c57d081b7ff0715c03be7
@@ -3,12 +3,32 @@ require 'open3'
3
3
  module ForemanHooks::Util
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ def render_hook_type
7
+ case self
8
+ when Host::Managed
9
+ 'host'
10
+ else
11
+ self.class.name.to_lower
12
+ end
13
+ end
14
+
15
+ def render_hook_json
16
+ # APIv2 has some pretty good templates. We could extend them later in special cases.
17
+ # Wrap them in a root node for pre-1.4 compatibility
18
+ json = Rabl.render(self, "api/v2/#{render_hook_type.tableize}/show", :view_path => 'app/views', :format => :json)
19
+ %Q|{"#{render_hook_type}":#{json}}|
20
+ rescue => e
21
+ logger.warn "Unable to render #{self} (#{self.class}) using RABL: #{e.message}"
22
+ logger.debug e.backtrace.join("\n")
23
+ self.to_json
24
+ end
25
+
6
26
  def exec_hook(*args)
7
27
  logger.debug "Running hook: #{args.join(' ')}"
8
28
  success = if defined? Bundler && Bundler.responds_to(:with_clean_env)
9
- Bundler.with_clean_env { exec_hook_int(self.to_json, *args) }
29
+ Bundler.with_clean_env { exec_hook_int(render_hook_json, *args) }
10
30
  else
11
- exec_hook_int(self.to_json, *args)
31
+ exec_hook_int(render_hook_json, *args)
12
32
  end.success?
13
33
 
14
34
  # Raising here causes Foreman Orchestration to correctly show error bubble in GUI
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_hooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominic Cleal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-21 00:00:00.000000000 Z
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Plugin engine for Foreman that enables running custom hook scripts on
14
14
  Foreman events