2012-10-29 17:48:08 -04:00
|
|
|
require 'fog/core/collection'
|
|
|
|
require 'fog/openstack/models/identity/ec2_credential'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Identity
|
|
|
|
class OpenStack
|
|
|
|
class Ec2Credentials < Fog::Collection
|
|
|
|
model Fog::Identity::OpenStack::Ec2Credential
|
|
|
|
|
|
|
|
attribute :user
|
|
|
|
|
|
|
|
def all
|
|
|
|
user_id = user ? user.id : nil
|
|
|
|
|
2012-12-22 18:24:36 -05:00
|
|
|
ec2_credentials = service.list_ec2_credentials(user_id)
|
2012-10-29 17:48:08 -04:00
|
|
|
|
|
|
|
load(ec2_credentials.body['credentials'])
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(attributes = {})
|
|
|
|
if user then
|
|
|
|
attributes[:user_id] ||= user.id
|
|
|
|
attributes[:tenant_id] ||= user.tenant_id
|
|
|
|
end
|
|
|
|
|
|
|
|
super attributes
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy(access_key)
|
|
|
|
ec2_credential = self.find_by_access_key(access_key)
|
|
|
|
ec2_credential.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_by_access_key(access_key)
|
|
|
|
user_id = user ? user.id : nil
|
|
|
|
|
|
|
|
ec2_credential =
|
|
|
|
self.find { |ec2_credential| ec2_credential.access == access_key }
|
|
|
|
|
|
|
|
unless ec2_credential then
|
2012-12-22 18:24:36 -05:00
|
|
|
response = service.get_ec2_credential(user_id, access_key)
|
2012-10-29 17:48:08 -04:00
|
|
|
body = response.body['credential']
|
2012-12-22 18:24:36 -05:00
|
|
|
body = body.merge 'service' => service
|
2012-10-29 17:48:08 -04:00
|
|
|
|
|
|
|
ec2_credential = Fog::Identity::OpenStack::EC2Credential.new(body)
|
|
|
|
end
|
|
|
|
|
|
|
|
ec2_credential
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|