require 'sinatra/base' require 'hws_settings' module HelixVersioningEngine # Methods for executing generic Perforce commands. # # These do not actually map to any particular 'resource', but are just a # bucket for random things you can try out. # # thj: I would prefer to remove these methods, and replace them with # 'resources' we would define for people. class App < Sinatra::Base get '/helix_versioning_engine/:api/commands/:cmd' do |_, cmd| args = params.select { |k, _| k.start_with?('arg') }.map { |_, v| v } check_whitelist(cmd, args) require_p4 p4 = env['p4'] results = p4.run(cmd, *args) messages = p4.messages if messages && messages.length > 0 messages.map { |m| to_msg(m) }.to_json elsif results results.to_json end end post '/helix_versioning_engine/:api/commands/:cmd' do |_, cmd| args = params.select { |key, _| key.start_with?('arg') }.map { |_, x| x } check_whitelist(cmd, args) require_p4 p4 = env['p4'] p4.input = filter_params(params) p4.run(cmd, args) messages = p4.messages messages.map { |m| to_msg(m) }.to_json if messages end def check_whitelist(cmd, args) # Make sure command is whitelisted cmd_whitelisted = HWSSettings.system.COMMAND_WHITELIST.any? do |wl| if wl.is_a?(String) wl == cmd elsif wl.is_a?(Array) wl.first == cmd end end unless cmd_whitelisted halt 403, { MessageCode: 15_360, MessageText: "#{cmd} not whitelisted in configuration", MessageSeverity: :ERROR }.to_json end # If command is whitelisted, double check that we do not have required # arguments required_args = HWSSettings.system.COMMAND_WHITELIST.find do |wl| if wl.is_a?(Array) wl.first == cmd end end if required_args unless required_args.drop(1).all? { |r| args.include?(r) } halt 403, { MessageCode: 15_360, MessageText: "#{cmd} not used with all required arguments #{required_args.drop(1)}", MessageSeverity: :ERROR }.to_json end end end end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 15741 | ptomiak | Branch HWS for my use. | ||
//guest/perforce_software/helix-web-services/main/source/helix_web_services/lib/helix_versioning_engine/app/commands.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/commands.rb | |||||
#4 | 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 |
||
#3 | 15208 | tjuricek |
Revise 'command' implementation, tests, and documentaiton. This includes a change from a command blacklist to a whitelist. See P4WEBAPI-21 |
||
#2 | 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. |
||
#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/commands.rb | |||||
#3 | 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. |
||
#2 | 13808 | tjuricek | Finish converting most of the core p4d API into the new monolithic system. | ||
#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. |
||
//guest/perforce_software/helix-web-services/main/p4_web_api/p4_web_api/lib/p4_web_api/app/commands.rb | |||||
#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. |