This feature is currently not exposed through the UI. We expect to add AJAX logic to allow the user to view file diffs.
Paired-with: Nick Lewis <[email protected]> Signed-off-by: Paul Berry <[email protected]> --- Local-branch: ticket/next/5171-config-filebucket app/controllers/files_controller.rb | 18 +++++++++++++ config/settings.yml.example | 12 ++++++++- spec/controllers/files_controller_spec.rb | 40 +++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletions(-) create mode 100644 app/controllers/files_controller.rb create mode 100644 spec/controllers/files_controller_spec.rb diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb new file mode 100644 index 0000000..10f4b14 --- /dev/null +++ b/app/controllers/files_controller.rb @@ -0,0 +1,18 @@ +class FilesController < ApplicationController + def diff + unless SETTINGS.use_file_bucket_diffs + render :text => "File bucket diffs have been disabled", :content_type => 'text/plain', :status => 403 + return + end + + [params[:file1], params[:file2]].each do |md5| + unless md5 =~ /^[0-9a-f]{32}$/ + render :text => "Invalid md5: #{md5.inspect}", :content_type => 'text/plain', :status => 400 + return + end + end + url = "https://#{SETTINGS.file_bucket_server}:#{SETTINGS.file_bucket_port}/production/file_bucket_file/md5/#{params[:file1]}?diff_with=#{params[:file2]}" + diff = PuppetHttps.get(url, 's') + render :text => diff, :content_type => 'text/plain' + end +end diff --git a/config/settings.yml.example b/config/settings.yml.example index 7e5f043..3cbf64f 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -8,7 +8,7 @@ # #---[ Values ]---------------------------------------------------------- -# Node name to use when contacting the inventory service. This is the +# Node name to use when contacting the puppet master. This is the # CN that is used in Dashboard's certificate. cn_name: 'dashboard' @@ -37,6 +37,16 @@ inventory_server: 'puppet' # Port for the inventory server. inventory_port: 8140 +# Set this to true to allow Dashboard to display diffs on files that +# are archived in the file bucket. +use_file_bucket_diffs: false + +# Hostname of the file bucket server. +file_bucket_server: 'puppet' + +# Port for the file bucket server. +file_bucket_port: 8140 + # Amount of time in seconds since last report before a node is considered no longer reporting no_longer_reporting_cutoff: 3600 diff --git a/spec/controllers/files_controller_spec.rb b/spec/controllers/files_controller_spec.rb new file mode 100644 index 0000000..af62a9e --- /dev/null +++ b/spec/controllers/files_controller_spec.rb @@ -0,0 +1,40 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe FilesController do + describe "#diff" do + before :each do + SETTINGS.stubs(:use_file_bucket_diffs).returns(true) + SETTINGS.stubs(:file_bucket_server).returns('filebucket') + SETTINGS.stubs(:file_bucket_port).returns(1337) + @options = {:file1 => '24d27c169c2c881eb09a065116f2aa5c', :file2 => '40bb25658a72f731a6f71ef9476cd5af'} + end + + it "Forwards the request to the file bucket server" do + PuppetHttps.expects(:get).with("https://filebucket:1337/production/file_bucket_file/md5/24d27c169c2c881eb09a065116f2aa5c?diff_with=40bb25658a72f731a6f71ef9476cd5af", 's').returns("This is the diff") + + get :diff, @options + + response.should be_success + response.body.should == "This is the diff" + end + + it "Doesn't attempt to do a diff if use_file_bucket_diffs is turned off" do + SETTINGS.stubs(:use_file_bucket_diffs).returns(false) + PuppetHttps.expects(:get).never + + get :diff, @options + + response.should_not be_success + end + + [:file1, :file2].each do |which_parameter| + it "Rejects an invalid md5 for #{which_parameter}" do + @options[which_parameter] = 'Turkmenistan' + + get :diff, @options + + response.should_not be_success + end + end + end +end -- 1.7.2 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
