vinz-clortho 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/CONTRIBUTING.md +9 -0
- data/Gemfile +4 -0
- data/LICENSE.md +21 -0
- data/README.md +31 -0
- data/Rakefile +10 -0
- data/exe/git-push-authenticated +10 -0
- data/exe/git-ssh-login +46 -0
- data/exe/git-ssh-login-all +9 -0
- data/exe/git-ssh-login-install-hook +9 -0
- data/lib/vinz/clortho.rb +4 -0
- data/lib/vinz/clortho/git_authors_manager.rb +40 -0
- data/lib/vinz/clortho/github_key_uploader.rb +23 -0
- data/lib/vinz/clortho/ssh_setup.rb +64 -0
- data/lib/vinz/clortho/version.rb +5 -0
- data/vinz-clortho.gemspec +27 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e824892bb1bc45ec04ca1320b0cbebe7438cdc9f
|
4
|
+
data.tar.gz: b5337b8ee3585da400042b7cbb57c65479680e3a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 07751f3a4954589e3836f77e0bac528d4e2cd854683401770b9db6c288958b31ba24c6b1490eb6a0d1f70fb103f25bb2ac635188919ba859573af2baa16e4175
|
7
|
+
data.tar.gz: 595234d57b070c7007425f67cef93cd1a2eb2b6b14c02e2b6379e3f8c6ee206d51981804282812c9ff6bf9d04f46016df2de3ed6dbf8d740ea3abe82d3f69d03
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
* Fork the [project](https://github.com/pivotal/clortho)
|
4
|
+
* Create a feature branch
|
5
|
+
* Make sure any new code added to `lib/` has appropriate tests in `test/`
|
6
|
+
* Rebase on master
|
7
|
+
* Issue a [pull request](https://github.com/pivotal/clortho/pulls)
|
8
|
+
|
9
|
+
Feel free to create new [issues](https://github.com/pivotal/clortho/issues). If you'd like to see what else is in our pipeline, look at our public [Tracker](https://www.pivotaltracker.com/n/projects/1437254).
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Pivotal Labs
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Vinz Clortho
|
2
|
+
|
3
|
+
<img src="http://i.giphy.com/Sf0xvEgdWyraU.gif" alt="Vinz Clortho" width="100%">
|
4
|
+
|
5
|
+
Vinz Clortho is a Ruby-based tool for managing SSH authentication when dealing with git.
|
6
|
+
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
Vinz Clortho requires a `.git-authors` file to be present, similar in format to [git-duet](https://github.com/git-duet/git-duet) and [git-pair](https://github.com/pivotal/git_scripts). In addition to authors and email addresses, Vinz Clortho will look for a `sshkey_paths` entry where each pair of initials below points to the location of a private key (perhaps on a flash drive). For example:
|
10
|
+
|
11
|
+
``` yaml
|
12
|
+
sshkey_paths:
|
13
|
+
jd: /Volumes/jdoe/.ssh/id_rsa
|
14
|
+
fb: /Volumes/fbar/.ssh/id_rsa
|
15
|
+
```
|
16
|
+
See the [.git-authors](.git-authors) file in this repository as a full example.
|
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
|
+
|
20
|
+
## 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.
|
22
|
+
|
23
|
+
```
|
24
|
+
Usage: git ssh-login [options] (committer-initials)
|
25
|
+
|
26
|
+
-h, --help Shows help
|
27
|
+
-v, --version Returns version
|
28
|
+
--add-to-github Adds a public key to GitHub
|
29
|
+
```
|
30
|
+
|
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).
|
data/Rakefile
ADDED
data/exe/git-ssh-login
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require 'io/console'
|
4
|
+
require 'vinz/clortho'
|
5
|
+
|
6
|
+
begin
|
7
|
+
ssh_setup = Vinz::Clortho::SSHSetup.new
|
8
|
+
initials = ARGV[0]
|
9
|
+
|
10
|
+
parser = OptionParser.new do |opts|
|
11
|
+
opts.banner = ssh_setup.usage_msg
|
12
|
+
|
13
|
+
opts.on('-h', '--help', 'Shows help') do |v|
|
14
|
+
puts parser
|
15
|
+
exit 0
|
16
|
+
end
|
17
|
+
opts.on('-v', '--version', 'Returns version') do |v|
|
18
|
+
puts Vinz::Clortho::VERSION
|
19
|
+
exit 0
|
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
|
31
|
+
exit 0
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
parser.parse!
|
36
|
+
ssh_setup.login(initials)
|
37
|
+
rescue OptionParser::InvalidOption => e
|
38
|
+
puts parser
|
39
|
+
exit 1
|
40
|
+
rescue => e
|
41
|
+
puts e.message
|
42
|
+
puts parser
|
43
|
+
exit (e.is_a? Vinz::Clortho::UserNotFoundError) ? 2 : 1
|
44
|
+
end
|
45
|
+
|
46
|
+
puts "Key will expire at #{ssh_setup.key_expiry}"
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
path_to_post_commit_hook = File.join(`git rev-parse --show-toplevel`.chomp, '.git', 'hooks', 'post-commit')
|
3
|
+
|
4
|
+
cmd = orig_cmd = "exec git-ssh-login-all"
|
5
|
+
cmd = "#!/bin/sh\n#{cmd}" unless File.exist?(path_to_post_commit_hook)
|
6
|
+
|
7
|
+
File.open(path_to_post_commit_hook, 'a+', 0755) do |file|
|
8
|
+
file.write cmd unless file.read.include? orig_cmd
|
9
|
+
end
|
data/lib/vinz/clortho.rb
ADDED
@@ -0,0 +1,40 @@
|
|
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
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
|
3
|
+
module Vinz
|
4
|
+
module Clortho
|
5
|
+
class GitHubKeyUploader
|
6
|
+
def initialize(initials, username, password)
|
7
|
+
@manager = GitAuthorsManager.new
|
8
|
+
@initials = initials
|
9
|
+
@username, @password = username, password
|
10
|
+
end
|
11
|
+
|
12
|
+
def upload(title)
|
13
|
+
key = File.open("#{@manager.key_path_for(@initials)}.pub", "r").read
|
14
|
+
client.add_key(title, key)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def client
|
19
|
+
@client ||= Octokit::Client.new(login: @username, password: @password)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Vinz
|
2
|
+
module Clortho
|
3
|
+
class SSHSetup
|
4
|
+
attr_reader :key_expiry
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@git_authors_mgr = GitAuthorsManager.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def login(initials)
|
11
|
+
set_key_expiry
|
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)
|
16
|
+
end
|
17
|
+
|
18
|
+
def login_all(key_ttl = nil)
|
19
|
+
if key_ttl.nil?
|
20
|
+
set_key_expiry
|
21
|
+
key_ttl = @key_expiry.to_i - Time.now.to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
@git_authors_mgr.all_key_paths.values.each do |path|
|
25
|
+
ssh_add(key_ttl, path) if File.exist?(path)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def ssh_add(key_ttl, key_path)
|
30
|
+
`ssh-add -t #{key_ttl} #{key_path}`
|
31
|
+
end
|
32
|
+
|
33
|
+
def usage_msg
|
34
|
+
committers_and_keypaths = @git_authors_mgr.all_key_paths.map do |committer_initials, keypath|
|
35
|
+
"\t#{committer_initials} : #{keypath}"
|
36
|
+
end
|
37
|
+
msg = <<-MSG
|
38
|
+
Usage: git ssh-login [options] (committer-initials)
|
39
|
+
|
40
|
+
known committers:
|
41
|
+
#{committers_and_keypaths.join("\n")}
|
42
|
+
|
43
|
+
If there is no mapping from your initials to your keypath, add it to .git-authors.
|
44
|
+
MSG
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def set_key_expiry
|
49
|
+
now = Time.now
|
50
|
+
lunchtime = Time.new(now.year, now.month, now.day, 12, 30)
|
51
|
+
end_of_day = Time.new(now.year, now.month, now.day, 18, 0)
|
52
|
+
in_fifteen_minutes = now + (60 * 15)
|
53
|
+
|
54
|
+
@key_expiry = if now < lunchtime
|
55
|
+
lunchtime
|
56
|
+
elsif now < end_of_day
|
57
|
+
end_of_day
|
58
|
+
else
|
59
|
+
in_fifteen_minutes
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vinz/clortho/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'vinz-clortho'
|
8
|
+
spec.version = Vinz::Clortho::VERSION
|
9
|
+
spec.authors = ['Liam Morley', 'Navya Canumalla']
|
10
|
+
spec.email = %w(lmorley@pivotal.io ncanumalla@pivotal.io)
|
11
|
+
|
12
|
+
spec.summary = %q{Git plugin for managing SSH authentication}
|
13
|
+
spec.homepage = 'https://github.com/pivotal/clortho'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test/|\.)}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'octokit', '~> 4.1.1'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'mocha'
|
26
|
+
spec.add_development_dependency 'minitest'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vinz-clortho
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Liam Morley
|
8
|
+
- Navya Canumalla
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: octokit
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 4.1.1
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 4.1.1
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.10'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.10'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '10.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: mocha
|
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'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: minitest
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description:
|
85
|
+
email:
|
86
|
+
- lmorley@pivotal.io
|
87
|
+
- ncanumalla@pivotal.io
|
88
|
+
executables:
|
89
|
+
- git-push-authenticated
|
90
|
+
- git-ssh-login
|
91
|
+
- git-ssh-login-all
|
92
|
+
- git-ssh-login-install-hook
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- CODE_OF_CONDUCT.md
|
97
|
+
- CONTRIBUTING.md
|
98
|
+
- Gemfile
|
99
|
+
- LICENSE.md
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- exe/git-push-authenticated
|
103
|
+
- exe/git-ssh-login
|
104
|
+
- exe/git-ssh-login-all
|
105
|
+
- exe/git-ssh-login-install-hook
|
106
|
+
- lib/vinz/clortho.rb
|
107
|
+
- lib/vinz/clortho/git_authors_manager.rb
|
108
|
+
- lib/vinz/clortho/github_key_uploader.rb
|
109
|
+
- lib/vinz/clortho/ssh_setup.rb
|
110
|
+
- lib/vinz/clortho/version.rb
|
111
|
+
- vinz-clortho.gemspec
|
112
|
+
homepage: https://github.com/pivotal/clortho
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.4.8
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Git plugin for managing SSH authentication
|
136
|
+
test_files: []
|