russh 0.0.4 → 0.0.5
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/README.md +8 -11
- data/lib/russh/accessor.rb +44 -12
- data/lib/russh/cli.rb +15 -3
- data/lib/russh/version.rb +1 -1
- data/spec/lib/russh/accessor_spec.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1914bfc930ce7a0fe5d96e79309e8694d49287cc
|
4
|
+
data.tar.gz: de673be7381035aa26230359be3654a30db6f0bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b476daad69ad412a0578dcb2bfa9458a40ed6bd0271c1f8dfa8d0f4de9e1b0382826beb8fd9a48ba49a646fd6891cf629088897e1c0935aef82026e240995ea
|
7
|
+
data.tar.gz: f8dea1d5ec7c589876608ee245fccf4cd7a81acf1a86be5bceb65a874b151d22c5d9a9c931136baa9caf2928d83635ec42d0f87d972aab4fa5586fc0e97f7e01
|
data/README.md
CHANGED
@@ -1,24 +1,21 @@
|
|
1
1
|
# Russh
|
2
2
|
|
3
|
-
**Russh =** Ruby + SSH . SSH Config Manager for Ruby.
|
3
|
+
**Russh =** Ruby + SSH . SSH Config Manager for Ruby. It helps you manage your SSH configuration.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'russh'
|
10
|
-
|
11
|
-
And then execute:
|
5
|
+
You can create, delete and update your existing configuration.
|
12
6
|
|
13
|
-
|
7
|
+
Currently under heavy development.
|
14
8
|
|
15
|
-
|
9
|
+
## Installation
|
16
10
|
|
17
11
|
$ gem install russh
|
18
12
|
|
19
13
|
## Usage
|
20
14
|
|
21
|
-
|
15
|
+
### Create a new configuration
|
16
|
+
|
17
|
+
russh create
|
18
|
+
|
22
19
|
|
23
20
|
## Contributing
|
24
21
|
|
data/lib/russh/accessor.rb
CHANGED
@@ -6,18 +6,40 @@ module Russh
|
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@path = Dir.home + '/.ssh/config'
|
9
|
-
@
|
10
|
-
@
|
9
|
+
@is_existing = is_existing?
|
10
|
+
@is_readable = is_readable?
|
11
|
+
@is_writable = is_writable?
|
11
12
|
end
|
12
13
|
|
14
|
+
# Checks if the config file is existing. If not it creates a new one.
|
15
|
+
def is_existing?
|
16
|
+
if File.exist? @path
|
17
|
+
@is_existing = true
|
18
|
+
else
|
19
|
+
puts "You don't have an existing ssh config file. Creating a new one for you."
|
20
|
+
File.new(@path, 'w')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Checks if the config file is readable.
|
13
25
|
def is_readable?
|
14
|
-
|
26
|
+
begin
|
27
|
+
@is_readable = File.readable? @path
|
28
|
+
rescue => e
|
29
|
+
puts "Couldn't be able to read your ssh config: Error #{e}"
|
30
|
+
end
|
15
31
|
end
|
16
32
|
|
33
|
+
# Checks if the config file is writable.
|
17
34
|
def is_writable?
|
18
|
-
|
35
|
+
begin
|
36
|
+
@is_writable = File.writable? @path
|
37
|
+
rescue => e
|
38
|
+
puts "Couldn't be able to write your ssh config: Error #{e}"
|
39
|
+
end
|
19
40
|
end
|
20
41
|
|
42
|
+
# Backups the config file to config.bk
|
21
43
|
def backup
|
22
44
|
if is_readable?
|
23
45
|
FileUtils.cp @path, "#{@path}.bk"
|
@@ -30,18 +52,28 @@ module Russh
|
|
30
52
|
end
|
31
53
|
end
|
32
54
|
|
33
|
-
def create
|
34
|
-
|
35
|
-
@
|
36
|
-
@
|
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
|
37
61
|
if is_readable? && is_writable?
|
38
62
|
backup
|
39
|
-
open(@path, 'a') do |f|
|
40
|
-
|
41
|
-
f.puts
|
42
|
-
|
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
|
43
68
|
end
|
44
69
|
end
|
45
70
|
end
|
71
|
+
|
72
|
+
protected
|
73
|
+
|
74
|
+
# Formats each entry
|
75
|
+
def format_entry
|
76
|
+
"Host #{@host}\n\tHostName #{@host_name}\n\tUser #{@user}"
|
77
|
+
end
|
46
78
|
end
|
47
79
|
end
|
data/lib/russh/cli.rb
CHANGED
@@ -7,17 +7,29 @@ module Russh
|
|
7
7
|
include Commander::Methods
|
8
8
|
|
9
9
|
def run
|
10
|
-
program :name, '
|
10
|
+
program :name, 'Russh'
|
11
11
|
program :version, VERSION
|
12
12
|
program :description, 'SSH Config Manager For Ruby'
|
13
13
|
|
14
14
|
command :create do |c|
|
15
|
-
c.syntax = 'russh create'
|
15
|
+
c.syntax = 'russh create [options]'
|
16
16
|
c.description = 'Creates a new host'
|
17
|
+
c.option '--alias STRING', String, 'Host Alias'
|
18
|
+
c.option '--host STRING', String, 'Host Address'
|
19
|
+
c.option '--user STRING', String, 'Username'
|
17
20
|
c.action do |args, options|
|
18
|
-
Accessor.new.create
|
21
|
+
Accessor.new.create options.alias, options.host, options.user
|
19
22
|
end
|
20
23
|
end
|
24
|
+
|
25
|
+
command :backup do |c|
|
26
|
+
c.syntax = 'russh backup'
|
27
|
+
c.description = 'Backups your ssh config'
|
28
|
+
c.action do |args, options|
|
29
|
+
Accessor.new.backup
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
21
33
|
run!
|
22
34
|
end
|
23
35
|
end
|
data/lib/russh/version.rb
CHANGED
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.5
|
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-
|
11
|
+
date: 2014-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|