class Api::Activation
This class executes an HTTP call to the API in billing, when the node is started for the first time. As a result of activation if receives an auth key, which is used for signing all subsequent API calls.
Constants
- PKI_PATH
Public Instance Methods
activate()
click to toggle source
# File lib/api/activation.rb, line 11 def activate return if active_node? if activated_successfully? save_auth_key else raise "Can't activate server at billing" end end
Private Instance Methods
action()
click to toggle source
# File lib/api/activation.rb, line 63 def action "activate" end
activated_successfully?()
click to toggle source
# File lib/api/activation.rb, line 23 def activated_successfully? success_api_call? end
active_node?()
click to toggle source
# File lib/api/activation.rb, line 27 def active_node? File.exist?(KEY_PATH) end
client_crt()
click to toggle source
# File lib/api/activation.rb, line 55 def client_crt read_pki('generic_client.crt') end
client_key()
click to toggle source
# File lib/api/activation.rb, line 59 def client_key read_pki('generic_client.key') end
data()
click to toggle source
# File lib/api/activation.rb, line 41 def data { signature: secret_token, hostname: hostname, server_crt: server_crt, client_crt: client_crt, client_key: client_key } end
read_pki(file)
click to toggle source
# File lib/api/activation.rb, line 71 def read_pki(file) File.read("#{PKI_PATH}/#{file}") end
save_auth_key()
click to toggle source
# File lib/api/activation.rb, line 31 def save_auth_key key = JSON.parse(api_call_result.body)["auth_key"] File.open('/etc/openvpn/auth_key', 'w') { |file| file.write(key) } end
secret_token()
click to toggle source
# File lib/api/activation.rb, line 67 def secret_token ENV['SECRET_TOKEN'] end
server_crt()
click to toggle source
# File lib/api/activation.rb, line 51 def server_crt read_pki('ca.crt') end
signed_data()
click to toggle source
# File lib/api/activation.rb, line 36 def signed_data # TODO: sign initial request with secret key data end