vagrant-proxyssh 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Kenneth Vestergaard
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # `vagrant-proxyssh`
2
+
3
+ A small hack to enable ssh'ing to Vagrant VMs directly from the command-line.
4
+
5
+ My personal use-case is in system-level tests where `ssh` is used as a part of the program.
6
+ It's much easier just to have a test-specific hostname (`vagrant`), than having to write
7
+ special-cased code to do a `vagrant ssh`, or having to add a custom host to `~/.ssh/config`
8
+ for each Vagrant VM.
9
+
10
+
11
+ ## Requirements
12
+
13
+ Requires `nc` (netcat). It also currently only works when the Vagrant VMs have a standard
14
+ SSH-setup.
15
+
16
+
17
+ ## Installation
18
+
19
+ Either use `vagrant gem`, or add a `gem "vagrant-proxyssh"` to your `Gemfile`.
20
+
21
+ Before first use, you can run `vagrant proxy-ssh --setup` to add the necessary
22
+ configuration to `~/.ssh/config`.
23
+
24
+ The setup routine is hard-coded for `rbenv`, and assumes Vagrant is bundled with
25
+ each project. Simply modify the `ProxyCommand` line in `~/.ssh/config` if you use
26
+ a system-Ruby, or RVM, or have Vagrant installed as a system gem.
27
+
28
+
29
+ ## Usage
30
+
31
+ After installation and setup, you can `ssh vagrant` from your project directory,
32
+ and it'll work just like `vagrant ssh`.
@@ -0,0 +1,54 @@
1
+ require 'socket'
2
+
3
+ class Vagrant::Command::ProxySSH < Vagrant::Command::Base
4
+ def execute
5
+ options = {}
6
+
7
+ opts = OptionParser.new do |opt|
8
+ opt.banner = "Usage: <used by ssh>"
9
+ opt.separator "Helper used to create fake hostnames that proxy through to a VM"
10
+ opt.separator ""
11
+
12
+ opt.on("-s", "--setup", "Set up magic in ~/.ssh/config") do |o|
13
+ options[:setup] = o
14
+ end
15
+ end
16
+
17
+ argv = parse_options(opts)
18
+
19
+ return if argv[0].nil?
20
+
21
+ vmname = argv[0].sub(/^vagrant-?/, '')
22
+ vmname = nil if vmname == ""
23
+
24
+ with_target_vms(vmname, :single_target => true) do |vm|
25
+ raise Errors::VMNotCreatedError if !vm.created?
26
+ raise Errors::VMInaccessible if !vm.state == :inaccessible
27
+ raise Errors::VMNotRunningError if vm.state != :running
28
+
29
+ ssh_info = vm.ssh.info
30
+
31
+ if options[:setup]
32
+ File.open(File.expand_path("~/.ssh/config"), 'a') do |file|
33
+ file.puts
34
+ file.puts "Host vagrant*"
35
+ file.puts " ProxyCommand rbenv exec bundle exec vagrant proxy-ssh %h"
36
+ file.puts " User #{ssh_info[:username]}"
37
+ file.puts " UserKnownHostsFile /dev/null"
38
+ file.puts " StrictHostKeyChecking no"
39
+ file.puts " PasswordAuthentication no"
40
+ file.puts " IdentityFile #{ssh_info[:private_key_path]}"
41
+ file.puts " IdentitiesOnly yes"
42
+ end
43
+ else
44
+ raise Errors::SSHPortNotDetected if ssh_info[:port].nil?
45
+
46
+ connect_socket
47
+ forward_data
48
+
49
+ exec 'nc', '127.0.0.1', ssh_info[:port].to_s
50
+ end
51
+ end
52
+ end
53
+ end
54
+ Vagrant.commands.register(:"proxy-ssh") { Vagrant::Command::ProxySSH }
@@ -0,0 +1,4 @@
1
+ # This file is automatically loaded by Vagrant to load any
2
+ # plugins. This file kicks off this plugin.
3
+
4
+ require 'vagrant-proxyssh'
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "vagrant-proxyssh"
5
+ s.version = "0.1.0"
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ["Kenneth Vestergaard"]
8
+ s.email = ["kvs@binarysolutions.dk"]
9
+ s.homepage = "https://github.com/kvs/vagrant-proxyssh"
10
+ s.summary = "A Vagrant plugin + ssh_config snippet for ssh'ing to a VM"
11
+ s.description = "Makes it possible to use 'ssh' to login to a Vagrant VM, without adding multiple fake hosts to ~/.ssh/config"
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
15
+ s.require_path = 'lib'
16
+
17
+ s.add_dependency "vagrant", ">= 1.0.0"
18
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-proxyssh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kenneth Vestergaard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: vagrant
16
+ requirement: &70295356937320 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70295356937320
25
+ description: Makes it possible to use 'ssh' to login to a Vagrant VM, without adding
26
+ multiple fake hosts to ~/.ssh/config
27
+ email:
28
+ - kvs@binarysolutions.dk
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - LICENSE
34
+ - README.md
35
+ - lib/vagrant-proxyssh.rb
36
+ - lib/vagrant_init.rb
37
+ - vagrant-proxyssh.gemspec
38
+ homepage: https://github.com/kvs/vagrant-proxyssh
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.11
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: A Vagrant plugin + ssh_config snippet for ssh'ing to a VM
62
+ test_files: []