Module: Conjur::Exists

Included in:
Deputy, Resource, Role
Defined in:
lib/conjur/exists.rb

Instance Method Summary collapse

Instance Method Details

#exists?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/conjur/exists.rb', line 23

def exists?(options = {})
  begin
    self.head(options)
    true
  rescue RestClient::Forbidden
    # rationale is: exists? should return true iff creating a resource with
    # the same name would fail (not by client's fault). Why it would fail
    # doesn't matter that much.
    # (Plus, currently it always 403s when the resource exists but is unaccessible.)
    true
  rescue RestClient::ResourceNotFound
    false
  end
end