uberssh 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00ceb1a29c2b813d5df35a33cd0692de1f2bc2bd
4
- data.tar.gz: c272b3853e0a0389356f2d97bcbc87de93b71ffe
3
+ metadata.gz: 12dd63cee0251013a6e9232d122f0042a2cb2dc6
4
+ data.tar.gz: 6af7485090d6997bb95887f5eb6217a38cd311ef
5
5
  SHA512:
6
- metadata.gz: 30efa33ed2656808ba981f185b5e6e1c615ed8168541804a699df811dda5dd36521eb532125d509006bbab7ebd250023a9e0a9ea3e27f4d5215647eb8766c11a
7
- data.tar.gz: 18885444f600606bfc994273c5459b87e5264fac1c1ad6f77f4a8574e0387dd0cbc7b15bad24ee860527262fa564d561b501b40de2237e7293fff5869f161c86
6
+ metadata.gz: c9e578675128cfc4243a31f88ddd0f1128cfbe4eaf0c0570c5ac51e90c627c470f5f8d0d972e5f998aaa66a41edad2c693f9ef76495149fb70bd54442caeae75
7
+ data.tar.gz: d8452a64b0b14677f42aa3d30e7f2bebe05587742309c191997840e82790241e9beb82f5c988b0d65e97db3b4a776c331bb28b02eb7a4fc4b1b404eabb1e0ffd
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.2
5
+ - 2.2.0
6
+
7
+ before_install: gem update bundler
8
+
9
+ script: bundle exec rspec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Uberssh
2
2
 
3
+ [![Tag](https://img.shields.io/github/tag/baschtl/uberssh.svg?style=flat-square)](https://github.com/baschtl/uberssh/releases) [![Build Status](https://img.shields.io/travis/baschtl/uberssh.svg?style=flat-square)](https://travis-ci.org/baschtl/uberssh) [![Code Climate](https://img.shields.io/codeclimate/github/baschtl/uberssh.svg?style=flat-square)](https://codeclimate.com/github/baschtl/uberssh)
4
+
3
5
  Uberssh is a script to select to which of your [Uberspaces](https://uberspace.de/) you want to connect to via ssh in just a few key strokes.
4
6
 
5
7
  The script was initially written by [pixelpogo](https://github.com/pixelpogo/).
@@ -21,16 +23,20 @@ To install the gem use the following command:
21
23
  foo: # your Uberspace account name
22
24
  project: "My Foo" # an arbitrary description of the project
23
25
  hostname: cepheus.uberspace.de # the hostname of your Uberspace
24
- ssh-key: ~/.ssh/uberspace_rsa # the ssh key used to connect to your Uberspace
26
+ ssh_key: ~/.ssh/uberspace_rsa # the ssh key used to connect to your Uberspace
25
27
  bar:
26
28
  project: "My Bar"
27
29
  hostname: perseus.uberspace.de
28
- ssh-key: ~/.ssh/uberspace_rsa
30
+ ssh_key: ~/.ssh/uberspace_rsa
29
31
  # ...
30
32
  ```
31
33
 
32
34
  3. Run `uberssh` from your command line.
33
35
 
36
+ ## Upgrading from 0.1.0 to 0.2.0
37
+
38
+ The configuration file format has changed slightly in version 0.2.0. The name of the key `ssh-key` was changed to `ssh_key`.
39
+
34
40
  ## Development
35
41
 
36
42
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec uberssh` to use the code located in this directory, ignoring other installed copies of this gem.
@@ -3,4 +3,4 @@
3
3
  require "bundler/setup"
4
4
  require "uberssh"
5
5
 
6
- Uberssh.connect!
6
+ Uberssh.run
@@ -1,29 +1,31 @@
1
- require "uberssh/version"
1
+ require "uberssh/app"
2
+ require "uberssh/account"
2
3
  require "uberssh/account_manager"
4
+ require "uberssh/version"
3
5
 
4
6
  require 'optparse'
5
- require 'ostruct'
6
7
  require 'etc'
8
+ require 'yaml'
7
9
 
8
10
  module Uberssh
9
11
 
10
- def self.connect!
11
- options = OpenStruct.new
12
+ def self.run
13
+ account_name = nil
14
+
12
15
  OptionParser.new do |opts|
16
+ opts.banner = "Uberssh"
13
17
 
14
- opts.banner = "Uberssh"
15
- opts.define_head "SSH to your uberspace"
18
+ opts.define_head "SSH to your Uberspace"
16
19
  opts.separator ""
17
20
  opts.separator "Options:"
18
21
 
19
22
  opts.on_tail("--help", "Show this message") do
20
23
  puts opts
21
- puts "\nTo be written...\n\n"
22
24
  exit
23
25
  end
24
26
 
25
- opts.on_tail("-a", "--account ACCOUNTNAME", "Specify your account") do |a|
26
- options.account = a
27
+ opts.on_tail("-a", "--account ACCOUNTNAME", "Specify your Uberspace account.") do |name|
28
+ account_name = name
27
29
  end
28
30
 
29
31
  begin
@@ -32,40 +34,9 @@ module Uberssh
32
34
  puts opts
33
35
  exit 1
34
36
  end
35
-
36
- end
37
-
38
- begin
39
-
40
- if options.account.nil?
41
- puts "\n============================================================="
42
- puts " uberssh - ssh to your uberspace"
43
- puts "=============================================================\n"
44
-
45
- accounts = []
46
- AccountManager.accounts.each_pair do |account, settings|
47
- accounts << account
48
- puts "[#{accounts.size}] #{settings['project']}"
49
- end
50
- print "\n--> Please select account: "
51
- index = gets.chomp.to_i
52
- options.account = accounts[index - 1]
53
- end
54
-
55
-
56
- system "clear"
57
- puts "Connecting to #{AccountManager.account(options.account)['project'].upcase}...\n"
58
-
59
- AccountManager.ssh(options.account).each_line do |ssh|
60
- puts ssh
61
- puts "\n"
62
- exec ssh
63
- end
64
-
65
- rescue Exception => e
66
- puts e.message
67
37
  end
68
38
 
39
+ App.new(account_name: account_name).start
69
40
  end
70
41
 
71
42
  end
@@ -0,0 +1,25 @@
1
+ module Uberssh
2
+
3
+ class Account
4
+
5
+ VALID_OPTIONS = %w( project hostname ssh_key )
6
+
7
+ attr_accessor :name, :project, :hostname, :ssh_key
8
+
9
+ def initialize(name, options = {})
10
+ @name = name
11
+
12
+ filtered_options(options).each do |k, v|
13
+ send("#{k}=", v)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def filtered_options(options)
20
+ options.select { |k, _| VALID_OPTIONS.include?(k) }
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -1,26 +1,42 @@
1
- require 'yaml'
2
-
3
1
  module Uberssh
4
2
 
5
3
  class AccountManager
6
4
 
7
- def self.accounts
8
- raise "No uberssh configuration found in #{config}" unless File.exist?(config)
9
- YAML.load_file(config)['accounts']
5
+ CONFIG_FILE = Etc.getpwuid.dir. + '/.uberssh'
6
+
7
+ def initialize
8
+ @accounts = []
9
+ end
10
+
11
+ def accounts
12
+ load_accounts if @accounts.empty?
13
+
14
+ @accounts
10
15
  end
11
16
 
12
- def self.ssh(name)
13
- a = account(name)
14
- raise "Unknown Uberspace account '#{name}'" if a.nil?
15
- "ssh -l #{name} #{a['hostname']} -i #{a['ssh-key']}"
17
+ def account_from_name(name)
18
+ accounts.detect { |a| a.name == name }
16
19
  end
17
20
 
18
- def self.account(name)
19
- accounts[name]
21
+ def print_accounts
22
+ accounts.each_with_index do |account, index|
23
+ puts "[#{index + 1}] #{account.project}"
24
+ end
20
25
  end
21
26
 
22
- def self.config
23
- Etc.getpwuid.dir. + "/.uberssh"
27
+ private
28
+
29
+ def config_file
30
+ CONFIG_FILE
31
+ end
32
+
33
+ def load_accounts
34
+ raise "No uberssh configuration found in #{config_file}." unless File.exist?(config_file)
35
+
36
+ config = YAML.load_file(config_file)['accounts']
37
+ config.each_pair do |k ,v|
38
+ @accounts << Account.new(k, v)
39
+ end
24
40
  end
25
41
 
26
42
  end
@@ -0,0 +1,62 @@
1
+ module Uberssh
2
+
3
+ class App
4
+
5
+ def initialize(account_name: nil)
6
+ @account_name = account_name
7
+ @manager = AccountManager.new
8
+ end
9
+
10
+ def start
11
+ begin
12
+ selected_account = nil
13
+
14
+ unless @account_name
15
+ selected_account = select_account
16
+ else
17
+ selected_account = @manager.account_from_name(@account_name)
18
+ raise "The given Uberspace account was not found." unless selected_account
19
+ end
20
+
21
+ system "clear"
22
+
23
+ puts "Connecting to #{selected_account.project}..."
24
+ connect_via_ssh_to(selected_account)
25
+ rescue Exception => e
26
+ puts e.message
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def select_account
33
+ print_welcome_message
34
+ @manager.print_accounts
35
+ print "\n--> Please select an account: "
36
+
37
+ selected_index = gets.chomp.to_i
38
+ selected_account = @manager.accounts[selected_index - 1]
39
+ raise "The number you gave was not on the list." unless selected_account
40
+
41
+ selected_account
42
+ end
43
+
44
+ def print_welcome_message
45
+ puts "\n============================================================="
46
+ puts " uberssh - ssh to your uberspace"
47
+ puts "=============================================================\n"
48
+ end
49
+
50
+ def connect_via_ssh_to(account)
51
+ ssh = ssh_command(account)
52
+ puts "#{ssh}"
53
+ exec ssh
54
+ end
55
+
56
+ def ssh_command(account)
57
+ "ssh -l #{account.name} #{account.hostname} -i #{account.ssh_key}"
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -1,3 +1,3 @@
1
1
  module Uberssh
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -20,8 +20,9 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_dependency "bundler", "~> 1.9"
23
+ spec.add_dependency "bundler", "~> 1.9"
24
24
 
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "rspec", "~> 3"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3"
27
+ spec.add_development_dependency "rspec-its", "~> 1.2"
27
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uberssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Oelke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-08 00:00:00.000000000 Z
11
+ date: 2015-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
55
69
  description: Uberssh is a script that let's you select to which of your uberspaces
56
70
  you want to connect to via ssh in just a few key strokes.
57
71
  email:
@@ -62,6 +76,7 @@ extensions: []
62
76
  extra_rdoc_files: []
63
77
  files:
64
78
  - ".gitignore"
79
+ - ".travis.yml"
65
80
  - Gemfile
66
81
  - LICENSE
67
82
  - README.md
@@ -70,7 +85,9 @@ files:
70
85
  - bin/setup
71
86
  - exe/uberssh
72
87
  - lib/uberssh.rb
88
+ - lib/uberssh/account.rb
73
89
  - lib/uberssh/account_manager.rb
90
+ - lib/uberssh/app.rb
74
91
  - lib/uberssh/version.rb
75
92
  - uberssh.gemspec
76
93
  homepage: https://github.com/baschtl/uberssh.git