Module: Rundeck::Client::Key

Included in:
Rundeck::Client
Defined in:
lib/rundeck/client/key.rb

Overview

Defines methods related to projects.

Instance Method Summary collapse

Instance Method Details

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

Create a private key

Examples:

key = "-----BEGIN RSA PRIVATE KEY-----\nProc-Type:..."
Rundeck.create_private_key('path', key)

Parameters:

Options Hash (options):

  • :query (Hash)

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

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

Returns:

Raises:



95
96
97
# File 'lib/rundeck/client/key.rb', line 95

def create_private_key(path, key, options = {})
  create_or_update_key(path, key, 'private', 'post', options)
end

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

Create a public key

Examples:

key = "ssh-rsa AAAA.....3MOj [email protected]"
Rundeck.create_public_key('path/to/key', key)

Parameters:

Options Hash (options):

  • :query (Hash)

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

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

Returns:

Raises:



127
128
129
# File 'lib/rundeck/client/key.rb', line 127

def create_public_key(path, key, options = {})
  create_or_update_key(path, key, 'public', 'post', options)
end

#delete_key(path, options = {}) ⇒ nil

Delete a key

Examples:

Rundeck.delete_key('path/to/key')

Parameters:

Options Hash (options):

  • :query (Hash)

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

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

Returns:

  • (nil)

Raises:



157
158
159
# File 'lib/rundeck/client/key.rb', line 157

def delete_key(path, options = {})
  delete("#{STORAGE_KEYS_PATH}/#{path}", options)
end

#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')

Parameters:

Options Hash (options):

  • :query (Hash)

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

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

Returns:

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

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

Get a single key’s metadata

Examples:

Rundeck.('path/to/key1')

Parameters:

Options Hash (options):

  • :query (Hash)

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

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

Returns:

Raises:



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rundeck/client/key.rb', line 44

def (path, options = {})
  r = get("#{STORAGE_KEYS_PATH}/#{path}", options)

  # In case a user provides a key path instead of a path to a single key.
  if r['resource']['contents']
    fail Error::InvalidAttributes,
         'Please provide a key storage path that ' \
         'is a direct path to a key'
  else
    objectify r['resource']['resource_meta']
  end
end

#keys(path = '', options = {}) ⇒ Array<Rundeck::ObjectifiedHash>

Gets a list of keys at a specific path.

Examples:

Rundeck.keys('path')

Parameters:

Options Hash (options):

  • :query (Hash)

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

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

Returns:

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rundeck/client/key.rb', line 20

def keys(path = '', options = {})
  r = get("#{STORAGE_KEYS_PATH}/#{path}", options)

  # In case a user provides a direct path to a key, error.
  if r['resource']['contents']
    objectify r['resource']['contents']['resource']
  else
    fail Error::InvalidAttributes,
         'Please provide a key storage path that ' \
         'isn\'t a direct path to a key'
  end
end

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

Update a private key

Examples:

key = "-----BEGIN RSA PRIVATE KEY-----\nProc-Type:..."
Rundeck.update_private_key('path', key)

Parameters:

Options Hash (options):

  • :query (Hash)

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

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

Returns:

Raises:



111
112
113
114
# File 'lib/rundeck/client/key.rb', line 111

def update_private_key(path, key, options = {})
  key_check(path, 'private', options)
  create_or_update_key(path, key, 'private', 'put', options)
end

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

Update a public key

Examples:

key = "ssh-rsa AAAA.....3MOj [email protected]"
Rundeck.update_public_key('path/to/key', key)

Parameters:

Options Hash (options):

  • :query (Hash)

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

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

Returns:

Raises:



143
144
145
146
# File 'lib/rundeck/client/key.rb', line 143

def update_public_key(path, key, options = {})
  key_check(path, 'public', options)
  create_or_update_key(path, key, 'public', 'put', options)
end