foreman_hooks 0.3.14 → 0.3.15

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: 2f2bdeb9f5b1cfff753640427f732d376599f824
4
- data.tar.gz: d181ec7e648ff2c7631c2d39c69628bcd2f4e362
3
+ metadata.gz: 87442c737ac9a7e0a5dfa830a53ebbce69121da6
4
+ data.tar.gz: 9b455bf7f174ade8aa225cc961068f0e4fde84a8
5
5
  SHA512:
6
- metadata.gz: a10e596c30229296c2b8e90f5c6023f227cec98763b45ca956247131027722c26eaa3716636853322d41ae96e91732c9afae5f0fafe0a353cccc8ccb32ece938
7
- data.tar.gz: 1a9c5966288d7d7f2e02277bf31e6d32cecc00cb128a697adb1c1eb09ce54e9ecb1e323eaf9abf71cacee9faa336bd338781f16a9d7198aa849dee759526b9b6
6
+ metadata.gz: 27d082d0c28f8406a081b5b6be1be72aad4b5f74d7790735c2a12d2a32984da91a438f6face9676cd472a720eef639755f35fe7fd7c13a1a955c0da96f18f851
7
+ data.tar.gz: 7f861b52fb1dc7ae207fc4d3218afee8c6d01c5e423d9a2ad36a1ea1a93dde521963faace55cb494adbc52b4138ef7c5d305becb7ad38216ddd35a9337340098
data/README.md CHANGED
@@ -131,6 +131,12 @@ may want to ensure stdin is closed to prevent pipe buffer from filling.
131
131
  | ~foreman/config/hooks/host/managed/create/50_register_system.sh \
132
132
  create foo.example.com
133
133
 
134
+ Some arguments are available as environment variables:
135
+
136
+ Variable | Description
137
+ -------- | -----------
138
+ FOREMAN_HOOKS_USER | Username of Foreman user
139
+
134
140
  Every hook within the event directory is executed in alphabetical order. For
135
141
  orchestration hooks, an integer prefix in the hook filename will be used as
136
142
  the priority value, so influences where it's done in relation to DNS, DHCP, VM
@@ -10,7 +10,11 @@ module ForemanHooks::CallbackHooks
10
10
  next unless name
11
11
 
12
12
  Rails.logger.debug("Created hook method #{event} on #{self}")
13
- set_callback name.to_sym, filter.to_sym, "#{event}_hooks".to_sym
13
+ if "#{event}" == "before_destroy"
14
+ set_callback name.to_sym, filter.to_sym, "#{event}_hooks".to_sym, prepend: true
15
+ else
16
+ set_callback name.to_sym, filter.to_sym, "#{event}_hooks".to_sym
17
+ end
14
18
  define_method("#{event}_hooks") do
15
19
  Rails.logger.debug "Observed #{event} hook on #{self}"
16
20
  return unless hooks = ForemanHooks.find_hooks(self.class, event)
@@ -16,11 +16,15 @@ module ForemanHooks::Util
16
16
  end
17
17
  end
18
18
 
19
+ def rabl_path
20
+ "api/v2/#{render_hook_type.tableize}/show"
21
+ end
22
+
19
23
  def render_hook_json
20
24
  # APIv2 has some pretty good templates. We could extend them later in special cases.
21
25
  # Wrap them in a root node for pre-1.4 compatibility
22
26
  view_path = ActionController::Base.view_paths.collect(&:to_path)
23
- json = Rabl.render(self, "api/v2/#{render_hook_type.tableize}/show",
27
+ json = Rabl.render(self, rabl_path,
24
28
  view_path: view_path, format: :json, scope: RablScope.new)
25
29
  %Q|{"#{render_hook_type}":#{json}}|
26
30
  rescue => e
@@ -47,6 +51,10 @@ module ForemanHooks::Util
47
51
  end
48
52
 
49
53
  def exec_hook_int(stdin_data, *args)
54
+ # Set environment vars available in hook scripts
55
+ # Name of active Foreman user:
56
+ ENV['FOREMAN_HOOKS_USER'] = User.current.login
57
+
50
58
  args.map!(&:to_s)
51
59
  output, status = if Open3.respond_to? :capture2e
52
60
  Open3.capture2e(*args.push(:stdin_data => stdin_data))
data/lib/tasks/hooks.rake CHANGED
@@ -2,7 +2,14 @@ namespace :hooks do
2
2
  desc 'Print a list of object names that can be hooked'
3
3
  task :objects => :environment do
4
4
  Rails.application.config.eager_load_namespaces.each(&:eager_load!)
5
- puts ActiveRecord::Base.descendants.collect(&:name).collect(&:underscore).sort
5
+
6
+ # Gather the models
7
+ models = ActiveRecord::Base.descendants.collect(&:name).collect(&:underscore)
8
+
9
+ # filter out known models not hookable
10
+ models.reject! {|e| e.start_with?('habtm')}
11
+
12
+ puts models.sort
6
13
  end
7
14
 
8
15
  desc 'Print a list of event names for a given object, e.g. hooks:events[host/managed]'
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.14
4
+ version: 0.3.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominic Cleal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-17 00:00:00.000000000 Z
11
+ date: 2018-06-18 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
@@ -38,7 +38,7 @@ files:
38
38
  - lib/tasks/hooks.rake
39
39
  - test/test_helper.rb
40
40
  - test/unit/host_observer_test.rb
41
- homepage: http://github.com/theforeman/foreman_hooks
41
+ homepage: https://github.com/theforeman/foreman_hooks
42
42
  licenses:
43
43
  - GPL-3.0
44
44
  metadata: {}
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  requirements: []
60
60
  rubyforge_project:
61
- rubygems_version: 2.6.10
61
+ rubygems_version: 2.6.14.1
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Run custom hook scripts on Foreman events