require 'net/http' require 'hws_settings' require 'json' # require 'cloud/projects_service' module Cloud class Auth def self.valid_session?(env, auth) # if the session is not valid, throw an exception # GET (cloud url)/api/v1/user uri = URI("#{Settings.cloud_settings[:helix_cloud_url]}/api/v1/user") # auth.credentials.first == username # auth.credentials.last == session token req = Net::HTTP::Get.new(uri) req['Cookie'] = auth.credentials.last req['Content-Type'] = 'application/json' res = Net::HTTP.start(uri.hostname, uri.port) {|http| http.request(req) } # make sure the username matches? return false if res.code != '200' || JSON(res.body)['user'] != auth.credentials.first env['AUTH_CREDENTIALS'] = auth.credentials env['p4.user'] = JSON(res.body)['user'] env['p4'] = nil return true end def self.login(user, password) begin # POST (cloud url)/api/v1/login # puts "login against #{Settings.cloud_settings[:helix_cloud_url]}/api/v1/login" uri = URI("#{Settings.cloud_settings[:helix_cloud_url]}/api/v1/login") # return the session token for this user req = Net::HTTP::Post.new(uri) req['Content-Type'] = 'application/json' req.set_form_data('user[name]' => user, 'user[password]' => password) res = Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) } # the body contains the required cookie return (res.code != '200') ? nil : res.body rescue Exception => e # puts e.message end end def self.logout(env) # POST (cloud url)/api/v1/logout uri = URI("#{HWSSettings.cloud_settings[:helix_cloud_url]}/api/v1/login") # set the session token somehow res = Net::HTTP.post(uri) end end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 16024 | Doug Scheirer | Some cloud spec forking, got the mock_raymond to spin up in cloud testing, split normal vs cloud spec output | ||
#2 | 15872 | Doug Scheirer |
More tweaks for Cloud environment, still have HVE_... nil issues in client test env |
||
#1 | 15854 | Doug Scheirer |
Cloud auth and projects Still getting 2 extra project errors even thought nothing is configured to be cloud enabled |