module Conjur::HasAttributes
Many Conjur
assets have key-value attributes. Although these should generally be accessed via methods on specific asset classes (for example, {Conjur::Resource#owner}), the are available as a ‘Hash` on all types supporting attributes.
Public Class Methods
@api private
# File lib/conjur/has_attributes.rb, line 29 def annotation_value annotations, name (annotations.find{|a| a['name'] == name} || {})['value'] end
Public Instance Methods
# File lib/conjur/has_attributes.rb, line 74 def annotations Hash[(attributes['annotations']||{}).collect {|e| [e['name'],e['value']]}] end
# File lib/conjur/has_attributes.rb, line 34 def as_json options={} result = super(options) if @attributes result.merge!(@attributes.as_json(options)) end result end
Get the attributes for this asset. This is an immutable Hash, unless the attributes are changed via policy update.
@return [Hash] the asset’s attributes.
# File lib/conjur/has_attributes.rb, line 56 def attributes return @attributes if @attributes fetch end
@api private Set the attributes for this Resource
. @param [Hash] attributes new attributes for the object. @return [Hash] the new attributes
# File lib/conjur/has_attributes.rb, line 50 def attributes=(attributes); @attributes = attributes; end
Call a block that will perform actions that might change the asset’s attributes. No matter what happens in the block, this method ensures that the cached attributes will be invalidated.
@note this is mainly used internally, but included in the public api for completeness.
@return [void]
# File lib/conjur/has_attributes.rb, line 68 def invalidate(&block) yield ensure @attributes = nil end
# File lib/conjur/has_attributes.rb, line 42 def to_s to_json.to_s end
Protected Instance Methods
# File lib/conjur/has_attributes.rb, line 80 def annotation_value name annotations[name] end
@api private Fetch the attributes, overwriting any current ones.
# File lib/conjur/has_attributes.rb, line 86 def fetch @attributes ||= fetch_attributes end
@api private
# File lib/conjur/has_attributes.rb, line 91 def fetch_attributes cache_key = Conjur.cache_key username, url_for(:resources_resource, credentials, id).url Conjur.cache.fetch_attributes cache_key do JSON.parse(url_for(:resources_resource, credentials, id).get.body) end end