russh 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e4af0e6a54d75a9e599d90c7b181111897ddab4
4
- data.tar.gz: 00513f2149c5367fb396d5d32d4a2ce58c759751
3
+ metadata.gz: 614706f0a74e0dc9663785bd9692ef884a322ce0
4
+ data.tar.gz: 4db4a0818d8c4d25d385c40422bcb8b9779c3f7d
5
5
  SHA512:
6
- metadata.gz: 296ec9449bf2cbdb87b6bdb05acd72e15b12fb7a11dbf84ed8e39db3f431919d0a0e1579a9bc8256a52a4d0c5a7d91bf0a7dd1cc1d273554cea0665088a8946d
7
- data.tar.gz: b8454e6066df5d6b8f0b56cc33559703445cb42cfddec82fed377384544e3b479e79822ce9f8eb5b815e733202b8dbd45e76553d2af3255db6d2fa7cb187b008
6
+ metadata.gz: 76c12a3c2d8f23881262a01db24986a155e15965a1f87671318be58226db3bdd9d3ba8afcd4338d9a93c6e384ad0615bdcfe0704b9c2946afeb18a4722d237f1
7
+ data.tar.gz: dd48d669aa5f05a03423e7198c69015b3d49e5f171b844895c14f6bc981be94a49180a74d945ea5df6d278a9d14b34c207a03d236d9cc515457efe0312ef9560
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
1
  --color
2
- --warnings
3
2
  --require spec_helper
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Russh
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/russh.svg)](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/[my-github-username]/russh/fork )
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`)
@@ -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
- # Checks if the config file is readable.
25
- def is_readable?
26
- begin
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
- # Checks if the config file is writable.
34
- def is_writable?
35
- begin
36
- @is_writable = File.writable? @path
37
- rescue => e
38
- puts "Couldn't write to your ssh config: Error #{e}"
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
- # Backups the config file to config.bk
43
- def backup
44
- if is_readable?
45
- FileUtils.cp @path, "#{@path}.bk"
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
- def read
50
- if is_readable?
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
- def create(host, host_name, user)
56
- # Ask the user for input
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
@@ -32,6 +32,14 @@ module Russh
32
32
  end
33
33
  end
34
34
 
35
+ command :list do |c|
36
+ c.syntax = 'russh list'
37
+ c.description = 'Lists all the entries in your ssh config'
38
+ c.action do
39
+ Accessor.new.list
40
+ end
41
+ end
42
+
35
43
  run!
36
44
  end
37
45
  end
@@ -1,3 +1,3 @@
1
1
  module Russh
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -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", "2.99.1"
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
- context 'accessing' do
7
- it 'should be able to read .ssh/config' do
8
- subject.is_readable?.should == true
9
- end
10
- it 'should be able to write .ssh/config' do
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 == original_file
18
+ File.read(subject.path + '.bk').should == File.read(subject.path)
20
19
  end
21
20
  end
22
21
 
23
- context 'reading' do
24
- it 'should be able to get the file content' do
25
- subject.read.should_not == nil
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 'writing' do
30
- it 'should be able to create a new host' do
31
- original_file = subject.read
32
- subject.create('host1', 'www.sample.com', 'user1')
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.6
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-08-09 00:00:00.000000000 Z
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: 2.99.1
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: 2.99.1
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