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
-
#create_private_key(path, key, options = {}) ⇒ Rundeck::ObjectifiedHash
Create a private key.
-
#create_public_key(path, key, options = {}) ⇒ Rundeck::ObjectifiedHash
Create a public key.
-
#delete_key(path, options = {}) ⇒ nil
Delete a key.
-
#key_contents(path, options = {}) ⇒ Rundeck::ObjectifiedHash
Get the contents of a key.
-
#key_metadata(path, options = {}) ⇒ Rundeck::ObjectifiedHash
Get a single key’s metadata.
-
#keys(path = '', options = {}) ⇒ Array<Rundeck::ObjectifiedHash>
Gets a list of keys at a specific path.
-
#update_private_key(path, key, options = {}) ⇒ Rundeck::ObjectifiedHash
Update a private key.
-
#update_public_key(path, key, options = {}) ⇒ Rundeck::ObjectifiedHash
Update a public key.
Instance Method Details
#create_private_key(path, key, options = {}) ⇒ Rundeck::ObjectifiedHash
Create a private key
95 96 97 |
# File 'lib/rundeck/client/key.rb', line 95 def create_private_key(path, key, = {}) create_or_update_key(path, key, 'private', 'post', ) end |
#create_public_key(path, key, options = {}) ⇒ Rundeck::ObjectifiedHash
Create a public key
127 128 129 |
# File 'lib/rundeck/client/key.rb', line 127 def create_public_key(path, key, = {}) create_or_update_key(path, key, 'public', 'post', ) end |
#delete_key(path, options = {}) ⇒ nil
Delete a key
157 158 159 |
# File 'lib/rundeck/client/key.rb', line 157 def delete_key(path, = {}) delete("#{STORAGE_KEYS_PATH}/#{path}", ) 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.
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, = {}) # 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, ).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 .merge!(format: :plain, headers: { 'Accept' => 'application/pgp-keys' }) key = get("#{STORAGE_KEYS_PATH}/#{path}", ) objectify 'public_key' => key end |
#key_metadata(path, options = {}) ⇒ Rundeck::ObjectifiedHash
Get a single key’s metadata
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rundeck/client/key.rb', line 44 def (path, = {}) r = get("#{STORAGE_KEYS_PATH}/#{path}", ) # 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.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rundeck/client/key.rb', line 20 def keys(path = '', = {}) r = get("#{STORAGE_KEYS_PATH}/#{path}", ) # 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
111 112 113 114 |
# File 'lib/rundeck/client/key.rb', line 111 def update_private_key(path, key, = {}) key_check(path, 'private', ) create_or_update_key(path, key, 'private', 'put', ) end |
#update_public_key(path, key, options = {}) ⇒ Rundeck::ObjectifiedHash
Update a public key
143 144 145 146 |
# File 'lib/rundeck/client/key.rb', line 143 def update_public_key(path, key, = {}) key_check(path, 'public', ) create_or_update_key(path, key, 'public', 'put', ) end |