require 'faraday' require 'faraday_middleware' require 'p4_web_api_client/errors' module P4WebApiClient # Adds common configuration to the Faraday connection, like, the host name, # version, and context prefixes. class Connection attr_accessor :user, :prefix, :session_token # See the options for Faraday.new, plus, the following fields: # - :user # - :password # - :prefix - defaults to '/v1' def initialize(options) local_opts = [:user, :password, :prefix] conn_options = options.select { |k| !local_opts.include?(k) } @conn = Faraday.new(conn_options) do |conn| conn.request :multipart conn.request :url_encoded conn.adapter :net_http end @session_token = nil if options.key?(:user) @user = options[:user] @prefix = options.key?(:prefix) ? options[:prefix] : '/v1' # When we're not initialized with a password, we may be on a insecure # server, so don't even log in. if options[:password] && !Connection.p4_ticket?(options[:password]) response = @conn.post(path_for('/sessions'), user: @user, password: options[:password]) assert_ok(response) @session_token = response.body else # When the password looks like a p4 ticket (or maybe it's empty), # we don't generate the session token @session_token = options[:password] || '' end @conn.basic_auth(user, session_token) end end def self.p4_ticket?(str) /^[a-zA-Z0-9]{32,}$/.match(str) != nil end def run_method_no_body(method, path, params = nil) path = path_for(path) response = @conn.send(method, path, params) assert_ok(response) response end def run_method_with_body(method, path, params = nil, body = nil) if !body && params body = params params = nil end path = path_for(path) if params params_hash = Faraday::Utils::ParamsHash.new params_hash.merge!(params) path += "?#{params_hash.to_query}" end response = @conn.send(method, path, body) assert_ok(response) response end # Basically just prepends the prefix to our subpath, typically, '/p4'. def path_for(subpath) if @prefix.empty? subpath elsif subpath.nil? or subpath.empty? @prefix else File.join(@prefix, subpath) end end # Raises an error when the response is not 200. Some errors may have # diagnostic information in the response body, so we pass that on as well def assert_ok(response) return unless response.status >= 400 if response.status == 403 fail Errors::Unauthenticated.new, 'Illegal login or password' elsif response.status == 404 fail Errors::ResourceNotFound.new, 'Required resource not found' elsif response.status == 500 && response.body fail P4WebApiClient::Errors::PerforceProblem.new(JSON.parse(response.body)), 'Unknown issue from the Perforce server' else fail Errors::ServerError.new, 'Unknown problem' end end end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 13972 | tjuricek |
Removing old microservice implementations. The system is now mostly a monolith. Eventually there will be a websocket service. |
||
#5 | 13635 | tjuricek |
Exploring modular web applications with Sinatra. If the app has fairly unique content per page, Sinatra works really well actually. (Mostly because it's a thin layer over Rack.) Sharing anything though, basically means implementing a module or base class and implementing it everywhere. An added benefit is that these applications could be used in Rails apps as well. I'd probably think hard about this, because Rails tends to be a resource hog. Here's an example config.ru I used for running against the dev system: require 'pms' app = Pms::App.new Pms::Login.settings.p4_web_api_url = http://172.16.100.20/p4_web_api/v1 ProjectApp.settings.phoenix_services_url = http://172.16.100.20/p4_phoenix_services/v1 app.settings.static = :true app.settings.public_folder = File.absolute_path('../../ui/pms', __FILE__) puts "public_folder is #{app.settings.public_folder}" run app |
||
#4 | 13528 | tjuricek |
Moved rack and app server configuration to be managed via Salt. Also, only using a single value "url" to configure how the p4_project_services instance references the p4_web_api. And, removing the Docker setup, since that won't work for a production system. |
||
#3 | 13470 | tjuricek |
Phoenix notification services, client API, including new phoenix_updater This is an interim commit containing a first pass implementation of the phoenix_updater. Notably missing parts: - The Qt API doesn't yet actually interact with the phoenix_updater - The phoenix_services web service doesn't filter out notifications I *may* end up creating another web application *just* to filter out notifications, since this may end up taking up a lot of background workers. |
||
#2 | 13419 | tjuricek | The p4_project_services specs now run that provide basic create-read ability. | ||
#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. |