russh 0.0.6 → 0.0.7
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 +4 -4
- data/.rspec +0 -1
- data/README.md +11 -1
- data/lib/russh/accessor.rb +25 -40
- data/lib/russh/cli.rb +8 -0
- data/lib/russh/version.rb +1 -1
- data/russh.gemspec +2 -1
- data/spec/lib/russh/accessor_spec.rb +26 -16
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 614706f0a74e0dc9663785bd9692ef884a322ce0
|
4
|
+
data.tar.gz: 4db4a0818d8c4d25d385c40422bcb8b9779c3f7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76c12a3c2d8f23881262a01db24986a155e15965a1f87671318be58226db3bdd9d3ba8afcd4338d9a93c6e384ad0615bdcfe0704b9c2946afeb18a4722d237f1
|
7
|
+
data.tar.gz: dd48d669aa5f05a03423e7198c69015b3d49e5f171b844895c14f6bc981be94a49180a74d945ea5df6d278a9d14b34c207a03d236d9cc515457efe0312ef9560
|
data/.rspec
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Russh
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/russh)
|
4
|
+
|
3
5
|
**Russh =** Ruby + SSH . SSH Config Manager for Ruby. It helps you manage your SSH configuration.
|
4
6
|
|
5
7
|
You can create, delete and update your existing configuration.
|
@@ -14,15 +16,23 @@ Currently under heavy development.
|
|
14
16
|
|
15
17
|
### Create a new configuration
|
16
18
|
|
19
|
+
Creates a new configuration for an alias.
|
20
|
+
|
17
21
|
russh create --alias host1 --host www.example.com --username ubuntu
|
18
22
|
|
19
23
|
### Backup
|
20
24
|
|
25
|
+
Backups your entire .ssh/config file.
|
26
|
+
|
21
27
|
russh backup
|
22
28
|
|
29
|
+
## Todo
|
30
|
+
|
31
|
+
Add todo list
|
32
|
+
|
23
33
|
## Contributing
|
24
34
|
|
25
|
-
1. Fork it ( https://github.com/
|
35
|
+
1. Fork it ( https://github.com/sdogruyol/russh/fork )
|
26
36
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
37
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
38
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/russh/accessor.rb
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
require 'commander'
|
2
|
+
require 'net/ssh'
|
2
3
|
|
3
4
|
module Russh
|
4
5
|
class Accessor
|
5
|
-
attr_reader :path
|
6
|
-
|
7
6
|
def initialize
|
8
7
|
@path = Dir.home + '/.ssh/config'
|
9
8
|
@is_existing = is_existing?
|
10
|
-
@is_readable = is_readable?
|
11
|
-
@is_writable = is_writable?
|
12
9
|
end
|
13
10
|
|
14
11
|
# Checks if the config file is existing. If not it creates a new one.
|
@@ -21,52 +18,40 @@ module Russh
|
|
21
18
|
end
|
22
19
|
end
|
23
20
|
|
24
|
-
#
|
25
|
-
def
|
26
|
-
|
27
|
-
@is_readable = File.readable? @path
|
28
|
-
rescue => e
|
29
|
-
puts "Couldn't read your ssh config: Error #{e}"
|
30
|
-
end
|
21
|
+
# Backups the config file to config.bk
|
22
|
+
def backup
|
23
|
+
FileUtils.cp @path, "#{@path}.bk"
|
31
24
|
end
|
32
25
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
26
|
+
def create(host, host_name, user)
|
27
|
+
@host = host
|
28
|
+
@host_name = host_name
|
29
|
+
@user = user
|
30
|
+
backup
|
31
|
+
open(@path, 'a+') do |f|
|
32
|
+
# If the file is new don't add a newline.
|
33
|
+
f.puts if f.readlines.size > 0
|
34
|
+
# Format each entry
|
35
|
+
f.puts format_entry
|
39
36
|
end
|
40
37
|
end
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
def list
|
40
|
+
hosts = []
|
41
|
+
configs = []
|
42
|
+
|
43
|
+
File.readlines(@path).each do |line|
|
44
|
+
hosts << line.split(' ')[1].strip if line[/^Host/]
|
46
45
|
end
|
47
|
-
end
|
48
46
|
|
49
|
-
|
50
|
-
|
51
|
-
File.read @path
|
47
|
+
hosts.each do |host|
|
48
|
+
configs.push Net::SSH::Config.load @path, host
|
52
49
|
end
|
53
|
-
end
|
54
50
|
|
55
|
-
|
56
|
-
|
57
|
-
@host = host
|
58
|
-
@host_name = host_name
|
59
|
-
@user = user
|
60
|
-
# Check for read and write access
|
61
|
-
if is_readable? && is_writable?
|
62
|
-
backup
|
63
|
-
open(@path, 'a+') do |f|
|
64
|
-
# If the file is new don't add a newline.
|
65
|
-
f.puts if f.readlines.size > 0
|
66
|
-
# Format each entry
|
67
|
-
f.puts format_entry
|
68
|
-
end
|
51
|
+
configs.each do |config|
|
52
|
+
puts "Host #{config['host']} HostName #{config['hostname']} User #{config['user']}"
|
69
53
|
end
|
54
|
+
|
70
55
|
end
|
71
56
|
|
72
57
|
protected
|
data/lib/russh/cli.rb
CHANGED
data/lib/russh/version.rb
CHANGED
data/russh.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
-
spec.add_development_dependency "rspec",
|
23
|
+
spec.add_development_dependency "rspec", '3.0.0'
|
24
24
|
spec.add_dependency "commander", "4.2.0"
|
25
|
+
spec.add_dependency "net-ssh"
|
25
26
|
end
|
@@ -1,35 +1,45 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Russh::Accessor do
|
4
|
-
let(:path){ }
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
subject.is_writable?.should == true
|
5
|
+
class TestAccessor < Russh::Accessor
|
6
|
+
attr_accessor :path
|
7
|
+
def initialize
|
8
|
+
@path = '/tmp/ssh_conf'
|
9
|
+
is_existing?
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
13
|
+
subject { TestAccessor.new }
|
14
|
+
|
15
15
|
context 'backup' do
|
16
16
|
it 'should copy the original config' do
|
17
|
-
original_file = subject.read
|
18
17
|
subject.backup
|
19
|
-
File.read( + '.bk').should ==
|
18
|
+
File.read(subject.path + '.bk').should == File.read(subject.path)
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
|
-
context '
|
24
|
-
it 'should be able to
|
25
|
-
subject.
|
22
|
+
context 'writing' do
|
23
|
+
it 'should be able to create a new host' do
|
24
|
+
subject.stub(:backup)
|
25
|
+
subject.create('host', 'example.com', 'user')
|
26
|
+
File.exist?(subject.path).should == true
|
27
|
+
File.delete('/tmp/ssh_conf')
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
context '
|
30
|
-
it '
|
31
|
-
|
32
|
-
subject.create('
|
31
|
+
context 'listing' do
|
32
|
+
it 'lists all the entries' do
|
33
|
+
subject.stub(:backup)
|
34
|
+
subject.create('test1', 'test1.com', 'serdar')
|
35
|
+
subject.create('test2', 'test2.com', 'serkan')
|
36
|
+
expected_output = "Host test1 HostName test1.com User serdar\nHost test2 HostName test2.com User serkan\n"
|
37
|
+
expect{ subject.list }.to output(expected_output).to_stdout
|
33
38
|
end
|
34
39
|
end
|
40
|
+
|
41
|
+
after(:all) do
|
42
|
+
File.delete('/tmp/ssh_conf', '/tmp/ssh_conf.bk')
|
43
|
+
end
|
44
|
+
|
35
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: russh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Serdar Dogruyol
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.0.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.0.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: commander
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 4.2.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: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: 'Russh: Ruby + SSH. SSH Config Manager for Ruby'
|
70
84
|
email:
|
71
85
|
- dogruyolserdar@gmail.com
|