vinz-clortho 0.1.1 → 0.2.0

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: e824892bb1bc45ec04ca1320b0cbebe7438cdc9f
4
- data.tar.gz: b5337b8ee3585da400042b7cbb57c65479680e3a
3
+ metadata.gz: 1c7d1dc9a67cbe8dbb7fed2576a513dbbf1893a2
4
+ data.tar.gz: 0ae8f1d61cce96605e507ea754a29174c8ae0f2d
5
5
  SHA512:
6
- metadata.gz: 07751f3a4954589e3836f77e0bac528d4e2cd854683401770b9db6c288958b31ba24c6b1490eb6a0d1f70fb103f25bb2ac635188919ba859573af2baa16e4175
7
- data.tar.gz: 595234d57b070c7007425f67cef93cd1a2eb2b6b14c02e2b6379e3f8c6ee206d51981804282812c9ff6bf9d04f46016df2de3ed6dbf8d740ea3abe82d3f69d03
6
+ metadata.gz: 1c45a032491881e39f991ccc4c74d6c365fba9b73d31c28b23e7b13f18401e99010055758f5616a52486bb401e2216ecfeee2309a07cf195b355fd89ae190ab3
7
+ data.tar.gz: a94adbb62af2e8dc09556b71459631e2f662f8fcd02007b6ab86dc9740c2d02b698191b7c2084d2ac9344e1142ff7e1eb228ac51fc1d1927d09a14ea9a3fea3c
data/README.md CHANGED
@@ -15,13 +15,13 @@ sshkey_paths:
15
15
  ```
16
16
  See the [.git-authors](.git-authors) file in this repository as a full example.
17
17
 
18
- Vinz Clortho also requires the [Octokit](https://github.com/octokit/octokit.rb) rubygem for communicating with GitHub. You can install this via `gem install octokit`.
19
18
 
20
19
  ## Usage
21
- Run `git ssh-login (committer-initials)` to add the SSH key corresponding to the committer's initials. The key expiry is set to 12:30 PM if executed before 12:30 PM, 6:00 PM if executed after that but before 6:00 PM, or within 15 minutes if executed after 6:00 PM.
20
+
21
+ Run `git ssh-login [committer-initials]` to add the SSH key corresponding to the committer's initials. If no committer initials are included, then all available keys will be added. The key expiry is set to 12:30 PM if executed before 12:30 PM, 6:00 PM if executed after that but before 6:00 PM, or within 15 minutes if executed after 6:00 PM.
22
22
 
23
23
  ```
24
- Usage: git ssh-login [options] (committer-initials)
24
+ Usage: git ssh-login [options] [committer-initials]
25
25
 
26
26
  -h, --help Shows help
27
27
  -v, --version Returns version
@@ -1,4 +1,4 @@
1
1
  require 'vinz/clortho/version'
2
- require 'vinz/clortho/git_authors_manager'
2
+ require 'vinz/clortho/ssh_key_path_manager'
3
3
  require 'vinz/clortho/ssh_setup'
4
4
  require 'vinz/clortho/github_key_uploader'
@@ -4,7 +4,7 @@ module Vinz
4
4
  module Clortho
5
5
  class GitHubKeyUploader
6
6
  def initialize(initials, username, password)
7
- @manager = GitAuthorsManager.new
7
+ @manager = SSHKeyPathManager.new
8
8
  @initials = initials
9
9
  @username, @password = username, password
10
10
  end
@@ -0,0 +1,62 @@
1
+ require 'yaml'
2
+
3
+ module Vinz
4
+ module Clortho
5
+ class UserNotFoundError < StandardError
6
+ end
7
+
8
+ class KeyPathEntry
9
+ attr_reader :initials, :path
10
+ def initialize(path, initials = nil)
11
+ @initials = initials
12
+ @path = path
13
+ end
14
+ end
15
+
16
+ class SSHKeyPathManager
17
+ attr_reader :key_paths
18
+
19
+ DEFAULT_KEY_PATH = '/Volumes/*/.ssh/id_rsa'
20
+
21
+ def initialize
22
+ @key_paths = if git_authors_file.nil?
23
+ Dir[DEFAULT_KEY_PATH].map { |path| KeyPathEntry.new(path) }
24
+ else
25
+ git_authors = YAML::load_file(git_authors_file)
26
+ git_authors['sshkey_paths'].map do |initials, path|
27
+ KeyPathEntry.new(path, initials)
28
+ end
29
+ end
30
+ end
31
+
32
+ def key_path_for(initials)
33
+ raise ArgumentError.new('Committer initials are required') unless initials
34
+ key_path = @key_paths.detect { |kp| kp.initials == initials }
35
+ if key_path.nil?
36
+ raise UserNotFoundError.new(user_not_found_msg)
37
+ else
38
+ key_path.path
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def git_authors_file(current_dir = Dir.pwd)
45
+ @git_authors_file ||= begin
46
+ git_authors_location = File.join(current_dir, '.git-authors')
47
+ if File.exist?(git_authors_location)
48
+ git_authors_location
49
+ elsif current_dir == '/'
50
+ nil
51
+ else
52
+ git_authors_file(File.expand_path('..', current_dir))
53
+ end
54
+ end
55
+ end
56
+
57
+ def user_not_found_msg
58
+ "ERROR: Unable to find committer initials in .git-authors (check the \"sshkey_paths\" mapping for your initials)."
59
+ end
60
+ end
61
+ end
62
+ end
@@ -4,15 +4,19 @@ module Vinz
4
4
  attr_reader :key_expiry
5
5
 
6
6
  def initialize
7
- @git_authors_mgr = GitAuthorsManager.new
7
+ @ssh_key_path_mgr = SSHKeyPathManager.new
8
8
  end
9
9
 
10
- def login(initials)
10
+ def login(initials = nil)
11
11
  set_key_expiry
12
12
  key_ttl = @key_expiry.to_i - Time.now.to_i
13
- key_path = @git_authors_mgr.key_path_for initials
14
- raise Errno::ENOENT.new unless File.exist? key_path
15
- ssh_add(key_ttl, key_path)
13
+ if initials.nil?
14
+ login_all key_ttl
15
+ else
16
+ key_path = @ssh_key_path_mgr.key_path_for initials
17
+ raise Errno::ENOENT.new unless File.exist? key_path
18
+ ssh_add(key_ttl, key_path)
19
+ end
16
20
  end
17
21
 
18
22
  def login_all(key_ttl = nil)
@@ -21,7 +25,8 @@ module Vinz
21
25
  key_ttl = @key_expiry.to_i - Time.now.to_i
22
26
  end
23
27
 
24
- @git_authors_mgr.all_key_paths.values.each do |path|
28
+ @ssh_key_path_mgr.key_paths.each do |key_path|
29
+ path = key_path.path
25
30
  ssh_add(key_ttl, path) if File.exist?(path)
26
31
  end
27
32
  end
@@ -31,11 +36,11 @@ module Vinz
31
36
  end
32
37
 
33
38
  def usage_msg
34
- committers_and_keypaths = @git_authors_mgr.all_key_paths.map do |committer_initials, keypath|
35
- "\t#{committer_initials} : #{keypath}"
39
+ committers_and_keypaths = @ssh_key_path_mgr.key_paths.map do |key_path|
40
+ "\t#{key_path.initials} : #{key_path.path}"
36
41
  end
37
42
  msg = <<-MSG
38
- Usage: git ssh-login [options] (committer-initials)
43
+ Usage: git ssh-login [options] [committer-initials]
39
44
 
40
45
  known committers:
41
46
  #{committers_and_keypaths.join("\n")}
@@ -1,5 +1,5 @@
1
1
  module Vinz
2
2
  module Clortho
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  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.1.1
4
+ version: 0.2.0
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-01 00:00:00.000000000 Z
12
+ date: 2015-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: octokit
@@ -104,8 +104,8 @@ files:
104
104
  - exe/git-ssh-login-all
105
105
  - exe/git-ssh-login-install-hook
106
106
  - lib/vinz/clortho.rb
107
- - lib/vinz/clortho/git_authors_manager.rb
108
107
  - lib/vinz/clortho/github_key_uploader.rb
108
+ - lib/vinz/clortho/ssh_key_path_manager.rb
109
109
  - lib/vinz/clortho/ssh_setup.rb
110
110
  - lib/vinz/clortho/version.rb
111
111
  - vinz-clortho.gemspec
@@ -1,40 +0,0 @@
1
- require 'yaml'
2
-
3
- module Vinz
4
- module Clortho
5
- class UserNotFoundError < StandardError
6
- end
7
-
8
- class GitAuthorsManager
9
- def initialize
10
- @git_authors = YAML::load_file(git_authors_file)
11
- end
12
-
13
- def all_key_paths
14
- @git_authors['sshkey_paths']
15
- end
16
-
17
- def key_path_for(initials)
18
- raise ArgumentError.new('Committer initials are required') unless initials
19
- @git_authors['sshkey_paths'][initials] or raise UserNotFoundError.new(user_not_found_msg)
20
- end
21
-
22
- private
23
-
24
- def git_authors_file(current_dir = Dir.pwd)
25
- git_authors_location = File.join(current_dir, '.git-authors')
26
- if File.exist?(git_authors_location)
27
- git_authors_location
28
- elsif current_dir == '/'
29
- raise Errno::ENOENT.new
30
- else
31
- git_authors_file(File.expand_path('..', current_dir))
32
- end
33
- end
34
-
35
- def user_not_found_msg
36
- "ERROR: Unable to find committer initials in mapping (check the \"sshkey_paths\" mapping for your initials)."
37
- end
38
- end
39
- end
40
- end