Class: Fog::Identity::OpenStack::V3::Projects

Inherits:
OpenStack::Collection show all
Defined in:
lib/fog/openstack/models/identity_v3/projects.rb

Constant Summary collapse

@@cache =
{}

Instance Attribute Summary

Attributes inherited from OpenStack::Collection

#response

Instance Method Summary collapse

Methods inherited from OpenStack::Collection

#destroy, #get, #load_response, #summary

Instance Method Details

#all(options = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/fog/openstack/models/identity_v3/projects.rb', line 14

def all(options = {})
  cached_project, expires = @@cache[{token: service.auth_token, options: options}]
  return cached_project if cached_project && expires > Time.now
  project_to_cache = load_response(service.list_projects(options), 'projects')
  @@cache[{token: service.auth_token, options: options}] = project_to_cache, Time.now + 30 # 30-second TTL
  return project_to_cache
end

#auth_projects(options = {}) ⇒ Object



27
28
29
# File 'lib/fog/openstack/models/identity_v3/projects.rb', line 27

def auth_projects(options = {})
  load(service.auth_projects(options).body['projects'])
end

#create(attributes) ⇒ Object



22
23
24
25
# File 'lib/fog/openstack/models/identity_v3/projects.rb', line 22

def create(attributes)
  @@cache.clear if @@cache
  super(attributes)
end

#find_by_id(id, options = []) ⇒ Object

options can include :subtree_as_ids, :subtree_as_list, :parents_as_ids, :parents_as_list



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/openstack/models/identity_v3/projects.rb', line 31

def find_by_id(id, options=[]) # options can include :subtree_as_ids, :subtree_as_list, :parents_as_ids, :parents_as_list
  if options.is_a? Symbol # Deal with a single option being passed on its own
    options = [options]
  end
  cached_project, expires = @@cache[{token: service.auth_token, id: id, options: options}]
  return cached_project if cached_project && expires > Time.now
  project_hash = service.get_project(id, options).body['project']
  top_project = project_from_hash(project_hash, service)
  if options.include? :subtree_as_list
    top_project.subtree.map! {|proj_hash| project_from_hash(proj_hash['project'], service)}
  end
  if options.include? :parents_as_list
    top_project.parents.map! {|proj_hash| project_from_hash(proj_hash['project'], service)}
  end
  @@cache[{token: service.auth_token, id: id, options: options}] = top_project, Time.now + 30 # 30-second TTL
  return top_project
end