Log In
Log In
Places
All Projects
Status Monitor
Collapse sidebar
obs:server:fedora-2.5
obs-server
obs-server-2.5.3-0001-api-Fix-to-work-when-host...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File obs-server-2.5.3-0001-api-Fix-to-work-when-hosted-in-non-root-server-direc.patch of Package obs-server
From 750a4d14e154e94ce9572487b8aa3e84b986c1d7 Mon Sep 17 00:00:00 2001 From: Oleg Girko <ol@infoserver.lv> Date: Mon, 11 Nov 2013 20:00:25 +0000 Subject: [PATCH 1/4] [api] Fix to work when hosted in non-root server directory. This change allows OBS API and WebUI to be installed on a web server in a place other than document root, so its URL prefix has a non-empty pathname (like https://example.com/api instead of https://api.example.com). This is useful for those who can't have OBS api, webui and main site on different domains and buy separate X.509 certificates for them, or just can't afford to have separate IP addresses for them (please note that currently osc doesn't support TLS SNI). Signed-off-by: Oleg Girko <ol@infoserver.lv> --- src/api/app/controllers/application_controller.rb | 1 + src/api/app/controllers/source_controller.rb | 11 +++++++++-- src/api/app/views/layouts/webui/webui.html.erb | 2 +- src/api/config/initializers/activexml.rb | 3 ++- src/api/lib/activexml/transport.rb | 9 +++++---- src/api/test/unit/code_quality_test.rb | 2 +- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/api/app/controllers/application_controller.rb b/src/api/app/controllers/application_controller.rb index 4faa727..867f93f 100644 --- a/src/api/app/controllers/application_controller.rb +++ b/src/api/app/controllers/application_controller.rb @@ -386,6 +386,7 @@ class ApplicationController < ActionController::Base def get_request_path path = request.path query_string = request.query_string + path.slice!( 0, root_path.length-1 ) if path.start_with?( root_path ) if request.form_data? # it's uncommon, but possible that we have both query_string += "&" unless query_string.blank? diff --git a/src/api/app/controllers/source_controller.rb b/src/api/app/controllers/source_controller.rb index 85b0811..29a9066 100644 --- a/src/api/app/controllers/source_controller.rb +++ b/src/api/app/controllers/source_controller.rb @@ -656,7 +656,9 @@ class SourceController < ApplicationController if params.has_key?(:rev) or pack.nil? # and not pro_name # check if this comes from a remote project, also true for _project package # or if rev it specified we need to fetch the meta from the backend - answer = Suse::Backend.get(request.path) + reqpath = request.path + reqpath.slice!(0, root_path.length-1) if reqpath.start_with?(root_path) + answer = Suse::Backend.get(reqpath) if answer render :text => answer.body.to_s, :content_type => 'text/xml' else @@ -1117,6 +1119,7 @@ class SourceController < ApplicationController # read meta data from backend to restore database object path = request.path + '/_meta' + path.slice!(0, root_path.length-1) if path.start_with?(root_path) prj = Project.new(name: params[:project]) Project.transaction do prj.update_from_xml(Xmlhash.parse(backend_get(path))) @@ -1341,6 +1344,7 @@ class SourceController < ApplicationController # read meta data from backend to restore database object path = request.path + '/_meta' + path.slice!(0, root_path.length-1) if path.start_with?(root_path) prj = Project.find_by_name!(params[:project]) pkg = prj.packages.new(name: params[:package]) pkg.update_from_xml(Xmlhash.parse(backend_get(path))) @@ -1351,6 +1355,7 @@ class SourceController < ApplicationController # POST /source/<project>/<package>?cmd=createSpecFileTemplate def package_command_createSpecFileTemplate specfile_path = "#{request.path}/#{params[:package]}.spec" + specfile_path.slice!(0, root_path.length-1) if specfile_path.start_with?(root_path) begin backend_get( specfile_path ) render_error :status => 400, :errorcode => 'spec_file_exists', @@ -1372,7 +1377,9 @@ class SourceController < ApplicationController # check for sources in this or linked project unless @package # check if this is a package on a remote OBS instance - answer = Suse::Backend.get(request.path) + reqpath = request.path + reqpath.slice!(0, root_path.length-1) if reqpath.start_with?(root_path) + answer = Suse::Backend.get(reqpath) unless answer render_error :status => 400, :errorcode => 'unknown_package', :message => "Unknown package '#{package_name}'" diff --git a/src/api/app/views/layouts/webui/webui.html.erb b/src/api/app/views/layouts/webui/webui.html.erb index 42869a4..5764695 100644 --- a/src/api/app/views/layouts/webui/webui.html.erb +++ b/src/api/app/views/layouts/webui/webui.html.erb @@ -6,7 +6,7 @@ <meta name="robots" content="<%= @metarobots %>"/> <% end %> - <link href="<%= CONFIG['relative_url_root'] %>/favicon.ico" rel="shortcut icon" /> + <link href="<%= root_path %>/favicon.ico" rel="shortcut icon" /> <title><%= "#{@pagetitle} - " if @pagetitle -%><%= @configuration ? @configuration['title'] : 'Open Build Service' %></title> diff --git a/src/api/config/initializers/activexml.rb b/src/api/config/initializers/activexml.rb index 3ba5ca7..a5908fb 100644 --- a/src/api/config/initializers/activexml.rb +++ b/src/api/config/initializers/activexml.rb @@ -1,6 +1,7 @@ require_dependency 'activexml/activexml' CONFIG['source_protocol'] ||= 'http' +CONFIG['api_relative_url_root'] ||= '' map = ActiveXML::setup_transport_backend(CONFIG['source_protocol'], CONFIG['source_host'], CONFIG['source_port']) @@ -32,7 +33,7 @@ if defined?(Rack::MiniProfiler) end end -map = ActiveXML::setup_transport_api(CONFIG['frontend_protocol'], CONFIG['frontend_host'], CONFIG['frontend_port']) +map = ActiveXML::setup_transport_api(CONFIG['frontend_protocol'], CONFIG['frontend_host'], CONFIG['frontend_port'], CONFIG['api_relative_url_root']) map.connect :webuiproject, 'rest:///source/:name/_meta?:view', :delete => 'rest:///source/:name?:force', diff --git a/src/api/lib/activexml/transport.rb b/src/api/lib/activexml/transport.rb index 6d9893a..72b0367 100644 --- a/src/api/lib/activexml/transport.rb +++ b/src/api/lib/activexml/transport.rb @@ -3,8 +3,8 @@ module ActiveXML @@transport_api end - def self.setup_transport_api(schema, host, port) - @@transport_api = Transport.new(schema, host, port) + def self.setup_transport_api(schema, host, port, prefix='') + @@transport_api = Transport.new(schema, host, port, prefix) end def self.backend @@ -110,10 +110,11 @@ module ActiveXML @mapping[model][:opt] end - def initialize( schema, host, port ) + def initialize( schema, host, port, prefix='' ) @schema = schema @host = host @port = port + @prefix = prefix @default_servers ||= Hash.new @http_header = {"Content-Type" => "text/plain", 'Accept-Encoding' => 'identity'} # stores mapping information @@ -329,7 +330,7 @@ module ActiveXML @http.read_timeout = opt[:timeout] raise "url.path.nil" if url.path.nil? - path = url.path + path = @prefix + url.path path += "?" + url.query if url.query logger.debug "http_do: method: #{method} url: " + "http#{"s" if @http.use_ssl?}://#{url.host}:#{url.port}#{path}" diff --git a/src/api/test/unit/code_quality_test.rb b/src/api/test/unit/code_quality_test.rb index ab6ba65..7127617 100644 --- a/src/api/test/unit/code_quality_test.rb +++ b/src/api/test/unit/code_quality_test.rb @@ -131,7 +131,7 @@ class CodeQualityTest < ActiveSupport::TestCase 'SourceController#package_command' => 65.31, 'SourceController#project_command_copy' => 140.04, 'SourceController#project_command_set_flag' => 53.57, - 'SourceController#project_command_undelete' => 53.7, + 'SourceController#project_command_undelete' => 62.54, 'SourceController#update_file' => 97.26, 'SourceController#update_project_meta' => 127.52, 'SourceController#verify_repos_match!' => 52.26, -- 1.9.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Contact
Support
@OBShq
The Open Build Service is an
openSUSE project
.
Log In
Places
Places
All Projects
Status Monitor