Module: Conjur::ActsAsResource
- Included in:
 - Resource, Variable, Webservice
 
- Defined in:
 - lib/conjur/acts_as_resource.rb
 
Overview
This module is included in object classes that have resource behavior.
Instance Method Summary collapse
- 
  
    
      #exists?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Check whether this object exists by performing a HEAD request to its URL.
 - 
  
    
      #owner  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    
The full role id of the role that owns this resource.
 - 
  
    
      #permitted?(privilege, role: nil)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
True if the logged-in role, or a role specified using the :role option, has the specified +privilege+ on this resource.
 - 
  
    
      #permitted_roles(privilege)  ⇒ Array<String> 
    
    
  
  
  
  
  
  
  
  
  
    
Lists roles that have a specified privilege on the resource.
 
Instance Method Details
#exists? ⇒ Boolean
Check whether this object exists by performing a HEAD request to its URL.
This method will return false if the object doesn't exist.
      62 63 64 65 66 67 68 69 70 71  | 
    
      # File 'lib/conjur/acts_as_resource.rb', line 62 def exists? begin url_for(:resources_resource, credentials, id).head true rescue RestClient::Forbidden true rescue RestClient::ResourceNotFound false end end  | 
  
#owner ⇒ String
The full role id of the role that owns this resource.
      40 41 42  | 
    
      # File 'lib/conjur/acts_as_resource.rb', line 40 def owner build_object attributes['owner'], default_class: Role end  | 
  
#permitted?(privilege, role: nil) ⇒ Boolean
True if the logged-in role, or a role specified using the :role option, has the specified +privilege+ on this resource.
      114 115 116 117 118 119 120 121  | 
    
      # File 'lib/conjur/acts_as_resource.rb', line 114 def permitted? privilege, role: nil url_for(:resources_check, credentials, id, privilege, role) true rescue RestClient::Forbidden false rescue RestClient::ResourceNotFound false end  | 
  
#permitted_roles(privilege) ⇒ Array<String>
Lists roles that have a specified privilege on the resource.
This will return only roles of which api.current_user is a member.
Options:
- offset Zero-based offset into the result set.
 - limit Total number of records returned.
 
      90 91 92 93 94 95 96 97  | 
    
      # File 'lib/conjur/acts_as_resource.rb', line 90 def permitted_roles privilege result = JSON.parse url_for(:resources_permitted_roles, credentials, id, privilege).get if result.is_a?(Hash) && ( count = result['count'] ) count else result end end  |