Sha256: 27fa947ffbdf29cdfc07c68bb69e01b565c34379a409537e91f41548d7ea9c68
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
require 'net/https' require 'json' require 'netrc' class AuthenticationController < MVCLI::Controller requires :user def login login_info = user username = login_info.name password = login_info.password connection = Excon.new('https://identity.api.rackspacecloud.com') headers = {'Content-Type' => 'application/json'} body = {auth: {passwordCredentials: {username: username, password: password}}} response = connection.post headers: headers, body: body.to_json, path: '/v2.0/tokens' #TODO check the status code of the request user_info = Map(JSON.parse response.body) headers.merge!({'X-Auth-Token' => user_info.access.token.id}) response = connection.get headers: headers, path: "/v2.0/users/#{user_info.access.user.id}/OS-KSADM/credentials/RAX-KSKEY:apiKeyCredentials" user_credentials = Map(JSON.parse response.body) netrc = Netrc.read netrc['api.rackspace.com'] = username, user_credentials["RAX-KSKEY:apiKeyCredentials"].apiKey netrc.save user_info end def logout n = Netrc.read n.delete 'api.rackspace.com' n.save end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rumm-0.0.5 | app/controllers/authentication_controller.rb |
rumm-0.0.4 | app/controllers/authentication_controller.rb |