capistrano-demand_forward_agent 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b77ebfb30a2d0a46fcd407be9eb48c7d48556180
4
+ data.tar.gz: 36267a8cd039ff4761dc43e410b4e06bfdf677b7
5
+ SHA512:
6
+ metadata.gz: 03eeb58af6a2e3e2bf79e11329f20089827ef16af9a3e5f6e4278f52d890b3322107cd715b1b620a62b4e9b9946d9543e4eeb1f738a87abc7887047326d5a83a
7
+ data.tar.gz: d97e8ce569f1a4ae6263b79df84e933e353c215364d27cd4b4cf5b4c76a30ffc28ef0cf57755255297e0dc62f24134007452099bbb09b01ff0f4bf8dd2741d88
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-demand_forward_agent.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Takeru Naito
2
+
3
+ MIT 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.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ Capistrano::DemandForwardAgent
2
+ ==============================
3
+
4
+ Demand forward-agent on deploying.
5
+
6
+ - Confirming agent connection.
7
+ - Confirming identity status.
8
+
9
+ Unless satisfied then raise exception.
10
+
11
+
12
+ Installation
13
+ ------------
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'capistrano-demand_forward_agent',
18
+ git: 'git@github.com:elim/capistrano-demand_forward_agent.git'
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install capistrano-demand_forward_agent
27
+
28
+
29
+ Usage
30
+ -----
31
+
32
+ Put the following to your `deploy.rb`.
33
+
34
+ require 'capistrano-demand_forward_agent'
35
+
36
+ demand_forward_agent.confirm
37
+
38
+
39
+ Contributing
40
+ ------------
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/demand_forward_agent/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'capistrano-demand_forward_agent'
8
+ spec.version = Capistrano::DemandForwardAgent::VERSION
9
+ spec.authors = ['Takeru Naito']
10
+ spec.email = ['takeru.naito@gmail.com']
11
+ spec.description = %q{Demand SSH forward agent on capistrano.}
12
+ spec.summary = spec.description
13
+ spec.homepage = 'https://github.com/elim/capistrano-demand_forward_agent'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'capistrano'
25
+ spec.add_development_dependency 'net-ssh'
26
+ end
@@ -0,0 +1,45 @@
1
+ require 'capistrano/demand_forward_agent/version'
2
+ require 'capistrano'
3
+ require 'net/ssh'
4
+
5
+ module Capistrano
6
+ module DemandForwardAgent
7
+ extend self
8
+ include Net::SSH::Authentication
9
+
10
+ SSHAgentError = Class.new Capistrano::Error
11
+ SSHIdentityError = Class.new Capistrano::Error
12
+
13
+ def confirm
14
+ set_ssh_option
15
+ agent = connect_agent
16
+ confirm_identity agent
17
+ end
18
+
19
+ def set_ssh_option
20
+ ssh_options[:forward_agent] = true
21
+ end
22
+
23
+ def connect_agent
24
+ begin
25
+ agent = Agent.connect
26
+ rescue AgentNotAvailable
27
+ raise SSHAgentError.new 'Please run the `eval $(ssh-agent)` first.'
28
+ end
29
+
30
+ agent
31
+ end
32
+
33
+ def confirm_identity agent
34
+ if agent.identities.length == 0
35
+ raise SSHIdentityError.new 'Please run the `ssh-add` first.'
36
+ end
37
+
38
+ true
39
+ end
40
+
41
+ end
42
+ end
43
+
44
+ Capistrano.plugin :demand_forward_agent, Capistrano::DemandForwardAgent
45
+
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module DemandForwardAgent
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,123 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'capistrano'
4
+ require 'capistrano/ssh'
5
+
6
+ describe Capistrano::DemandForwardAgent do
7
+
8
+ before :all do
9
+ class Container
10
+ include Capistrano::DemandForwardAgent
11
+ attr_accessor :ssh_options
12
+
13
+ def initialize
14
+ @ssh_options = {}
15
+ end
16
+ end
17
+
18
+ @container = Container.new
19
+ end
20
+
21
+ before do
22
+ Net::SSH::Authentication::Agent.stub(:connect) do
23
+ Net::SSH::Authentication::Agent.new
24
+ end
25
+
26
+ Net::SSH::Authentication::Agent.any_instance.stub(:identities) do
27
+ [1]
28
+ end
29
+ end
30
+
31
+ describe 'version number' do
32
+ it do
33
+ Capistrano::DemandForwardAgent::VERSION.should_not be_nil
34
+ end
35
+ end
36
+
37
+ describe '#confirm' do
38
+ it do
39
+ @container.should_receive(:set_ssh_option).once
40
+ @container.should_receive(:connect_agent).once
41
+ @container.should_receive(:confirm_identity).once
42
+ @container.confirm
43
+ end
44
+ end
45
+
46
+ describe '#set_ssh_option' do
47
+ context 'ssh_options[:forward_agent] = true' do
48
+ before do
49
+ @container.ssh_options[:forward_agent] = true
50
+ end
51
+
52
+ it do
53
+ expect(@container.set_ssh_option).to be_true
54
+ end
55
+ end
56
+
57
+ context 'ssh_options[:forward_agent] = false' do
58
+ before do
59
+ @container.ssh_options[:forward_agent] = false
60
+ end
61
+
62
+ it do
63
+ expect(@container.set_ssh_option).to be_true
64
+ end
65
+ end
66
+
67
+ context 'unset ssh_options[:forward_agent]' do
68
+ it do
69
+ expect(@container.set_ssh_option).to be_true
70
+ end
71
+ end
72
+ end
73
+
74
+ describe '#connect_agent' do
75
+ context 'when ssh-agent running' do
76
+ it do
77
+ expect(@container.connect_agent).to be_instance_of Net::SSH::Authentication::Agent
78
+ end
79
+ end
80
+
81
+ context 'when ssh-agent is stopped' do
82
+ before do
83
+ Net::SSH::Authentication::Agent.stub(:connect) do
84
+ raise Net::SSH::Authentication::AgentNotAvailable
85
+ end
86
+ end
87
+
88
+ it do
89
+ expect do
90
+ @container.connect_agent
91
+ end.to raise_error Capistrano::DemandForwardAgent::SSHAgentError
92
+ end
93
+ end
94
+ end
95
+
96
+ describe '#confirm_identity' do
97
+ context 'when there is one identify' do
98
+ before do
99
+ @agent = @container.connect_agent
100
+ Net::SSH::Authentication::Agent.any_instance.stub(:identities) do
101
+ [1]
102
+ end
103
+ end
104
+
105
+ it do
106
+ expect(@container.confirm_identity(@agent)).to be_true
107
+ end
108
+ end
109
+
110
+ context 'when there is no identify' do
111
+ before do
112
+ @agent = @container.connect_agent
113
+ Net::SSH::Authentication::Agent.any_instance.stub(:identities) do
114
+ []
115
+ end
116
+ end
117
+
118
+ it do
119
+ expect {@container.confirm_identity(@agent)}.to raise_error Capistrano::DemandForwardAgent::SSHIdentityError
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'capistrano/demand_forward_agent'
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-demand_forward_agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Takeru Naito
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-30 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: capistrano
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: net-ssh
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Demand SSH forward agent on capistrano.
84
+ email:
85
+ - takeru.naito@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - capistrano-demand_forward_agent.gemspec
98
+ - lib/capistrano/demand_forward_agent.rb
99
+ - lib/capistrano/demand_forward_agent/version.rb
100
+ - spec/capistrano/demand_forward_agent_spec.rb
101
+ - spec/spec_helper.rb
102
+ homepage: https://github.com/elim/capistrano-demand_forward_agent
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.0.2
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Demand SSH forward agent on capistrano.
126
+ test_files:
127
+ - spec/capistrano/demand_forward_agent_spec.rb
128
+ - spec/spec_helper.rb