Class: AuthenticationController

Inherits:
MVCLI::Controller
  • Object
show all
Defined in:
app/controllers/authentication_controller.rb

Instance Method Summary collapse

Instance Method Details

#loginObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/authentication_controller.rb', line 10

def 
   = user
  username = .name
  password = .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
   = Map(JSON.parse response.body)

  headers.merge!({'X-Auth-Token' => .access.token.id})
  response = connection.get headers: headers, path: "/v2.0/users/#{.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

  
end

#logoutObject



38
39
40
41
42
# File 'app/controllers/authentication_controller.rb', line 38

def logout
  n = Netrc.read
  n.delete 'api.rackspace.com'
  n.save
end