Sha256: fcf7aec75957db8a0ff97d2c890273fd812173070e37586f4c9378c5836fbe9e

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

# 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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
meroku-2.0.31 lib/meroku/key.rb
meroku-2.0.30 lib/meroku/key.rb
meroku-2.0.29 lib/meroku/key.rb
meroku-2.0.28 lib/meroku/key.rb
meroku-2.0.27 lib/meroku/key.rb
meroku-2.0.26 lib/meroku/key.rb
meroku-2.0.25 lib/meroku/key.rb