ssh-locate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :dev do
6
+ gem "guard"
7
+ gem "rb-inotify"
8
+ gem "libnotify"
9
+ gem "cucumber"
10
+ gem "aruba", git: "git@github.com:ameuret/aruba.git"
11
+ gem "guard-cucumber"
12
+ end
13
+
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+
2
+ guard 'cucumber' do
3
+ watch(%r{^features/.+\.feature$})
4
+ watch(%r{^features/support/.+$}) { 'features' }
5
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
6
+ end
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ ssh-locate
2
+ ==========
3
+
4
+ A command line tool that helps you locate and contact a SSH agent launched in a separate session.
5
+
6
+ Features
7
+ --------
8
+ - output is fully compatible with openSSH:
9
+
10
+ ```
11
+ SSH_AUTH_SOCK=/tmp/ssh-locate-test.15970; export SSH_AUTH_SOCK;
12
+ SSH_AGENT_PID=12427; export SSH_AGENT_PID;
13
+ echo Agent pid 12427;
14
+ ```
15
+
16
+ Installation
17
+ ------------
18
+
19
+ gem install ssh-locate
20
+
21
+ Usage
22
+ -----
23
+
24
+ Launch your SSH agent and tell it to use a specific socket file with the -a option:
25
+
26
+ ssh-agent -a /tmp/deployer-38us9f
27
+
28
+ In a later shell (or any process running for the user owning the agent):
29
+
30
+ $ eval ssh-locate
31
+ Agent pid 13457
32
+
33
+ Caveat
34
+ ------
35
+
36
+ `ssh-locate` only reports the first agent found in the process table. If you have a scenario where you would like to be more specific, let me known and I can extend the selectivity. I just do not need that right now.
37
+
38
+ TODO
39
+ ----
40
+ As the YAGNI wisdom tells us not to fantasize requirements, here are some potentially useful things that are not implemented yet:
41
+
42
+ - Be aware of the agent launched by Ubuntu
43
+ - Have a more sensible output if no agent was found
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/ssh-locate ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ module Net
3
+ module SSH
4
+ module Locate
5
+ LIB=File.dirname(__FILE__) + '/../lib'
6
+ end
7
+ end
8
+ end
9
+ $: << Net::SSH::Locate::LIB unless $:.include?(File.expand_path(Net::SSH::Locate::LIB))
10
+ require "thor"
11
+ require "net/ssh/locate"
12
+
13
+ begin
14
+ Net::SSH::Locate::App.start
15
+ rescue ArgumentError
16
+ exit
17
+ end
@@ -0,0 +1,45 @@
1
+ Feature: Agent IDs
2
+ In order to connect to remote services in a secure and efficient manner
3
+ As a modern sysadmin who values machine resources and human time
4
+ I want to connect to a single ssh agent, launched a long time ago in a shell far far away
5
+
6
+ Scenario: Locate a running agent
7
+ Given an ssh agent has been launched without parameters
8
+ When I run `ssh-locate`
9
+ Then the output should contain "SSH_AUTH_SOCK="
10
+ And the output should contain "export SSH_AUTH_SOCK;"
11
+ And the output should contain "SSH_AGENT_PID="
12
+ And the output should contain "export SSH_AGENT_PID;"
13
+ And the output should contain the correct agent PID
14
+ And the output should contain the correct agent socket
15
+
16
+ Scenario: No agent is running or localizable
17
+ Given no agent is running
18
+ When I run `ssh-locate`
19
+ Then the output should be empty
20
+
21
+ Scenario: Locate an agent that shows its socket
22
+ Given an ssh agent has been launched with a specific socket
23
+ When I run `ssh-locate`
24
+ Then the output should contain "SSH_AUTH_SOCK="
25
+ And the output should contain "export SSH_AUTH_SOCK;"
26
+ And the output should contain "SSH_AGENT_PID="
27
+ And the output should contain "export SSH_AGENT_PID;"
28
+ And the output should contain the correct agent PID
29
+ And the output should contain the correct agent socket
30
+
31
+ Scenario: Recognize and honor the agent managed by Ubuntu
32
+ Given an ssh agent has been launched in my Ubuntu session
33
+ When I run `ssh-locate`
34
+ Then the output should contain "SSH_AUTH_SOCK="
35
+ And the output should contain "export SSH_AUTH_SOCK;"
36
+ And the output should contain "SSH_AGENT_PID="
37
+ And the output should contain "export SSH_AGENT_PID;"
38
+ And the output should contain the correct agent PID
39
+ And the output should contain the correct agent socket
40
+
41
+ Scenario: Ignore agents run by someone else
42
+ Given an ssh agent is running for another user
43
+ And no ssh agent is running for me
44
+ When I run `ssh-locate`
45
+ Then the output should contain "no agent found"
@@ -0,0 +1,41 @@
1
+ Given /^an ssh agent has been launched without parameters$/ do
2
+ pending
3
+ end
4
+
5
+ Given /^an ssh agent has been launched with a specific socket$/ do
6
+ @agentIO = IO.popen('ssh-agent -a /tmp/ssh-locate-test.15970')
7
+ @agentOutput = @agentIO.read
8
+ @agentIO.close
9
+ @agentPID = @agentOutput[/PID=(\d+)/,1].to_i
10
+ @agentSocket = @agentOutput[/SOCK=([\w\-._\/]+)/,1]
11
+ # The agent is shutdown in the 'after' hook
12
+ end
13
+
14
+ Given /^an SSH agent has been launched in my Ubuntu session$/ do
15
+ pending
16
+ end
17
+
18
+ Given /^no agent is running$/ do
19
+ @agentPID=nil
20
+ @agentSocket=nil
21
+ end
22
+
23
+ Given /^an ssh agent is running for another user$/ do
24
+ pending # express the regexp above with the code you wish you had
25
+ end
26
+
27
+ Given /^no ssh agent is running for me$/ do
28
+ pending # express the regexp above with the code you wish you had
29
+ end
30
+
31
+ Then /^the output should be empty$/ do
32
+ assert_exact_output('', all_output)
33
+ end
34
+
35
+ Then /^the output should contain the correct agent PID$/ do
36
+ assert_partial_output( @agentPID.to_s, all_output )
37
+ end
38
+
39
+ Then /^the output should contain the correct agent socket$/ do
40
+ assert_partial_output( @agentSocket.to_s, all_output )
41
+ end
@@ -0,0 +1 @@
1
+ require "aruba/cucumber"
@@ -0,0 +1,12 @@
1
+ # This file contains Cucumber hooks.
2
+ # It gets required automatically by Cucumber just because it has a .rb
3
+ # extension and resides under features/
4
+
5
+ Before do
6
+ end
7
+
8
+ After do
9
+ if @agentIO
10
+ Process.kill("TERM", @agentPID)
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ module Net
2
+ module SSH
3
+ module Locate
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ require "net/ssh/locate/version"
2
+ require "thor/group"
3
+ require "sys/proctable"
4
+
5
+ module Net
6
+ module SSH
7
+ module Locate
8
+ class App < Thor::Group
9
+ include Thor::Actions
10
+
11
+ def locate_agent
12
+ procs=Sys::ProcTable.ps.select do
13
+ |p|
14
+ (p.cmdline =~ /ssh-agent/) && !(p.cmdline =~ /--session=ubuntu/) && !(p.state=='Z')
15
+ end
16
+ return if procs.empty?
17
+ p=procs.first
18
+ p.cmdline =~ /ssh-agent\s-a ([-.a-zA-Z0-9_\/]+)/
19
+ return if !$~
20
+ @agentSocket = $1
21
+ @agentPID = p.pid
22
+ end
23
+
24
+ def print_shell_commands
25
+ return if (!@agentPID || !@agentSocket)
26
+ print "SSH_AUTH_SOCK=#{@agentSocket}; "
27
+ puts "export SSH_AUTH_SOCK;"
28
+ print "SSH_AGENT_PID=#{@agentPID}; "
29
+ puts "export SSH_AGENT_PID;"
30
+ puts "echo Agent pid #{@agentPID};"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("lib", File.dirname(__FILE__))
3
+ require "net/ssh/locate/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ssh-locate"
7
+ s.version = Net::SSH::Locate::VERSION
8
+ s.authors = ["Arnaud Meuret"]
9
+ s.email = ["arnaud@meuret.name"]
10
+ s.homepage = ""
11
+ s.summary = %q{A tool (+ a Ruby lib) to locate a running SSH agent}
12
+ s.description = %q{A CLI tool and its associated Ruby library that help you locate and reconnect to a running SSH agent. Useful in automation scenarios where multiple processes must repeatedly open SSH connections leveraging a one-time authentication pass}
13
+
14
+ s.rubyforge_project = "ssh-locate"
15
+
16
+ s.add_dependency "sys-proctable"
17
+ s.add_dependency "thor"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ssh-locate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Arnaud Meuret
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-05 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sys-proctable
16
+ requirement: &75522350 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *75522350
25
+ - !ruby/object:Gem::Dependency
26
+ name: thor
27
+ requirement: &75521890 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *75521890
36
+ description: A CLI tool and its associated Ruby library that help you locate and reconnect
37
+ to a running SSH agent. Useful in automation scenarios where multiple processes
38
+ must repeatedly open SSH connections leveraging a one-time authentication pass
39
+ email:
40
+ - arnaud@meuret.name
41
+ executables:
42
+ - ssh-locate
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - .gitignore
47
+ - Gemfile
48
+ - Guardfile
49
+ - README.md
50
+ - Rakefile
51
+ - bin/ssh-locate
52
+ - features/agent-ids.feature
53
+ - features/step_definitions/agent-ids.rb
54
+ - features/support/env.rb
55
+ - features/support/hooks.rb
56
+ - lib/net/ssh/locate.rb
57
+ - lib/net/ssh/locate/version.rb
58
+ - ssh-locate.gemspec
59
+ homepage: ''
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project: ssh-locate
79
+ rubygems_version: 1.8.11
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: A tool (+ a Ruby lib) to locate a running SSH agent
83
+ test_files: []