Module: Cult::LinodeMonkeyPatch

Defined in:
lib/cult/drivers/linode_driver.rb

Overview

This has been submitted as a PR. It lets us set a label and custom expiration length for an API key.

See: https://github.com/rick/linode/pull/34

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.install!Object



37
38
39
# File 'lib/cult/drivers/linode_driver.rb', line 37

def install!
  ::Linode.prepend(self)
end

Instance Method Details

#fetch_api_key(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cult/drivers/linode_driver.rb', line 9

def fetch_api_key(options = {})
  request = {
    api_action: 'user.getapikey',
    api_responseFormat: 'json',
    username: username,
    password: password
  }

  if options.key?(:label)
    request[:label] = options[:label]
  end

  if options.key?(:expires)
    expires = options[:expires]
    request[:expires] = expires.nil? ? 0 : expires
  end

  response = post(request)
  if error?(response)
    fail "Errors completing request [user.getapikey] @ [#{api_url}] for " +
         "username [#{username}]:\n" +
         "#{error_message(response, 'user.getapikey')}"
  end
  reformat_response(response).api_key
end