Log In
Log In
Places
All Projects
Status Monitor
Collapse sidebar
obs:server:fedora:2.6:testing
obs-server
obs-server-2.6.6-0001-api-Fix-to-work-when-host...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File obs-server-2.6.6-0001-api-Fix-to-work-when-hosted-in-non-root-server-direc.patch of Package obs-server
From 04df094182dbd660fba6a8f366c879e247dc486d 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/9] [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/obs instead of https://obs.example.com). This is useful for those who can't have OBS 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 | 2 +- src/api/app/controllers/build_controller.rb | 2 +- src/api/app/controllers/public_controller.rb | 14 ++--- src/api/app/controllers/source_controller.rb | 66 +++++++++++------------ src/api/app/views/layouts/webui/webui.html.erb | 2 +- src/api/config/initializers/activexml.rb | 3 +- src/api/config/options.yml.example | 1 + src/api/lib/activexml/transport.rb | 9 ++-- 8 files changed, 51 insertions(+), 48 deletions(-) diff --git a/src/api/app/controllers/application_controller.rb b/src/api/app/controllers/application_controller.rb index 4567949..2ef396d 100644 --- a/src/api/app/controllers/application_controller.rb +++ b/src/api/app/controllers/application_controller.rb @@ -392,7 +392,7 @@ class ApplicationController < ActionController::Base end def get_request_path - path = request.path + path = request.path_info query_string = request.query_string if request.form_data? # it's uncommon, but possible that we have both diff --git a/src/api/app/controllers/build_controller.rb b/src/api/app/controllers/build_controller.rb index ff55e9c..8a245d1 100644 --- a/src/api/app/controllers/build_controller.rb +++ b/src/api/app/controllers/build_controller.rb @@ -152,7 +152,7 @@ class BuildController < ApplicationController return end - path = request.path+"?"+request.query_string + path = request.path_info+"?"+request.query_string if request.delete? unless permissions.project_change? params[:project] diff --git a/src/api/app/controllers/public_controller.rb b/src/api/app/controllers/public_controller.rb index 2efa907..e12450a 100644 --- a/src/api/app/controllers/public_controller.rb +++ b/src/api/app/controllers/public_controller.rb @@ -54,8 +54,8 @@ class PublicController < ApplicationController # project visible/known ? Project.get_by_name(params[:project]) - path = unshift_public(request.path) - path << "?#{request.query_string}" unless request.query_string.empty? + path = unshift_public(request.path_info) + path += "?#{request.query_string}" unless request.query_string.empty? pass_to_backend path end @@ -65,14 +65,14 @@ class PublicController < ApplicationController # project visible/known ? Project.get_by_name(params[:project]) - pass_to_backend unshift_public(request.path) + pass_to_backend unshift_public(request.path_info) end # GET /public/source/:project def project_index # project visible/known ? Project.get_by_name(params[:project]) - path = unshift_public(request.path) + path = unshift_public(request.path_info) if params[:view] == 'info' # nofilename since a package may have no source access if params[:nofilename] and params[:nofilename] != '1' @@ -94,7 +94,7 @@ class PublicController < ApplicationController # project visible/known ? Project.get_by_name(params[:project]) - path = unshift_public(request.path) + path = unshift_public(request.path_info) path += "?#{request.query_string}" unless request.query_string.empty? pass_to_backend path end @@ -103,7 +103,7 @@ class PublicController < ApplicationController def package_index check_package_access(params[:project], params[:package]) - path = unshift_public(request.path) + path = unshift_public(request.path_info) path += "?#{request.query_string}" unless request.query_string.empty? pass_to_backend path end @@ -112,7 +112,7 @@ class PublicController < ApplicationController def package_meta check_package_access(params[:project], params[:package], false) - pass_to_backend unshift_public(request.path) + pass_to_backend unshift_public(request.path_info) end # GET /public/source/:project/:package/:filename diff --git a/src/api/app/controllers/source_controller.rb b/src/api/app/controllers/source_controller.rb index 31bd578..d97b09e 100644 --- a/src/api/app/controllers/source_controller.rb +++ b/src/api/app/controllers/source_controller.rb @@ -250,8 +250,8 @@ class SourceController < ApplicationController end # exec - path = request.path - path << build_query_from_hash(params, [:rev, :linkrev, :emptylink, :expand, :view, :extension, :lastworking, :withlinked, :meta, :deleted, :parse, :arch, :repository, :product]) + path = request.path_info + path += build_query_from_hash(params, [:rev, :linkrev, :emptylink, :expand, :view, :extension, :lastworking, :withlinked, :meta, :deleted, :parse, :arch, :repository, :product]) pass_to_backend path end @@ -445,7 +445,7 @@ class SourceController < ApplicationController # init # assemble path for backend - path = request.path + path = request.path_info path += build_query_from_hash(params, [:user, :comment, :rev]) #allowed = false request_data = request.raw_post @@ -579,7 +579,7 @@ class SourceController < ApplicationController # GET /source/:project/_config def show_project_config - path = request.path + path = request.path_info path += build_query_from_hash(params, [:rev]) pass_to_backend path end @@ -601,7 +601,7 @@ class SourceController < ApplicationController end # assemble path for backend - path = request.path + path = request.path_info path += build_query_from_hash(params, [:user, :comment]) pass_to_backend path @@ -610,7 +610,7 @@ class SourceController < ApplicationController def pubkey_path # check for project @prj = Project.get_by_name(params[:project]) - request.path + build_query_from_hash(params, [:user, :comment, :meta, :rev]) + request.path_info + build_query_from_hash(params, [:user, :comment, :meta, :rev]) end # GET /source/:project/_pubkey and /_sslcert @@ -669,7 +669,7 @@ 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) + answer = Suse::Backend.get(request.path_info) if answer render :text => answer.body.to_s, :content_type => 'text/xml' else @@ -1097,8 +1097,8 @@ class SourceController < ApplicationController # is there any value in this call? Project.find_by_name params[:project] - path = request.path - path << build_query_from_hash(params, [:cmd, :user, :comment]) + path = request.path_info + path += build_query_from_hash(params, [:cmd, :user, :comment]) pass_to_backend path end @@ -1124,12 +1124,12 @@ class SourceController < ApplicationController raise CmdExecutionNoPermission.new "no permission to execute command 'undelete'" end - path = request.path - path << build_query_from_hash(params, [:cmd, :user, :comment]) + path = request.path_info + path += build_query_from_hash(params, [:cmd, :user, :comment]) pass_to_backend path # read meta data from backend to restore database object - path = request.path + '/_meta' + path = request.path_info + '/_meta' prj = Project.new(name: params[:project]) Project.transaction do prj.update_from_xml(Xmlhash.parse(backend_get(path))) @@ -1313,8 +1313,8 @@ class SourceController < ApplicationController # Collect all project source services for a package # POST /source/<project>/<package>?cmd=getprojectservices def package_command_getprojectservices - path = request.path - path << build_query_from_hash(params, [:cmd]) + path = request.path_info + path += build_query_from_hash(params, [:cmd]) pass_to_backend path end @@ -1358,12 +1358,12 @@ class SourceController < ApplicationController raise CmdExecutionNoPermission.new "no permission to create package in project #{@target_project_name}" end - path = request.path - path << build_query_from_hash(params, [:cmd, :user, :comment]) + path = request.path_info + path += build_query_from_hash(params, [:cmd, :user, :comment]) pass_to_backend path # read meta data from backend to restore database object - path = request.path + '/_meta' + path = request.path_info + '/_meta' prj = Project.find_by_name!(params[:project]) pkg = prj.packages.new(name: params[:package]) pkg.update_from_xml(Xmlhash.parse(backend_get(path))) @@ -1373,7 +1373,7 @@ class SourceController < ApplicationController # FIXME: obsolete this for 3.0 # POST /source/<project>/<package>?cmd=createSpecFileTemplate def package_command_createSpecFileTemplate - specfile_path = "#{request.path}/#{params[:package]}.spec" + specfile_path = "#{request.path_info}/#{params[:package]}.spec" begin backend_get( specfile_path ) render_error :status => 400, :errorcode => 'spec_file_exists', @@ -1395,7 +1395,7 @@ 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) + answer = Suse::Backend.get(request.path_info) unless answer render_error :status => 400, :errorcode => 'unknown_package', :message => "Unknown package '#{package_name}'" @@ -1424,8 +1424,8 @@ class SourceController < ApplicationController # POST /source/<project>/<package>?cmd=commit def package_command_commit - path = request.path - path << build_query_from_hash(params, [:cmd, :user, :comment, :rev, :linkrev, :keeplink, :repairlink]) + path = request.path_info + path += build_query_from_hash(params, [:cmd, :user, :comment, :rev, :linkrev, :keeplink, :repairlink]) pass_to_backend path if @package # except in case of _project package @@ -1436,8 +1436,8 @@ class SourceController < ApplicationController # POST /source/<project>/<package>?cmd=commitfilelist def package_command_commitfilelist - path = request.path - path << build_query_from_hash(params, [:cmd, :user, :comment, :rev, :linkrev, :keeplink, :repairlink]) + path = request.path_info + path += build_query_from_hash(params, [:cmd, :user, :comment, :rev, :linkrev, :keeplink, :repairlink]) answer = pass_to_backend path if @package # except in case of _project package @@ -1450,8 +1450,8 @@ class SourceController < ApplicationController #oproject_name = params[:oproject] #opackage_name = params[:opackage] - path = request.path - path << build_query_from_hash(params, [:cmd, :rev, :orev, :oproject, :opackage, :expand ,:linkrev, :olinkrev, + path = request.path_info + path += build_query_from_hash(params, [:cmd, :rev, :orev, :oproject, :opackage, :expand ,:linkrev, :olinkrev, :unified ,:missingok, :meta, :file, :filelimit, :tarlimit, :view, :withissues, :onlyissues]) pass_to_backend path @@ -1459,16 +1459,16 @@ class SourceController < ApplicationController # POST /source/<project>/<package>?cmd=linkdiff def package_command_linkdiff - path = request.path - path << build_query_from_hash(params, [:cmd, :rev, :unified, :linkrev, :file, :filelimit, :tarlimit, + path = request.path_info + path += build_query_from_hash(params, [:cmd, :rev, :unified, :linkrev, :file, :filelimit, :tarlimit, :view, :withissues, :onlyissues]) pass_to_backend path end # POST /source/<project>/<package>?cmd=servicediff def package_command_servicediff - path = request.path - path << build_query_from_hash(params, [:cmd, :rev, :unified, :file, :filelimit, :tarlimit, :view, :withissues, :onlyissues]) + path = request.path_info + path += build_query_from_hash(params, [:cmd, :rev, :unified, :file, :filelimit, :tarlimit, :view, :withissues, :onlyissues]) pass_to_backend path end @@ -1565,8 +1565,8 @@ class SourceController < ApplicationController # POST /source/<project>/<package>?cmd=runservice def package_command_runservice - path = request.path - path << build_query_from_hash(params, [:cmd, :comment, :user]) + path = request.path_info + path += build_query_from_hash(params, [:cmd, :comment, :user]) pass_to_backend path @package.sources_changed @@ -1575,8 +1575,8 @@ class SourceController < ApplicationController # POST /source/<project>/<package>?cmd=deleteuploadrev def package_command_deleteuploadrev - path = request.path - path << build_query_from_hash(params, [:cmd]) + path = request.path_info + path += build_query_from_hash(params, [:cmd]) pass_to_backend path end diff --git a/src/api/app/views/layouts/webui/webui.html.erb b/src/api/app/views/layouts/webui/webui.html.erb index b6f2d5a..77f3828 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/config/options.yml.example b/src/api/config/options.yml.example index 1a62f8a..d32a5a8 100644 --- a/src/api/config/options.yml.example +++ b/src/api/config/options.yml.example @@ -27,6 +27,7 @@ source_port: 5352 frontend_host: localhost frontend_port: 443 frontend_protocol: https +#api_relative_url_root: /obs # if your users access the hosts through a proxy (or just a different name, use this to # overwrite the settings for users) #external_frontend_host: api.opensuse.org 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}" -- 2.1.0
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