net-ssh-local 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.circleci/config.yml +64 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/extensions/net/ssh/connection/session.rb +68 -0
- data/lib/extensions/net/ssh.rb +18 -0
- data/lib/net/ssh/local/version.rb +7 -0
- data/lib/net/ssh/local.rb +10 -0
- data/net-ssh-local.gemspec +29 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bf56178008f4dc111260ad9f4ce79645d2a95f2ced307d617242d7e7aadfa7c5
|
4
|
+
data.tar.gz: 43a4690de8e67a6ef867f1372b59d0b63c1262c375d3e97c277d3855b82a771f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57231738e2c313e4cffc8f14c00ec40a67a52ebb3f87740f0572dcf407fb4d1f7aac6aadf6c023029e679835b15ee4509169be0b71ebf4dbc58c9797cb16b06b
|
7
|
+
data.tar.gz: 2ac2aa63f390502a38da507694fbc98c2bbadb945ac360c76599b4f13fe2ff5dcd70aaa8b3b0d1cc8c6d5470b5ec84525dd3526a13dc1239e1f746307a6dda00
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
#
|
5
|
+
version: 2
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
docker:
|
9
|
+
# specify the version you desire here
|
10
|
+
- image: circleci/ruby:2.4.1-node-browsers
|
11
|
+
- image: circleci/ruby:2.5.3-node-browsers
|
12
|
+
|
13
|
+
# Specify service dependencies here if necessary
|
14
|
+
# CircleCI maintains a library of pre-built images
|
15
|
+
# documented at https://circleci.com/docs/2.0/circleci-images/
|
16
|
+
# - image: circleci/postgres:9.4
|
17
|
+
|
18
|
+
working_directory: ~/repo
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- checkout
|
22
|
+
|
23
|
+
# Download and cache dependencies
|
24
|
+
- restore_cache:
|
25
|
+
keys:
|
26
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
27
|
+
# fallback to using the latest cache if no exact match is found
|
28
|
+
- v1-dependencies-
|
29
|
+
|
30
|
+
- run:
|
31
|
+
name: install dependencies
|
32
|
+
command: |
|
33
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
34
|
+
|
35
|
+
- save_cache:
|
36
|
+
paths:
|
37
|
+
- ./vendor/bundle
|
38
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
39
|
+
|
40
|
+
# # Database setup
|
41
|
+
# - run: bundle exec rake db:create
|
42
|
+
# - run: bundle exec rake db:schema:load
|
43
|
+
|
44
|
+
# run tests!
|
45
|
+
- run:
|
46
|
+
name: run tests
|
47
|
+
command: |
|
48
|
+
mkdir /tmp/test-results
|
49
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
|
50
|
+
circleci tests split --split-by=timings)"
|
51
|
+
|
52
|
+
bundle exec rspec \
|
53
|
+
--format progress \
|
54
|
+
--format RspecJunitFormatter \
|
55
|
+
--out /tmp/test-results/rspec.xml \
|
56
|
+
--format progress \
|
57
|
+
$TEST_FILES
|
58
|
+
|
59
|
+
# collect reports
|
60
|
+
- store_test_results:
|
61
|
+
path: /tmp/test-results
|
62
|
+
- store_artifacts:
|
63
|
+
path: /tmp/test-results
|
64
|
+
destination: test-results
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Steve Lamotte
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Net::SSH::Local
|
2
|
+
[](https://circleci.com/gh/slamotte/net-ssh-local)
|
3
|
+
|
4
|
+
This gem is a Net::SSH plugin to streamline localhost deployment. It will streamline localhost operations when the hostname is "localhost" and the user is nil.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'net-ssh-local', require: false
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install net-ssh-local
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Require in whichever file(s) you'd like to optimize e.g. `Capfile`:
|
25
|
+
|
26
|
+
require 'net/ssh/local'
|
27
|
+
|
28
|
+
|
29
|
+
### Example
|
30
|
+
|
31
|
+
`config/deploy/staging_and_local.rb`
|
32
|
+
|
33
|
+
# typically server config is:
|
34
|
+
server 'my.remotehost.com', roles: %w{app web}, user: 'deploy', key: '/path/to/key.pem'
|
35
|
+
# localhost config is:
|
36
|
+
server 'localhost', roles: %w{app web} # no need to set SSH configs.
|
37
|
+
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/slamotte/net-ssh-local.
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "net/ssh/local"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
require 'net/ssh/connection/session'
|
3
|
+
|
4
|
+
module Extensions
|
5
|
+
module Net
|
6
|
+
module SSH
|
7
|
+
module Connection
|
8
|
+
module Session
|
9
|
+
def exec(command, status: nil, &block)
|
10
|
+
return super(command, status: status, &block) unless localhost?
|
11
|
+
|
12
|
+
result = exec_local_command(command)
|
13
|
+
|
14
|
+
# Return status if given
|
15
|
+
if status
|
16
|
+
status[:exit_code] = result[:code]
|
17
|
+
status[:exit_signal] = result[:signal]
|
18
|
+
end
|
19
|
+
|
20
|
+
# Process results
|
21
|
+
if result[:error].nil?
|
22
|
+
if block
|
23
|
+
block.call(nil, :stdout, result[:output])
|
24
|
+
else
|
25
|
+
$stdout.print(result[:output])
|
26
|
+
end
|
27
|
+
else
|
28
|
+
if block
|
29
|
+
block.call(nil, :stderr, result[:error])
|
30
|
+
else
|
31
|
+
$stderr.print(result[:error])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def send_data(data)
|
37
|
+
return super(data) unless localhost?
|
38
|
+
|
39
|
+
binding.pry
|
40
|
+
raise 'what do do here?'
|
41
|
+
# stdin << data # maybe??
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def localhost?
|
47
|
+
host == 'localhost' && options[:user].nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
def exec_local_command(command)
|
51
|
+
result = {}
|
52
|
+
begin
|
53
|
+
result[:output] = `#{command}`
|
54
|
+
rescue StandardError => e
|
55
|
+
result[:error] = e.message
|
56
|
+
ensure
|
57
|
+
result[:code] = $?.exitstatus
|
58
|
+
result[:signal] = $?.termsig
|
59
|
+
result
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
Net::SSH::Connection::Session.prepend(Extensions::Net::SSH::Connection::Session)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
|
3
|
+
module Net
|
4
|
+
module SSH #:nodoc:
|
5
|
+
SSH.singleton_class.send(:alias_method, :original_start, :start) # TODO: any way to use prepend instead?
|
6
|
+
|
7
|
+
# Custom behaviour for localhost with no user: nothing to log in with
|
8
|
+
def self.start(host, user=nil, options={}, &block)
|
9
|
+
return original_start(host, user, options, &block) unless host == 'localhost' && user.nil?
|
10
|
+
|
11
|
+
transport = Transport::Session.new(host, options)
|
12
|
+
connection = Connection::Session.new(transport, {})
|
13
|
+
return connection unless block_given?
|
14
|
+
|
15
|
+
yield connection
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'net/ssh/local/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "net-ssh-local"
|
8
|
+
spec.version = Net::SSH::Local::VERSION
|
9
|
+
spec.authors = ["Steve Lamotte"]
|
10
|
+
spec.email = ["steve@lexor.ca"]
|
11
|
+
|
12
|
+
spec.summary = %q{Net::SSH plugin to streamline localhost operations.}
|
13
|
+
spec.description = %q(net-ssh-local is a plugin to streamline localhost operations when the hostname is "localhost" and the user is nil.)
|
14
|
+
spec.homepage = "https://github.com/slamotte/net-ssh-local"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "net-ssh", "~> 5.2.0"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "rspec_junit_formatter"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: net-ssh-local
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Lamotte
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: net-ssh
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
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: pry
|
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: rake
|
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: rspec
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec_junit_formatter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: net-ssh-local is a plugin to streamline localhost operations when the
|
98
|
+
hostname is "localhost" and the user is nil.
|
99
|
+
email:
|
100
|
+
- steve@lexor.ca
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".circleci/config.yml"
|
106
|
+
- ".gitignore"
|
107
|
+
- ".rspec"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- lib/extensions/net/ssh.rb
|
115
|
+
- lib/extensions/net/ssh/connection/session.rb
|
116
|
+
- lib/net/ssh/local.rb
|
117
|
+
- lib/net/ssh/local/version.rb
|
118
|
+
- net-ssh-local.gemspec
|
119
|
+
homepage: https://github.com/slamotte/net-ssh-local
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.7.9
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Net::SSH plugin to streamline localhost operations.
|
143
|
+
test_files: []
|