Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add necessary stuff before oxidized base patch to hide enable password from REST API #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/oxidized/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class Web
require 'rack/handler'
attr_reader :thread
Rack::Handler::WEBrick = Rack::Handler.get(:puma)
def initialize nodes, listen
# in order to don't crash existing setup,
# we set hide_enable at false by default
def initialize nodes, listen, hide_enable=false
require 'oxidized/web/webapp'
listen, uri = listen.split '/'
addr, port = listen.split ':'
Expand All @@ -17,6 +19,7 @@ def initialize nodes, listen
Port: port,
}
WebApp.set :nodes, nodes
WebApp.set :hide_enable, hide_enable
@app = Rack::Builder.new do
map uri do
run WebApp
Expand Down
25 changes: 22 additions & 3 deletions lib/oxidized/web/webapp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WebApp < Sinatra::Base
node[:status] = node[:last][:status]
node[:time] = node[:last][:end]
end
node
hide_enable? node
end
end
out :nodes
Expand All @@ -40,7 +40,7 @@ class WebApp < Sinatra::Base
node[:status] = node[:last][:status]
node[:time] = node[:last][:end]
end
node
hide_enable? node
end
out :nodes
end
Expand Down Expand Up @@ -112,7 +112,7 @@ class WebApp < Sinatra::Base

get '/node/show/:node' do
node, @json = route_parse :node
@data = nodes.show node
@data = hide_enable?(nodes.show(node))
out :node
end

Expand Down Expand Up @@ -221,6 +221,25 @@ class WebApp < Sinatra::Base

private

def hide_enable? node
if settings.hide_enable
# We need to dup/clone twice not to break in memory node.
if (node.has_key? :vars) and (node[:vars].has_key? :enable)
n = node.clone
node.each_key do |k|
if node[k].is_a?(Symbol)
n[k] = node[k]
else
n[k] = node[k].dup unless node[k].nil?
end
end
n[:vars][:enable] = 'HIDDEN'
return n
end
end
return node
end

def out template = :text
if @json or params[:format] == 'json'
if @data.is_a?(String)
Expand Down