# frozen_string_literal: true module Meroku # Logic related to Ssh keys # eg. Uploading of users public key module Key extend Meroku::ResponseHandler extend Meroku::User def self.list result = RestClient.get 'https://www.meroku.com/keys.json', params: { 'token' => saved_token }, content_type: :json process_error(result) process_success(result) do JSON.parse(result).dig('data', 'keys_ids').each do |k| puts "Key id: #{k}" end end end def self.upload data = { 'token' => saved_token, 'key_name' => 'id_rsa.pub', 'key_data' => IO.read(Dir.home + '/.ssh/id_rsa.pub') }.to_json result = RestClient.post 'https://www.meroku.com/keys.json', data, content_type: :json process_error(result) process_success(result) { true } end def self.remove(key_id) data = { 'id' => key_id, 'token' => saved_token } result = RestClient::Request.execute( method: :delete, url: 'https://www.meroku.com/keys.json', headers: { params: data } ) process_error(result) process_success(result) end end end