1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/rackspace/models/identity/credentials.rb
Brad Gignac f9c5773bb6 [rackspace|identity] Correctly populate model from request data.
Previously, the model was being incorrectly loaded from request data. As a
result, the username and apiKey properties were always nil. This fixes parsing
and improves the tests to catch this type of bug in the future.
2013-01-29 17:10:49 -05:00

33 lines
768 B
Ruby

require 'fog/core/collection'
require 'fog/rackspace/models/identity/credential'
module Fog
module Rackspace
class Identity
class Credentials < Fog::Collection
model Fog::Rackspace::Identity::Credential
attr_accessor :user
def all
requires :user
load(retrieve_credentials)
end
def get(id)
requires :user
data = retrieve_credentials.find { |credential| credential['apiKey'] == id }
data && new(data)
end
private
def retrieve_credentials
raw_credentials = service.list_credentials(user.identity).body['credentials']
raw_credentials.map { |c| c['RAX-KSKEY:apiKeyCredentials'] }
end
end
end
end
end