require 'auth' require 'config' require 'hws_p4_cleanup' require 'hws_helpers' require 'hws_settings' require 'helix_sync' require 'helix_web_services/version' require 'helix_versioning_engine' require 'projects' require 'rack/parser' require 'sinatra/base' require 'sinatra/namespace' require 'git_fusion_strings' require 'P4' module HelixWebServices module ErrorHandling def self.registered(app) # Always invoke our error handlers. app.set :raise_errors => false app.set :show_exceptions => false app.set :dump_errors => true app.error do |err| err = env['sinatra.error'] if err.is_a?(P4Exception) # Can happen when we're not passing a block to # open_p4. Convert to a P4WebAPI error. This is not ideal # as it always uses the same code, but then we have no idea # what actually happened here. err = P4Error.default_error(err.to_s) # Fall through... end body = nil if err.is_a?(P4Error) if err.message_code == 7480 || err.message_code == 7189 halt 401, { MessageCode: 0, MessageSeverity: 4, MessageText: 'Resource not found' }.to_json else code = 500 code = 400 if err.user_error? halt code, { MessageCode: err.message_code, MessageSeverity: err.message_severity, MessageText: err.message_text }.to_json end end if body.nil? body = { MessageCode: 15_361, MessageSeverity: P4::E_FATAL, MessageText: 'Unknown server issue' }.to_json end halt 500, body end end end # A master Sinatra instance that basically sets up routing to each of the # sub-applications, and connects the authorization mechanism. # # In the future, we may have status and health check functionality available # here. # # We mount each application under a "versioned" subpath. This allows us to # keep an old and new version of a sub-application in the system at the # same time, ideally to allow for migration to breaking changes. class Master < Sinatra::Base register Sinatra::Namespace register HelixWebServices::ErrorHandling # Without this set, the return content type is always text/html before do content_type 'application/json' end # Inject Rack::Parser into the middleware stack so that it # automatically parses json bodies in post requests into the params # array. use Rack::Parser, content_types: { 'application/json' => proc { |body| ::MultiJson.decode body } } use HWSSettings use HWSP4Cleanup use Auth::Middleware, unauthenticated_paths: [ {method: 'POST', path: '/projects/v1/login'}, {method: 'POST', path: /p4\/v(\d*)\/login/}, {method: 'GET', path: '/status'} ] not_found do status 404 '' end class << self def register_app(app) use app app.register HelixWebServices::ErrorHandling app.before do content_type 'application/json' headers['X-Helix-Web-Services-Version'] = HelixWebServices::PRODUCT_ID end app.helpers HWSHelpers app.not_found do status 404 '' end end end get '/status' do {'status'=>'OK'}.to_json end register_app(Config::App) register_app(HelixVersioningEngine::App) register_app(Projects::App) if HWSSettings.system.ENABLE_GIT_FUSION require 'git_fusion' register_app(GitFusion::App) end register_app(HelixSync::App) # This is special method to inject custom middleware after you know the # per-request settings have been initialized. def self.use_after_settings(middleware, *args, &block) @prototype = nil settings_index = @middleware.index { |m| m.first == HWSSettings } @middleware.insert settings_index + 1, [middleware, args, block] end end end # We offer a special path in our settings where we'll load up any scripts # and require them. scripts_dir = ENV['CUSTOM_SCRIPTS'] || HWSSettings.system.CUSTOM_SCRIPTS if Dir.exist?(scripts_dir) $LOAD_PATH << scripts_dir Dir.glob("#{scripts_dir}/*.rb").each do |s| require s end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 16318 | Doug Scheirer | merge from main | ||
#5 | 16148 | Doug Scheirer | Merge from main | ||
#4 | 16114 | Doug Scheirer | Merge from main | ||
#3 | 16014 | Doug Scheirer | Merge down 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_web_services.rb | |||||
#2 | 15687 | tjuricek |
Associate 400 status codes for severity 3 exceptions and 500 for severity 4. We don't throw P4Exception for severity < 3 at the moment, since those are typically just warnings, like "you have no files in that directory". |
||
#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_web_services.rb | |||||
#11 | 15600 | tjuricek | Add /status method back to verify that the user's session actually works. | ||
#10 | 15513 | tjuricek |
Add a product ID header for debugging purposes. This will generally display INVALID unless the version file has been created during the build. |
||
#9 | 15297 | tjuricek |
Implement of 'cluster services' configuration. The configuration will be stored in a local JSON file, which is expected to be maintained by the systems admin. Eventually, it's expected to have this sort of thing implemented via Helix Admin. |
||
#8 | 15242 | tjuricek | Add Helix Sync stubs and documentation | ||
#7 | 15241 | tjuricek | Add Git Fusion stubs and documentation. | ||
#6 | 15110 | tjuricek | Revise changes methods for new p4 connection handling, add server specs, remove model references in client, and update asciidoc documentation. | ||
#5 | 15099 | tjuricek | Revise project services to be our simple 'container' for other systems. | ||
#4 | 15077 | tjuricek |
Add new 'model' technique, revised branch spec operations, test Auth::Middleware. The Ruby client now does *not* strictly type anything, but extends OpenStruct with helper methods to help deal with inconsistent data formats. See the OpenModel class documentation for more details. The Auth::Middleware class is also *finally* implemented as well. This does not take into account all possible variations of server behavior (yet), but that will happen in follow-up work. |
||
#3 | 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. |
||
#2 | 13941 | tjuricek |
Re-implemented the sync project methods at the HTTP level. The Qt API is missing the "members" concept, but it's likely not quite usable just yet. It's existing logic does work, however. |
||
#1 | 13799 | tjuricek |
Start with branch specs hosting in a new monolithic 'helix web services' project. Converting from a microservice to a monolithic architecture due to resource constraints at getting a deployable system running. Additionally, since it's not expected that people will upgrade often, the major benefit of microservices - being able to add services individually without affecting others - is not really a major benefit. The Ruby SDK will be consolidated into a single 'helix web services client' project. It may end up being distributed via Rubygems. This only runs branch specs at the moment. I want to get a CD pipeline setup for the monolithic server before revising more methods. |