sshhub 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dd64ad761563decffdb9c53de53a4b16ead4e1e9
4
+ data.tar.gz: fa17f935ae296a8cc3096faacb798fe166dd63d5
5
+ SHA512:
6
+ metadata.gz: fa4cd7aefe827cb2110c5e7d4608983b0a8164f030a4e7eb0a8fdde1c5a6234372029dfc01ffdbcb1fe1e007ba7112c5cf35a92513ac8d42b74d1a4ab3aa4dd7
7
+ data.tar.gz: f7bb65e4668965074c9c9c194e96829e3be2d423d546da3af3643f4844171e5ada43dc1a8ae092b790d8f0c299373e28ba55c4794b253e014f7e3cafd9638c7e
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .gitconfig
6
+ .yardoc
7
+ .rspec
8
+ .DS_Store
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
21
+ *.bundle
22
+ *.so
23
+ *.o
24
+ *.a
25
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sshhub.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Matthew Werner
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Sshhub
2
+
3
+ sshhub is an easy way to authorize the keys of a github user on your machine.
4
+
5
+ ````
6
+ $ sshhub authorize mwerner
7
+ Requesting keys for mwerner...
8
+ 2 keys found:
9
+ 1) ssh-rsa AAAAB3Nz ... 0QkUi8N3GtW8bWt
10
+ 2) ssh-dss AAAAB3Nz ... voG4UfVujCJdkh=
11
+ A) Authorize all keys
12
+
13
+ Select a key to authorize: 2
14
+ Added ssh-rsa AAAAB3Nz ... voG4UfVujCJdkh= to authorized_keys
15
+ $
16
+ ````
17
+
18
+ ## Installation
19
+
20
+ $ gem install sshhub
21
+
22
+ ## Contributing
23
+
24
+ 1. Fork it ( https://github.com/[my-github-username]/sshhub/fork )
25
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
26
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
27
+ 4. Push to the branch (`git push origin my-new-feature`)
28
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/sshhub ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ require 'thor'
3
+ require 'sshhub'
4
+
5
+ class SshhubCommand < Thor
6
+ include Thor::Actions
7
+
8
+ desc "authorize USERNAME", "Add keys from a github username to your authorized_keys file"
9
+ def authorize(username)
10
+ say "Requesting keys for #{username}...\n"
11
+ keychain = Sshhub::Keychain.new(username)
12
+ keys = keychain.length == 1 ? [keychain.keys.first] : key_selection(keychain.keys)
13
+
14
+ keys.each{|key| Sshhub::PortAuthority.authorize(key) }
15
+ print_report(keys)
16
+ end
17
+
18
+ private
19
+
20
+ def key_selection(keys)
21
+ say "#{keys.length} keys found:\n"
22
+ i = 0
23
+ keys.each do |key|
24
+ i += 1
25
+ printf(" %-3s %5s\n" % ["#{i})", key.abridged])
26
+ end
27
+ printf(" %-3s %5s\n" % ['A)', 'Authorize all keys'])
28
+ pos = ask("\nSelect a key to authorize:")
29
+ return [] if pos == ''
30
+
31
+ pos.to_i.zero? ? keys : [keys[pos.to_i - 1]]
32
+ end
33
+
34
+ def print_report(keys)
35
+ if keys.length == 0
36
+ say "No keys authorized"
37
+ elsif keys.length == 1
38
+ say "Added #{keys.first.abridged} to authorized_keys"
39
+ else
40
+ say "Added #{keys.length} keys to authorized_keys"
41
+ end
42
+ end
43
+ end
44
+
45
+ SshhubCommand.start
data/lib/sshhub/key.rb ADDED
@@ -0,0 +1,17 @@
1
+ module Sshhub
2
+ class Key
3
+ attr_accessor :id, :key
4
+ def initialize(options = {})
5
+ @id = options[:id]
6
+ @key = options[:key]
7
+ end
8
+
9
+ def abridged
10
+ "#{key[0..15]} ... #{key[(key.length - 15)..-1]}"
11
+ end
12
+
13
+ def to_s
14
+ key
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ require 'octokit'
2
+
3
+ module Sshhub
4
+ class Keychain
5
+ attr_reader :username
6
+
7
+ def initialize(username)
8
+ @username = username
9
+ end
10
+
11
+ def keys
12
+ @keys ||= api_data.map{|key| Sshhub::Key.new(key) }
13
+ end
14
+
15
+ def length
16
+ keys.length
17
+ end
18
+
19
+ private
20
+
21
+ def api_data
22
+ client.user_keys(username)
23
+ end
24
+
25
+ def client
26
+ @client ||= Octokit::Client.new
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ module Sshhub
2
+ class PortAuthority
3
+ def self.authorize(key)
4
+ system('mkdir', '-p', "/Users/#{whoami}/.ssh")
5
+ File.open(filename, 'a'){|f| f.write("#{key}\n") }
6
+ end
7
+
8
+ private
9
+
10
+ def self.filename
11
+ "/Users/#{whoami}/.ssh/authorized_keys"
12
+ end
13
+
14
+ def self.whoami
15
+ @whoami ||= `whoami`.rstrip
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Sshhub
2
+ VERSION = "0.0.1"
3
+ end
data/lib/sshhub.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "sshhub/version"
2
+
3
+ module Sshhub
4
+ autoload :Key, 'sshhub/key'
5
+ autoload :Keychain, 'sshhub/keychain'
6
+ autoload :PortAuthority, 'sshhub/port_authority'
7
+ end
@@ -0,0 +1,5 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'rspec'
5
+ require 'sshhub'
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sshhub::Key do
4
+ let(:key){ Sshhub::Key.new(id: 1, key: 'abc') }
5
+
6
+ context 'Initialization' do
7
+ it 'accepts a hash of options' do
8
+ expect(key.id).to eq(1)
9
+ expect(key.key).to eq('abc')
10
+ end
11
+ end
12
+
13
+ context 'Output' do
14
+ it 'provides an abridged key' do
15
+ key.key = 'abcdefghijklmnopqrstuvwxyz'
16
+ expect(key.abridged).to eq('abcdefghijklmnop ... lmnopqrstuvwxyz')
17
+ end
18
+
19
+ it 'returns the key when coerced to string' do
20
+ expect(key.to_s).to eq(key.key)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sshhub::Keychain do
4
+ let(:keychain){ Sshhub::Keychain.new('mwerner') }
5
+
6
+ context 'Initialization' do
7
+ it 'accepts a github username' do
8
+ expect(keychain.username).to eq('mwerner')
9
+ end
10
+ end
11
+
12
+ context 'Keys' do
13
+ it 'returns an array of keys' do
14
+ Octokit::Client.any_instance.should_receive(:user_keys).and_return([{id: 1, key: 'abc'}])
15
+ expect(keychain.keys).to be_a_kind_of(Array)
16
+ expect(keychain.keys.first).to be_a_kind_of(Sshhub::Key)
17
+ end
18
+
19
+ it 'delegates length to the keys' do
20
+ Octokit::Client.any_instance.should_receive(:user_keys).and_return([{id: 1, key: 'abc'}])
21
+ expect(keychain.length).to eq(1)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sshhub::PortAuthority do
4
+ let(:key){ Sshhub::Key.new(id: 1, key: 'ssh-rsa abc123') }
5
+
6
+ context 'Authorizing a key' do
7
+ before do
8
+ described_class.should_receive(:`).and_return('foo')
9
+ described_class.should_receive(:system).with('mkdir', '-p', "/Users/foo/.ssh").and_return(true)
10
+ end
11
+
12
+ it 'writes to authorized_keys' do
13
+ File.should_receive(:open)
14
+ Sshhub::PortAuthority.authorize(key)
15
+ end
16
+ end
17
+ end
data/sshhub.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sshhub/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sshhub"
8
+ spec.version = Sshhub::VERSION
9
+ spec.authors = ["Matthew Werner"]
10
+ spec.email = ["m@mjw.io"]
11
+ spec.summary = %q{sshhub is an easy way to get ssh keys authorized on your public server}
12
+ spec.description = spec.summary
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'thor', '~> 0.19'
22
+ spec.add_dependency 'octokit', '~> 3.1'
23
+
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'bundler', '~> 1.6'
26
+ spec.add_development_dependency 'simplecov', '~> 0.7'
27
+ spec.add_development_dependency 'rspec', '~> 2.13'
28
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sshhub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Werner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: octokit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.13'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.13'
97
+ description: sshhub is an easy way to get ssh keys authorized on your public server
98
+ email:
99
+ - m@mjw.io
100
+ executables:
101
+ - sshhub
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/sshhub
111
+ - lib/sshhub.rb
112
+ - lib/sshhub/key.rb
113
+ - lib/sshhub/keychain.rb
114
+ - lib/sshhub/port_authority.rb
115
+ - lib/sshhub/version.rb
116
+ - spec/spec_helper.rb
117
+ - spec/sshhub/key_spec.rb
118
+ - spec/sshhub/keychain_spec.rb
119
+ - spec/sshhub/port_authority_spec.rb
120
+ - sshhub.gemspec
121
+ homepage: ''
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.2.2
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: sshhub is an easy way to get ssh keys authorized on your public server
145
+ test_files:
146
+ - spec/spec_helper.rb
147
+ - spec/sshhub/key_spec.rb
148
+ - spec/sshhub/keychain_spec.rb
149
+ - spec/sshhub/port_authority_spec.rb