Method: Rundeck::Client::Key#key_contents

Defined in:
lib/rundeck/client/key.rb

#key_contents(path, options = {}) ⇒ Rundeck::ObjectifiedHash

Get the contents of a key. Only allowed for public keys. Note: This method returns a raw string of the public key, not at ObjectifiedHash.

Examples:

Rundeck.key_contents('path/to/key1')

Options Hash (options):

  • :query (Hash)

    The parameters to pass with the request Use this hash to specify Rundeck parameters.

    • query: { project: ‘anvils’, id: ‘123456’ }

Raises:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rundeck/client/key.rb', line 68

def key_contents(path, options = {})
  # Check if key exists first. Otherwise we could return some
  # weird strings. Also, raise error if user is trying to get a
  # private key.
  key_content_type = (path, options).rundeck_content_type
  if key_content_type == content_type('private')
    fail Error::Unauthorized,
         'You are not allowed to retrieve the contents of a private key'
  end

  options.merge!(format: :plain,
                 headers: { 'Accept' => 'application/pgp-keys' })
  key = get("#{STORAGE_KEYS_PATH}/#{path}", options)
  objectify 'public_key' => key
end