vinz-clortho 0.2.0 → 0.2.2

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: 1c7d1dc9a67cbe8dbb7fed2576a513dbbf1893a2
4
- data.tar.gz: 0ae8f1d61cce96605e507ea754a29174c8ae0f2d
3
+ metadata.gz: 704ac9fcd6af0c2f23318b8dbe9373a9019abf68
4
+ data.tar.gz: ba18d38827dc852d1369065a7278b2a9a96459cb
5
5
  SHA512:
6
- metadata.gz: 1c45a032491881e39f991ccc4c74d6c365fba9b73d31c28b23e7b13f18401e99010055758f5616a52486bb401e2216ecfeee2309a07cf195b355fd89ae190ab3
7
- data.tar.gz: a94adbb62af2e8dc09556b71459631e2f662f8fcd02007b6ab86dc9740c2d02b698191b7c2084d2ac9344e1142ff7e1eb228ac51fc1d1927d09a14ea9a3fea3c
6
+ metadata.gz: b7f57270367f369d3512bec73121b92d60162cd698f8d226ecfb9433c31e32edf6daeed3c673a634504c45299fb85695ffcea2a810531184c2987867dbd7b6dd
7
+ data.tar.gz: eda626e590e9bc29f90cf57a9a51b117895148fe04a012069760b94323524e72b62f160aff8aa9ca62c695a856e74eaae6d912729ed05ee281f2f1cb96fc84a1
@@ -0,0 +1,6 @@
1
+ guard :minitest do
2
+ # with Minitest::Unit
3
+ watch(%r{^test/(.*)\/?(.*)_test\.rb$})
4
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
5
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
6
+ end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Vinz Clortho
1
+ # Vinz Clortho [![Build Status](https://travis-ci.org/pivotal/vinz-clortho.svg?branch=master)](https://travis-ci.org/pivotal/vinz-clortho)
2
2
 
3
3
  <img src="http://i.giphy.com/Sf0xvEgdWyraU.gif" alt="Vinz Clortho" width="100%">
4
4
 
@@ -15,6 +15,11 @@ sshkey_paths:
15
15
  ```
16
16
  See the [.git-authors](.git-authors) file in this repository as a full example.
17
17
 
18
+ ## Installation
19
+
20
+ ```
21
+ gem install vinz-clortho
22
+ ```
18
23
 
19
24
  ## Usage
20
25
 
@@ -28,4 +33,4 @@ Usage: git ssh-login [options] [committer-initials]
28
33
  --add-to-github Adds a public key to GitHub
29
34
  ```
30
35
 
31
- You can also use `git push-authenticated [args]` to authenticate all existing keys for a period of 5 seconds and then push immediately. It takes the same arguments as `git push` (and just passes them on).
36
+ You can also use `git push-authenticated [args]` to authenticate all existing keys for a period of 5 seconds and then push immediately. It takes the same arguments as `git push` (and just passes them on).
@@ -1,10 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'vinz/clortho'
3
3
 
4
- begin
5
- Vinz::Clortho::SSHSetup.new.login_all(5)
6
- `git push #{ARGV.join ' '}`
7
- rescue => e
8
- puts e.message
9
- exit 1
10
- end
4
+ Vinz::Clortho::Cli::PushAuthenticated.new.perform(*ARGV)
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'optparse'
3
- require 'io/console'
4
3
  require 'vinz/clortho'
5
4
 
6
5
  begin
7
6
  ssh_setup = Vinz::Clortho::SSHSetup.new
8
7
  initials = ARGV[0]
8
+ sshlogin_cli = Vinz::Clortho::Cli::SSHLogin.new
9
9
 
10
10
  parser = OptionParser.new do |opts|
11
11
  opts.banner = ssh_setup.usage_msg
@@ -18,22 +18,15 @@ begin
18
18
  puts Vinz::Clortho::VERSION
19
19
  exit 0
20
20
  end
21
- opts.on('--add-to-github', 'Adds a public key to GitHub') do |v|
22
- print "Enter your username: "
23
- username = gets.chomp
24
- print "Enter your password: "
25
- password = STDIN.noecho(&:gets).chomp
26
- puts # because previous line of code doesn't insert newline
27
- uploader = Vinz::Clortho::GitHubKeyUploader.new(initials, username, password)
28
- print "Enter title for key: "
29
- title = gets.chomp
30
- uploader.upload title
21
+ opts.on('--add-to-github', 'Adds a public key to Github') do |v|
22
+ sshlogin_cli.add_to_github(initials)
31
23
  exit 0
32
24
  end
33
25
  end
34
26
 
35
27
  parser.parse!
36
- ssh_setup.login(initials)
28
+ sshlogin_cli.perform(initials)
29
+
37
30
  rescue OptionParser::InvalidOption => e
38
31
  puts parser
39
32
  exit 1
@@ -43,4 +36,3 @@ rescue => e
43
36
  exit (e.is_a? Vinz::Clortho::UserNotFoundError) ? 2 : 1
44
37
  end
45
38
 
46
- puts "Key will expire at #{ssh_setup.key_expiry}"
@@ -2,3 +2,7 @@ require 'vinz/clortho/version'
2
2
  require 'vinz/clortho/ssh_key_path_manager'
3
3
  require 'vinz/clortho/ssh_setup'
4
4
  require 'vinz/clortho/github_key_uploader'
5
+ require 'vinz/clortho/cli/push_authenticated'
6
+ require 'vinz/clortho/cli/ssh_login'
7
+ require 'vinz/clortho/github_client_wrapper'
8
+ require 'vinz/clortho/file_wrapper'
@@ -0,0 +1,6 @@
1
+ module Vinz
2
+ module Clortho
3
+ module Cli
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ module Vinz
2
+ module Clortho
3
+ module Cli
4
+
5
+ class PushAuthenticated
6
+ def perform *args
7
+ SSHSetup.new.login_all(5)
8
+ kernel.system "git push #{args.join(' ')}"
9
+ end
10
+
11
+ def kernel
12
+ Kernel
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,32 @@
1
+ require 'io/console'
2
+
3
+ module Vinz
4
+ module Clortho
5
+ module Cli
6
+ class SSHLogin
7
+ def kernel
8
+ Kernel
9
+ end
10
+
11
+ def perform(initials)
12
+ setup = SSHSetup.new
13
+ setup.login(initials)
14
+ kernel.puts "Key will expire at #{setup.key_expiry}"
15
+ end
16
+
17
+ def add_to_github initials
18
+ kernel.print "Enter your username: "
19
+ username = kernel.gets.chomp
20
+ kernel.print "Enter your password: "
21
+ password = STDIN.noecho(&:gets).chomp
22
+
23
+ kernel.puts # because previous line of code doesn't insert newline
24
+ uploader = Vinz::Clortho::GithubKeyUploader.new(initials, username, password)
25
+ kernel.print "Enter title for key: "
26
+ title = kernel.gets.chomp
27
+ uploader.upload title
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ module Vinz
2
+ module Clortho
3
+ class FileWrapper
4
+
5
+ def initialize(path, mode)
6
+ @file = File.new(path, mode)
7
+ end
8
+
9
+ def self.open(path, mode)
10
+ new(path, mode)
11
+ end
12
+
13
+ def read
14
+ @file.read
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Vinz
2
+ module Clortho
3
+ class GithubClientWrapper
4
+ def initialize(options = {})
5
+ @client = Octokit::Client.new(login: options[:login], password: options[:password])
6
+ end
7
+
8
+ def add_key(title, key)
9
+ @client.add_key(title, key)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -2,7 +2,7 @@ require 'octokit'
2
2
 
3
3
  module Vinz
4
4
  module Clortho
5
- class GitHubKeyUploader
5
+ class GithubKeyUploader
6
6
  def initialize(initials, username, password)
7
7
  @manager = SSHKeyPathManager.new
8
8
  @initials = initials
@@ -10,14 +10,19 @@ module Vinz
10
10
  end
11
11
 
12
12
  def upload(title)
13
- key = File.open("#{@manager.key_path_for(@initials)}.pub", "r").read
13
+ key = file.read
14
14
  client.add_key(title, key)
15
15
  end
16
16
 
17
17
  private
18
+
18
19
  def client
19
- @client ||= Octokit::Client.new(login: @username, password: @password)
20
+ @client ||= GithubClientWrapper.new(login: @username, password: @password)
21
+ end
22
+
23
+ def file
24
+ @file ||= FileWrapper.open("#{@manager.key_path_for(@initials)}.pub", "r")
20
25
  end
21
26
  end
22
27
  end
23
- end
28
+ end
@@ -16,15 +16,19 @@ module Vinz
16
16
  class SSHKeyPathManager
17
17
  attr_reader :key_paths
18
18
 
19
- DEFAULT_KEY_PATH = '/Volumes/*/.ssh/id_rsa'
19
+ DEFAULT_KEYS = lambda { Dir['/Volumes/*/.ssh/id_rsa'].map { |path| KeyPathEntry.new(path) } }
20
20
 
21
21
  def initialize
22
22
  @key_paths = if git_authors_file.nil?
23
- Dir[DEFAULT_KEY_PATH].map { |path| KeyPathEntry.new(path) }
23
+ DEFAULT_KEYS.call
24
24
  else
25
25
  git_authors = YAML::load_file(git_authors_file)
26
- git_authors['sshkey_paths'].map do |initials, path|
27
- KeyPathEntry.new(path, initials)
26
+ if git_authors.has_key? 'sshkey_paths'
27
+ git_authors['sshkey_paths'].map do |initials, path|
28
+ KeyPathEntry.new(path, initials)
29
+ end
30
+ else
31
+ DEFAULT_KEYS.call
28
32
  end
29
33
  end
30
34
  end
@@ -1,5 +1,8 @@
1
1
  module Vinz
2
2
  module Clortho
3
+ class UnableToLoginError < StandardError
4
+ end
5
+
3
6
  class SSHSetup
4
7
  attr_reader :key_expiry
5
8
 
@@ -14,7 +17,6 @@ module Vinz
14
17
  login_all key_ttl
15
18
  else
16
19
  key_path = @ssh_key_path_mgr.key_path_for initials
17
- raise Errno::ENOENT.new unless File.exist? key_path
18
20
  ssh_add(key_ttl, key_path)
19
21
  end
20
22
  end
@@ -25,6 +27,8 @@ module Vinz
25
27
  key_ttl = @key_expiry.to_i - Time.now.to_i
26
28
  end
27
29
 
30
+ raise UnableToLoginError.new('no key paths available') unless @ssh_key_path_mgr.key_paths.any?
31
+
28
32
  @ssh_key_path_mgr.key_paths.each do |key_path|
29
33
  path = key_path.path
30
34
  ssh_add(key_ttl, path) if File.exist?(path)
@@ -32,6 +36,7 @@ module Vinz
32
36
  end
33
37
 
34
38
  def ssh_add(key_ttl, key_path)
39
+ raise UnableToLoginError.new(Errno::ENOENT.new) unless File.exist? key_path
35
40
  `ssh-add -t #{key_ttl} #{key_path}`
36
41
  end
37
42
 
@@ -1,5 +1,5 @@
1
1
  module Vinz
2
2
  module Clortho
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -21,7 +21,11 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency 'octokit', '~> 4.1.1'
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.10'
24
+ spec.add_development_dependency 'guard'
25
+ spec.add_development_dependency 'guard-minitest'
24
26
  spec.add_development_dependency 'rake', '~> 10.0'
25
27
  spec.add_development_dependency 'mocha'
26
28
  spec.add_development_dependency 'minitest'
29
+ # spec.add_development_dependency 'minitest-reporters'
30
+ spec.add_development_dependency 'webmock'
27
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vinz-clortho
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liam Morley
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-10-02 00:00:00.000000000 Z
12
+ date: 2015-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: octokit
@@ -39,6 +39,34 @@ dependencies:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '1.10'
42
+ - !ruby/object:Gem::Dependency
43
+ name: guard
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: guard-minitest
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
42
70
  - !ruby/object:Gem::Dependency
43
71
  name: rake
44
72
  requirement: !ruby/object:Gem::Requirement
@@ -81,6 +109,20 @@ dependencies:
81
109
  - - ">="
82
110
  - !ruby/object:Gem::Version
83
111
  version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: webmock
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
84
126
  description:
85
127
  email:
86
128
  - lmorley@pivotal.io
@@ -96,6 +138,7 @@ files:
96
138
  - CODE_OF_CONDUCT.md
97
139
  - CONTRIBUTING.md
98
140
  - Gemfile
141
+ - Guardfile
99
142
  - LICENSE.md
100
143
  - README.md
101
144
  - Rakefile
@@ -104,6 +147,11 @@ files:
104
147
  - exe/git-ssh-login-all
105
148
  - exe/git-ssh-login-install-hook
106
149
  - lib/vinz/clortho.rb
150
+ - lib/vinz/clortho/cli.rb
151
+ - lib/vinz/clortho/cli/push_authenticated.rb
152
+ - lib/vinz/clortho/cli/ssh_login.rb
153
+ - lib/vinz/clortho/file_wrapper.rb
154
+ - lib/vinz/clortho/github_client_wrapper.rb
107
155
  - lib/vinz/clortho/github_key_uploader.rb
108
156
  - lib/vinz/clortho/ssh_key_path_manager.rb
109
157
  - lib/vinz/clortho/ssh_setup.rb
@@ -129,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
177
  version: '0'
130
178
  requirements: []
131
179
  rubyforge_project:
132
- rubygems_version: 2.4.8
180
+ rubygems_version: 2.4.5.1
133
181
  signing_key:
134
182
  specification_version: 4
135
183
  summary: Git plugin for managing SSH authentication