Sha256: 41599f960dde7d41cbb03800e4bb2d676c052d424b42758bcfc13af5564bce82

Contents?: true

Size: 772 Bytes

Versions: 11

Compression:

Stored size: 772 Bytes

Contents

module Kontena
  module Machine
    module DigitalOcean
      class SshKeyManager

        attr_reader :client

        # @param [String] token Digital Ocean API token
        def initialize(token)
          @client = DropletKit::Client.new(access_token: token)
        end

        def find_by_public_key(public_key)
          list.find { |key| key.public_key == public_key }
        end

        def list
          client.ssh_keys.all.to_a
        end

        def create(public_key)
          client.ssh_keys.create(DropletKit::SSHKey.new(public_key: public_key, name: public_key.split(/\s+/).last))
        end

        def find_or_create_by_public_key(public_key)
          find_by_public_key(public_key) || create(public_key)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
krates-plugin-digitalocean-0.3.11 lib/kontena/machine/digital_ocean/ssh_key_manager.rb
krates-plugin-digitalocean-0.3.10 lib/kontena/machine/digital_ocean/ssh_key_manager.rb
krates-plugin-digitalocean-0.3.9 lib/kontena/machine/digital_ocean/ssh_key_manager.rb
krates-plugin-digitalocean-0.3.8 lib/kontena/machine/digital_ocean/ssh_key_manager.rb
staticpages-plugin-digitalocean-0.3.7 lib/kontena/machine/digital_ocean/ssh_key_manager.rb
staticpages-plugin-digitalocean-0.3.6 lib/kontena/machine/digital_ocean/ssh_key_manager.rb
staticpages-plugin-digitalocean-0.3.5 lib/kontena/machine/digital_ocean/ssh_key_manager.rb
kontena-plugin-digitalocean-0.3.3 lib/kontena/machine/digital_ocean/ssh_key_manager.rb
kontena-plugin-digitalocean-0.3.2 lib/kontena/machine/digital_ocean/ssh_key_manager.rb
kontena-plugin-digitalocean-0.3.1 lib/kontena/machine/digital_ocean/ssh_key_manager.rb
kontena-plugin-digitalocean-0.3.1.rc1 lib/kontena/machine/digital_ocean/ssh_key_manager.rb