capistrano-ssh-helpers 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ gem 'capistrano'
4
+
5
+ # Add dependencies to develop your gem here.
6
+ # Include everything needed to run rake, tests, features, etc.
7
+ group :development do
8
+ gem "rdoc", "~> 3.12"
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.8.3"
11
+ end
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ capistrano (2.12.0)
5
+ highline
6
+ net-scp (>= 1.0.0)
7
+ net-sftp (>= 2.0.0)
8
+ net-ssh (>= 2.0.14)
9
+ net-ssh-gateway (>= 1.1.0)
10
+ git (1.2.5)
11
+ highline (1.6.12)
12
+ jeweler (1.8.3)
13
+ bundler (~> 1.0)
14
+ git (>= 1.2.5)
15
+ rake
16
+ rdoc
17
+ json (1.7.3)
18
+ net-scp (1.0.4)
19
+ net-ssh (>= 1.99.1)
20
+ net-sftp (2.0.5)
21
+ net-ssh (>= 2.0.9)
22
+ net-ssh (2.5.2)
23
+ net-ssh-gateway (1.1.0)
24
+ net-ssh (>= 1.99.1)
25
+ rake (0.9.2.2)
26
+ rdoc (3.12)
27
+ json (~> 1.4)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.0.0)
34
+ capistrano
35
+ jeweler (~> 1.8.3)
36
+ rdoc (~> 3.12)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Huiming Teo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ = capistrano-ssh-helpers
2
+
3
+ Provides a set of helper tasks related to SSH.
4
+
5
+ == Install
6
+ gem install 'capistrano-ssh-helpers'
7
+
8
+ For bundler, add it into your Gemfile
9
+
10
+ gem 'capistrano-ssh-helpers'
11
+
12
+ == Usage
13
+ You can include all helpers in config/deploy.rb:
14
+
15
+ require 'capistrnao-ssh-helpers' # includes all helper tasks
16
+
17
+ Or only include a specific helper:
18
+
19
+ require 'capistrano-ssh-helpers/git_host'
20
+
21
+ == Helpers
22
+
23
+ === git_host
24
+
25
+ Add a check to ensure Git SSH host is verified on remote server.
26
+
27
+ The check is added to deploy:check, when :scm is set to :git and
28
+ :repository looks like a ssh path/url.
29
+
30
+
31
+ === forward_agent
32
+
33
+ Add a check to ensure local SSH agent has identity key.
34
+
35
+ The check is added to deploy:check when ssh_options[:forward_agent]
36
+ is enabled.
37
+
38
+
39
+ == Contributing to capistrano-ssh-helpers
40
+
41
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
42
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
43
+ * Fork the project.
44
+ * Start a feature/bugfix branch.
45
+ * Commit and push until you are happy with your contribution.
46
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
47
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
48
+
49
+ == Copyright
50
+
51
+ Copyright (c) 2012 Huiming Teo. See LICENSE.txt for
52
+ further details.
53
+
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "capistrano-ssh-helpers"
18
+ gem.homepage = "http://github.com/teohm/capistrano-ssh-helpers"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Capistrano helper tasks related to SSH.}
21
+ gem.description = %Q{Capistrano helper tasks related to SSH.}
22
+ gem.email = "teohuiming@gmail.com"
23
+ gem.authors = ["Huiming Teo"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ task :default => :test
29
+
30
+ require 'rdoc/task'
31
+ Rake::RDocTask.new do |rdoc|
32
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
33
+
34
+ rdoc.rdoc_dir = 'rdoc'
35
+ rdoc.title = "capistrano-ssh-helpers #{version}"
36
+ rdoc.rdoc_files.include('README*')
37
+ rdoc.rdoc_files.include('lib/**/*.rb')
38
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "capistrano-ssh-helpers"
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Huiming Teo"]
12
+ s.date = "2012-06-05"
13
+ s.description = "Capistrano helper tasks related to SSH."
14
+ s.email = "teohuiming@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "capistrano-ssh-helpers.gemspec",
28
+ "lib/capistrano-ssh-helpers.rb",
29
+ "lib/capistrano-ssh-helpers/ext/local_dependency.rb",
30
+ "lib/capistrano-ssh-helpers/ext/remote_dependency.rb",
31
+ "lib/capistrano-ssh-helpers/forward_agent.rb",
32
+ "lib/capistrano-ssh-helpers/git_host.rb"
33
+ ]
34
+ s.homepage = "http://github.com/teohm/capistrano-ssh-helpers"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.24"
38
+ s.summary = "Capistrano helper tasks related to SSH."
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<capistrano>, [">= 0"])
45
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
48
+ else
49
+ s.add_dependency(%q<capistrano>, [">= 0"])
50
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
51
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<capistrano>, [">= 0"])
56
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
59
+ end
60
+ end
61
+
@@ -0,0 +1,2 @@
1
+ require 'capistrano-ssh-helpers/forward_agent'
2
+ require 'capistrano-ssh-helpers/git_host'
@@ -0,0 +1,28 @@
1
+ require 'capistrano/recipes/deploy/local_dependency'
2
+
3
+ Capistrano::Deploy::LocalDependency.class_eval do
4
+
5
+ # Run a command and check the output.
6
+ def run_cmd(command, expect, match_is_success=true, message=nil)
7
+ expect = Regexp.new(Regexp.escape(expect.to_s)) unless expect.is_a?(Regexp)
8
+
9
+ @configuration.logger.debug "executing \"#{command}\""
10
+ output = `#{command} 2>&1`
11
+ @configuration.logger.trace "[local] #{output}"
12
+
13
+ is_matched = output =~ expect
14
+
15
+ @success = if match_is_success
16
+ is_matched ? true : false
17
+ else
18
+ is_matched ? false : true
19
+ end
20
+
21
+ unless @success
22
+ @message = "#{message} (local)"
23
+ end
24
+ self
25
+ end
26
+
27
+ end
28
+
@@ -0,0 +1,39 @@
1
+ require 'capistrano/recipes/deploy/remote_dependency'
2
+
3
+ Capistrano::Deploy::RemoteDependency.class_eval do
4
+ def run_cmd(command, expect, match_is_success=true, message=nil, options={})
5
+ expect = Regexp.new(Regexp.escape(expect.to_s)) unless expect.is_a?(Regexp)
6
+
7
+ output_per_server = {}
8
+ try("#{command} ", options) do |ch, stream, out|
9
+ output_per_server[ch[:server]] ||= ''
10
+ output_per_server[ch[:server]] += out
11
+ end
12
+
13
+ # It is possible for some of these commands to return a status != 0
14
+ # (for example, rake --version exits with a 1). For this check we
15
+ # just care if the output matches, so we reset the success flag.
16
+ @success = true
17
+
18
+ errored_hosts = []
19
+ output_per_server.each_pair do |server, output|
20
+ if match_is_success
21
+ next if output =~ expect
22
+ else
23
+ next unless output =~ expect
24
+ end
25
+ errored_hosts << server
26
+ end
27
+
28
+ if errored_hosts.any?
29
+ @hosts = errored_hosts.join(', ')
30
+ output = output_per_server[errored_hosts.first]
31
+ default_message = "the output #{output.inspect} from #{command.inspect} did not match #{expect.inspect}"
32
+ @message = message || default_message
33
+ @success = false
34
+ end
35
+
36
+ self
37
+ end
38
+ end
39
+
@@ -0,0 +1,30 @@
1
+ unless Capistrano::Configuration.respond_to?(:instance)
2
+ abort "capistrano-checks requires Capistrano 2"
3
+ end
4
+
5
+ require 'capistrano-ssh-helpers/ext/local_dependency'
6
+
7
+ Capistrano::Configuration.instance.load do
8
+ namespace :deploy do
9
+ namespace :forward_agent do
10
+
11
+ desc <<-DESC
12
+ Add check to ensure local SSH agent has identity key.
13
+
14
+ The check is added to deploy:check, when ssh_options[:forward_agent]
15
+ is set to true.
16
+ DESC
17
+ task :check do
18
+ if ssh_options[:forward_agent]
19
+ depend :local, :run_cmd, 'ssh-add -l',
20
+ /no identities/, false,
21
+ "Local SSH agent has no key. To add key: 'ssh-add -K' or 'ssh-add -K private_key_file'"
22
+ end
23
+ end #task
24
+
25
+ end
26
+ end
27
+
28
+ before 'deploy:check', 'deploy:forward_agent:check'
29
+
30
+ end
@@ -0,0 +1,41 @@
1
+ unless Capistrano::Configuration.respond_to?(:instance)
2
+ abort "capistrano-checks requires Capistrano 2"
3
+ end
4
+
5
+ require 'capistrano-ssh-helpers/ext/remote_dependency'
6
+
7
+ Capistrano::Configuration.instance.load do
8
+ namespace :deploy do
9
+ namespace :git_host do
10
+
11
+ desc <<-DESC
12
+ Add check to ensure Git SSH host is verified on remote server.
13
+
14
+ The check is added to deploy:check, when :scm is set to :git
15
+ and :repository looks like a ssh path/url.
16
+ DESC
17
+ task :check do
18
+ return unless scm == :git
19
+
20
+ LIKE_SSH_HOST = /^([^@]+@[^:]+):.*$/
21
+ LIKE_SSH_URL = %r[^(ssh://[^/]+).*$]
22
+
23
+ repo_url = fetch(:repository, '')
24
+ ssh_host = if repo_url =~ LIKE_SSH_HOST
25
+ $1
26
+ elsif repo_url =~ LIKE_SSH_URL
27
+ $1
28
+ end
29
+
30
+ if ssh_host
31
+ depend :remote, :run_cmd, "ssh #{ssh_host}",
32
+ /Host key verification failed/, false,
33
+ "Git SSH host is not verified. To verify as known host, run this on server: 'ssh #{ssh_host}'"
34
+ end
35
+ end # task
36
+
37
+ end
38
+ end
39
+
40
+ before 'deploy:check', 'deploy:git_host:check'
41
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-ssh-helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Huiming Teo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.12'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.12'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.0.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: jeweler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.3
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.8.3
78
+ description: Capistrano helper tasks related to SSH.
79
+ email: teohuiming@gmail.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files:
83
+ - LICENSE.txt
84
+ - README.rdoc
85
+ files:
86
+ - .document
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE.txt
90
+ - README.rdoc
91
+ - Rakefile
92
+ - VERSION
93
+ - capistrano-ssh-helpers.gemspec
94
+ - lib/capistrano-ssh-helpers.rb
95
+ - lib/capistrano-ssh-helpers/ext/local_dependency.rb
96
+ - lib/capistrano-ssh-helpers/ext/remote_dependency.rb
97
+ - lib/capistrano-ssh-helpers/forward_agent.rb
98
+ - lib/capistrano-ssh-helpers/git_host.rb
99
+ homepage: http://github.com/teohm/capistrano-ssh-helpers
100
+ licenses:
101
+ - MIT
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ segments:
113
+ - 0
114
+ hash: -3162970074738685013
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.24
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Capistrano helper tasks related to SSH.
127
+ test_files: []