Sha256: a8937520098362bef8becbcf53b46238bdb9dc484d1a317f3ca749e38d690428

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

module Devkit
  module SshIdentity
    class << self
      def choose(identity)
        ssh_identity = File.join("~/.ssh/", identity['SSH Identity'])
        print "Switching ssh identity to #{File.expand_path(ssh_identity)}, "
        $stdout.flush

        if File.exists?(File.expand_path(ssh_identity))
          system("ssh-add -D")
          system("ssh-add #{ssh_identity}")
        else
          puts "#{identity["Full Name"]}'s ssh keys not found. Skipping identity switch.".red
        end

        check(identity)
      end

      def check(identity)
        ssh_identity = File.join("~/.ssh/", identity['SSH Identity'])
        ssh_identities = %x[ssh-add -l].split("\n")

        print "Checking identity, ".blue

        $stdout.flush

        if ssh_identities.length > 1
          puts "Possible amibiguity. Please double check your identity".red
        else
          puts "Using ssh identity #{File.expand_path(ssh_identity)}".green
        end
      end

      def status
        ssh_identities = %x[ssh-add -l].split("\n")
        puts ssh_identities
      end

      def drop
        system("ssh-add -D")

        ssh_identities = %x[ssh-add -l].split("\n")

        if ssh_identities.length > 1
          puts "Problem releasing existing identities. Possible amibiguity.".red
        else
          puts "Successfully dropped all the identities".green
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
windows-pr-1.2.5 vendor/bundle/ruby/2.2.0/gems/win32-api-1.6.0-universal-mingw32/vendor/bundle/ruby/2.2.0/gems/devkit-0.1.0/lib/devkit/ssh_identity.rb
win32-api-1.6.0-universal-mingw32 vendor/bundle/ruby/2.2.0/gems/devkit-0.1.0/lib/devkit/ssh_identity.rb
devkit-0.1.0 lib/devkit/ssh_identity.rb