require 'cloud/auth' require 'hws_settings' require 'json' require 'p4_error' require 'p4_util' require 'projects/methods' require 'sinatra/base' require 'auth' module Projects class App < Sinatra::Base include Projects::Methods # Sign into the "project server" depending upon the configuration of the # system. # # One implementation of this sits on top of a single p4d. Another uses # Helix Cloud. # # One subtle behavior of p4 login -p, is that it will reuse any token # lying in a p4ticket file. What this means, is that if you sign on, say, # using the p4 command line, this method will end up reusing and returning # that ticket. # # So, make sure you run your web services instance in a clean environment # that you don't do interactive work (like maintenance stuff) under. post '/projects/v1/login' do user = params[:user] password = params[:password] # may be a p4 ticket if user.nil? or password.nil? fail P4Error.default_error('user or password is not set') end ticket = nil if Cloud::Settings.cloud_enabled? ticket = Cloud::Auth::login(user, password) else env['p4'] = P4Util.open_from_env(env) p4 = env['p4'] p4.user = user p4.password = password p4.connect ticket = Auth.ticket_from_login(p4) end halt 403 if ticket.nil? if request.env['HTTP_ACCEPT'] =~ /application\/json/ content_type 'application/json' return { ticket: ticket }.to_json else content_type 'text/plain' return ticket end end # Query parameters: # # - `details` [Boolean] # - `extension` [String] get '/projects/v1' do require_p4 unless Cloud::Settings.cloud_enabled? options = {} options[:details] = params['details'] if params.key?('details') options[:extension] = params['extension'] if params.key?('extension') projects = list(options) projects.to_json if projects end get '/projects/v1/:project_id' do |project_id| require_p4 unless Cloud::Settings.cloud_enabled? project = fetch(project_id) halt 404 unless project project.to_json end end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 16114 | Doug Scheirer | Merge from main | ||
#4 | 15872 | Doug Scheirer |
More tweaks for Cloud environment, still have HVE_... nil issues in client test env |
||
#3 | 15854 | Doug Scheirer |
Cloud auth and projects Still getting 2 extra project errors even thought nothing is configured to be cloud enabled |
||
#2 | 15845 | Doug Scheirer | Integ 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/projects/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/projects/app.rb | |||||
#1 | 15099 | tjuricek | Revise project services to be our simple 'container' for other systems. |