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
37
38
39
40
41
|
# File 'app/controllers/authentication_controller.rb', line 11
def login
login_info = login_information
username = login_info.name
password = login_info.password
uri = URI.parse(configuration.auth_endpoint)
connection = Excon.new(uri.to_s)
= {'Content-Type' => 'application/json'}
body = {auth: {passwordCredentials: {username: username, password: password}}}
response = connection.post headers: , body: body.to_json, path: '/v2.0/tokens'
user_info = Map(JSON.parse response.body)
fail "User could not be authenticated" unless user_info[:access]
.merge!({'X-Auth-Token' => user_info.access.token.id})
response = connection.get headers: , path: "/v2.0/users/#{user_info.access.user.id}/OS-KSADM/credentials/RAX-KSKEY:apiKeyCredentials"
user_credentials = Map(JSON.parse response.body)
configuration.username = username
configuration.api_key = user_credentials["RAX-KSKEY:apiKeyCredentials"].apiKey
configuration.region = login_info.region
configuration.save
user_info
end
|