Skip to content

Commit

Permalink
Include parameter lists in host hook JSON
Browse files Browse the repository at this point in the history
Fixes #43
  • Loading branch information
domcleal committed May 17, 2017
1 parent 5541adb commit ed2c50c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/foreman_hooks/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def render_hook_json
# APIv2 has some pretty good templates. We could extend them later in special cases.
# Wrap them in a root node for pre-1.4 compatibility
view_path = ActionController::Base.view_paths.collect(&:to_path)
json = Rabl.render(self, "api/v2/#{render_hook_type.tableize}/show", :view_path => view_path, :format => :json)
json = Rabl.render(self, "api/v2/#{render_hook_type.tableize}/show",
view_path: view_path, format: :json, scope: RablScope.new)
%Q|{"#{render_hook_type}":#{json}}|
rescue => e
logger.warn "Unable to render #{self} (#{self.class}) using RABL: #{e.message}"
Expand Down Expand Up @@ -60,4 +61,17 @@ def exec_hook_int(stdin_data, *args)
logger.debug "Hook output: #{output}" if output && !output.empty?
[status.success?, output]
end

class RablScope
def initialize
# Used by api/v2/hosts/main.json.yaml to include parameter lists
@all_parameters = true
@parameters = true
end

def params
# Used by app/views/api/v2/common/show_hidden.json.rabl to show hidden parameter values (#17653)
{ 'show_hidden' => true, 'show_hidden_parameters' => true }
end
end
end

0 comments on commit ed2c50c

Please sign in to comment.