Class: Fog::Identity::OpenStack::Ec2Credentials

Inherits:
Collection
  • Object
show all
Defined in:
lib/fog/openstack/models/identity/ec2_credentials.rb

Instance Attribute Summary

Attributes inherited from Collection

#service

Instance Method Summary collapse

Methods inherited from Collection

#clear, #initialize, #inspect, #load, model, #model, #new, #reload, #table, #to_json

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Collection

Instance Method Details

#allObject



12
13
14
15
16
17
18
# File 'lib/fog/openstack/models/identity/ec2_credentials.rb', line 12

def all
  user_id = user ? user.id : nil

  ec2_credentials = service.list_ec2_credentials(user_id)

  load(ec2_credentials.body['credentials'])
end

#create(attributes = {}) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/fog/openstack/models/identity/ec2_credentials.rb', line 20

def create(attributes = {})
  if user then
    attributes[:user_id]   ||= user.id
    attributes[:tenant_id] ||= user.tenant_id
  end

  super attributes
end

#destroy(access_key) ⇒ Object



29
30
31
32
# File 'lib/fog/openstack/models/identity/ec2_credentials.rb', line 29

def destroy(access_key)
  ec2_credential = self.find_by_access_key(access_key)
  ec2_credential.destroy
end

#find_by_access_key(access_key) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/openstack/models/identity/ec2_credentials.rb', line 34

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
    response = service.get_ec2_credential(user_id, access_key)
    body = response.body['credential']
    body = body.merge 'service' => service

    ec2_credential = Fog::Identity::OpenStack::EC2Credential.new(body)
  end

  ec2_credential
end