# Copyright (c) 2014-2015 Perforce Software, Inc. All rights reserved. # # This is a HTTP interface to the p4d server (via p4ruby). require 'sinatra/base' require 'sinatra/json' require 'sinatra/config_file' require 'helix_versioning_engine/util' module HelixVersioningEngine # This web application is mostly a lightweight way of connecting the tagged # output via P4Ruby to JSON clients can consume relatively simply. class App < Sinatra::Base register Sinatra::ConfigFile # TODO not sure this should be in a sub-module not_found do return { # This is not an application error, so I'm using error code 0 to mean # 'use HTTP status' MessageCode: 0, MessageSeverity: 3, MessageText: 'Resource not found' }.to_json end def to_msg(message) { MessageCode: message.msgid, MessageSeverity: message.severity, MessageText: message.to_s } end # Will fetch the system offset based on the server date. # # If allow_env_p4_config is true, we don't cache. Each request could come # in from a new server, and the different servers may have different # offsets. def offset if settings.allow_env_p4_config fetch_offset else @offset ||= fetch_offset end end def fetch_offset offset = nil open_p4_as_user do |p4| results = p4.run_info offset = Util.p4_date_offset(results[0]['serverDate']) end offset end @normalizers = {} class << self attr_accessor :normalizers end # It's assumed that these are typically used to find the different spec # types within typical requests. def method_missing(method, *args) return unless method.to_s =~ /^normalize_(.*)/ spec_type = Regexp.last_match[1] unless self.class.normalizers.key?(spec_type) self.class.normalizers[spec_type] = Util.normalizer(spec_type, offset) end self.class.normalizers[spec_type].call(*args) end # Basically a "blacklist" of things we know the frameworks going to add to # the params array we don't want to pass on to the p4 command sets for spec # input def filter_params(params) params.select do |k, _v| k != 'spec_type' && k != 'id' && k != 'splat' && k != 'captures' end end before do match = /^\/p4\/v(\d+)\//.match(request.path_info) if match level = Integer(match[1]) # In case the p4 handle is not available, override any header env['HTTP_X_PERFORCE_HELIX_WEB_SERVICES_P4APILEVEL'] = match[1] if env['p4'] env['p4'].api_level = level end end end end end # Reopen up the P4WebAPI::App class and add most of our method handling. This # is done in lieu of having multiple Sinatra apps, so we can have the same # configuration and error handling. require 'helix_versioning_engine/app/changes' require 'helix_versioning_engine/app/commands' require 'helix_versioning_engine/app/counters' require 'helix_versioning_engine/app/files' require 'helix_versioning_engine/app/login' require 'helix_versioning_engine/app/protections' require 'helix_versioning_engine/app/specs' require 'helix_versioning_engine/app/streams' require 'helix_versioning_engine/app/triggers' require 'helix_versioning_engine/app/users'
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 16114 | Doug Scheirer | Merge from main | ||
#2 | 15715 | Doug Scheirer | merge changes from main | ||
#1 | 15688 | Doug Scheirer |
Populate -o //guest/perforce_software/helix-web-services/... //guest/doug_scheirer/helix-web-services/.... |
||
//guest/perforce_software/helix-web-services/main/source/helix_web_services/lib/helix_versioning_engine/app.rb | |||||
#1 | 15622 | tjuricek |
Move source code to 'source/' subdirectory of branch. build/ will remain where it is. |
||
//guest/perforce_software/helix-web-services/main/helix_web_services/lib/helix_versioning_engine/app.rb | |||||
#5 | 15240 | tjuricek |
Set api level via request path on all Helix Versioning Engine methods. This will allow migration of applications to different P4D versions. Our internal methods (like project API) should attempt to handle backward compatibility similarly. P4WEBAPI-118 |
||
#4 | 15225 | tjuricek |
Revise counter implementation, tests, and documentation Wasn't available in the Ruby client before, so, it's now available. |
||
#3 | 15208 | tjuricek |
Revise 'command' implementation, tests, and documentaiton. This includes a change from a command blacklist to a whitelist. See P4WEBAPI-21 |
||
#2 | 15099 | tjuricek | Revise project services to be our simple 'container' for other systems. | ||
#1 | 15032 | tjuricek |
Starting config and doc revisions. System is now broken while revisions underway. Configuration of the p4d connection is now done via a single HWSSettings middleware object injected into the Rack env. The HWSP4Cleanup middleware now cleans up any p4 injected into the Rack env. The Auth::App class now mostly just contains one method to generate a p4 ticket. /auth/v1/login. Added yard documentation for the main project. Yard docs have been reconfigured to dump into build/ directories. This should probably be done with each release. Hm... The top level rake file contains a task, 'all:doc', to update our documentation. This should probably be run for each checkin. Hm... Specs are now using Rack::Test on top of a 'live' p4d. I'd suggest you still use the p4util mechanism, which now dumps to a /tmp folder, so we can safely add P4IGNORE rules back into your local .p4config file. Old 'perforce' application now called 'helix_versioning_engine'. Removing cache data. Helix Sync may be slow. It may also get axed. We'll see. |
||
//guest/perforce_software/helix-web-services/main/helix_web_services/lib/perforce/app.rb | |||||
#1 | 13839 | tjuricek |
Conversion of the p4_project_service microservice to new monolithic system. This may not have an HTTP front end in the monolithic system. Project services are really just about how the core object model is structured. It's likely that each application will add their own wrinkles and extensions to the system, so it's unlikely we'll need a generic "project model". Exactly how extensions are registered and used is still a bit TBD at the moment. Previously they were to be registered webhooks, that model may change. Does not include tests yet. |