vagrant-auto_ssh_config 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dcf69bf199e29c814c44b69f2da894cf794eec2e
4
+ data.tar.gz: 7bd922aecbbfb2a912b3ac18672ee74ada75dde6
5
+ SHA512:
6
+ metadata.gz: 7c4d4554a2112a7601e53139ac7b1634b546f5832f9bbb84e7baf7205f108142b76f0f55c11e6ff19bf1631dbb97a972942de9cbc4adff31434f114122aad10f
7
+ data.tar.gz: 50bcca1794934b37d03f11527118518b5330826271032bc4abd2a65394ad5451d88fdb947310b305b00ebe2add2a9441998cac76c3304be57a375045dc97a9d0
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ /.vagrant
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "vagrant", github: "mitchellh/vagrant"
7
+ end
8
+
9
+ group :plugins do
10
+ gem "vagrant-auto_ssh_config", path: "."
11
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yuya.Nishida.
2
+
3
+ X11 License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # vagrant-auto_ssh_config
2
+
3
+ A vagrant plugin for automatically generating ssh_config entry.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ $ vagrant plugin install vagrant-auto_ssh_config
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ After plugin installed and run "vagrant up", you can login vagrant machine by "ssh vagrant-latest" without "vagrant ssh-config --host vagrant-latest >> ~/.ssh/config".
14
+
15
+ This plugin creates/updates ssh_config entry at "vagrant up". And it deletes ssh_config entry for "vagrant-latest" at "vagrant halt".
16
+
17
+ ## Development
18
+
19
+ ### Test on Vagrant machine
20
+
21
+ 1. Install related gems: `bundle`
22
+ 2. Run Vagrant machine: `bundle exec vagrant up`
23
+
24
+ ### Install from source
25
+
26
+ 1. Create a gem: `bundle exec rake build`
27
+ 2. Install built gem: `vagrant plugin install pkg/vagrant-auto_ssh_config-VERSION.gem`
28
+
29
+ ### Contributing
30
+
31
+ 1. Fork it ( https://github.com/nishidayuya/vagrant-auto_ssh_config/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,6 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure(2) do |config|
5
+ config.vm.box = "ubuntu/trusty64"
6
+ end
@@ -0,0 +1,3 @@
1
+ require "vagrant"
2
+ require "vagrant/auto_ssh_config/version"
3
+ require "vagrant/auto_ssh_config/plugin"
@@ -0,0 +1,76 @@
1
+ require "open3"
2
+
3
+ module Vagrant
4
+ module AutoSshConfig
5
+ module Action
6
+ class Base
7
+ def initialize(app, env, options = {})
8
+ @app = app
9
+ @options = options
10
+ end
11
+
12
+ def call(env)
13
+ @app.call(env)
14
+ run(env)
15
+ end
16
+
17
+ def run(env)
18
+ env[:ui].info("#{doing_prefix} ssh_config for current box...")
19
+
20
+ SSH_CONFIG_PATH.open(File::RDWR | File::CREAT) do |f|
21
+ f.flock(File::LOCK_EX)
22
+ old_ssh_config = f.read
23
+ ssh_config_without_myself =
24
+ old_ssh_config.gsub(TEMPLATE_REGEXP, "").
25
+ sub(/\n?\n?\z/, "")
26
+ new_ssh_config = create_new_ssh_config(ssh_config_without_myself)
27
+ if old_ssh_config == new_ssh_config
28
+ env[:ui].info("not changed.")
29
+ return
30
+ end
31
+ begin
32
+ f.rewind
33
+ f.puts(new_ssh_config)
34
+ rescue
35
+ f.rewind
36
+ f.write(old_ssh_config)
37
+ raise
38
+ ensure
39
+ f.flush
40
+ f.truncate(f.pos)
41
+ end
42
+ end
43
+ env[:ui].detail("#{done_prefix} ssh_config for current box.")
44
+ end
45
+
46
+ private
47
+
48
+ SSH_CONFIG_PATH = Pathname("~/.ssh/config").expand_path
49
+ SSH_CONFIG_TEMPLATE = <<EOS.chomp.freeze
50
+ # BEGIN vagrant-auto_ssh_config
51
+ # These are automatically generated configurations by vagrant-auto_ssh_config.
52
+
53
+ %{configurations}
54
+
55
+ # END vagrant-auto_ssh_config
56
+ EOS
57
+ ary = SSH_CONFIG_TEMPLATE.split("\n")
58
+ begin_mark = ary.first
59
+ end_mark = ary.last
60
+ TEMPLATE_REGEXP = /#{begin_mark}.*?#{end_mark}\n/m
61
+
62
+ def doing_prefix
63
+ raise NotImplementedError, "Subclass must implement."
64
+ end
65
+
66
+ def done_prefix
67
+ raise NotImplementedError, "Subclass must implement."
68
+ end
69
+
70
+ def create_new_ssh_config(ssh_config_without_myself)
71
+ raise NotImplementedError, "Subclass must implement."
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,31 @@
1
+ require_relative "base"
2
+
3
+ module Vagrant
4
+ module AutoSshConfig
5
+ module Action
6
+ class CreateOrUpdate < Base
7
+ private
8
+
9
+ def doing_prefix
10
+ return "Creating/Updating"
11
+ end
12
+
13
+ def done_prefix
14
+ return "Created/Updated"
15
+ end
16
+
17
+ def create_new_ssh_config(ssh_config_without_myself)
18
+ # dirty hack
19
+ config = `vagrant ssh-config --host vagrant-latest`
20
+ config = config[/^Host .*LogLevel FATAL\n/m].strip
21
+ additionals = SSH_CONFIG_TEMPLATE % {configurations: config}
22
+ return <<EOS
23
+ #{ssh_config_without_myself}
24
+
25
+ #{additionals}
26
+ EOS
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ require_relative "base"
2
+
3
+ module Vagrant
4
+ module AutoSshConfig
5
+ module Action
6
+ class Delete < Base
7
+ private
8
+
9
+ def doing_prefix
10
+ return "Deleting"
11
+ end
12
+
13
+ def done_prefix
14
+ return "Deleted"
15
+ end
16
+
17
+ def create_new_ssh_config(ssh_config_without_myself)
18
+ return ssh_config_without_myself
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ module Vagrant
2
+ module AutoSshConfig
3
+ class Plugin < Vagrant.plugin("2")
4
+ name "vagrant-auto_ssh_config"
5
+
6
+ action_hook("vagrant-auto_ssh_config: update") do |hook|
7
+ require_relative "action/create_or_update"
8
+ hook.before(Vagrant::Action::Builtin::WaitForCommunicator,
9
+ Action::CreateOrUpdate)
10
+ end
11
+
12
+ action_hook("vagrant-auto_ssh_config: delete") do |hook|
13
+ require_relative "action/delete"
14
+ hook.before(Vagrant::Action::Builtin::GracefulHalt, Action::Delete)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module AutoSshConfig
3
+ VERSION = "0.0.0"
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant/auto_ssh_config/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-auto_ssh_config"
8
+ spec.version = Vagrant::AutoSshConfig::VERSION
9
+ spec.authors = ["Yuya.Nishida."]
10
+ spec.email = ["yuya@j96.org"]
11
+ spec.summary = "A vagrant plugin for automatically generating ssh_config entry."
12
+ spec.homepage = "https://github.com/nishidayuya/vagrant-auto_ssh_config"
13
+ spec.license = "X11"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-auto_ssh_config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuya.Nishida.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - yuya@j96.org
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - Vagrantfile
54
+ - lib/vagrant/auto_ssh_config.rb
55
+ - lib/vagrant/auto_ssh_config/action/base.rb
56
+ - lib/vagrant/auto_ssh_config/action/create_or_update.rb
57
+ - lib/vagrant/auto_ssh_config/action/delete.rb
58
+ - lib/vagrant/auto_ssh_config/plugin.rb
59
+ - lib/vagrant/auto_ssh_config/version.rb
60
+ - vagrant-auto_ssh_config.gemspec
61
+ homepage: https://github.com/nishidayuya/vagrant-auto_ssh_config
62
+ licenses:
63
+ - X11
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: A vagrant plugin for automatically generating ssh_config entry.
85
+ test_files: []