require 'p4_web_api/p4_util' module P4WebAPI # Defines Sinatra helper methods in the main application. module Helpers # A block helper that uses the authentication credentials to create the p4 # connection def open_p4(&block) options = { user: env['AUTH_CREDENTIALS'].first, password: P4Util.resolve_password(env, settings), host: P4Util.resolve_host(env, settings), port: P4Util.resolve_port(env, settings) } charset = P4Util.resolve_charset(env, settings) options[:charset] = charset if charset P4Util.open(options, &block) end # Block helper to open a p4 handle with a temporary client workspace. # The client workspace will map the series of depot path expressions # directly into the client workspace. # # The depot_paths are generally expected to be complete file path # expressions, e.g., '//depot/dir1/dir2/file'. They'll be mapped directly # to the temporary working area: '//client/depot/dir/1/dir2/file' # # The block handler here will be called with the arguments (p4, root), # where root is the temporary client's root directory. def open_p4_temp_client(depot_paths, &block) open_p4 do |p4| name = (0...8).map { (65 + rand(26)).chr }.join dir = init_temp_workspace_dir(name) init_temp_client(p4, name, dir, depot_paths) ex = nil begin block.call(p4, dir) rescue StandardError => e ex = e end # We need to convert any exception before attempting to delete, # otherwise the p4.messages and p4.errors will get reset at the next # method call. if ex.instance_of?(P4Exception) ex = P4Util.make_p4_error(p4) end p4.at_exception_level(P4::RAISE_NONE) do delete_temp_client(p4, name, dir) end fail ex unless ex.nil? end end private def init_temp_workspace_dir(name) dir = File.join(settings.workspace_folder, name) unless Dir.exist?(dir) FileUtils.mkpath(dir) FileUtils.chmod(0700, dir) end dir end def init_temp_client(p4, name, dir, depot_paths) spec = p4.fetch_client spec._root = dir spec._client = name spec._description = 'p4_web_api temp client' spec._view = depot_paths.map do |path| stripped = path.gsub(/^[\/]*/, '') "\"//#{stripped}\" \"//#{name}/#{stripped}\"" end p4.save_client(spec) p4.client = name p4.run_sync('//...') end def delete_temp_client(p4, name, dir) p4.run_client('-d', '-f', name) FileUtils.rmtree(dir) end end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 13972 | tjuricek |
Removing old microservice implementations. The system is now mostly a monolith. Eventually there will be a websocket service. |
||
#2 | 13513 | tjuricek | Update several files that were missing from the last commit regarding a basic 'test' environment | ||
#1 | 13412 | tjuricek |
Initial version of the web-services mainline. This is a collection of several projects, that will likely often get released together, though many of them may not always be relevant. See the README for more information. |