vagrant-github_key_manager 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +11 -0
- data/lib/vagrant-github_key_manager.rb +45 -0
- data/lib/vagrant-github_key_manager/action/add_key.rb +80 -0
- data/lib/vagrant-github_key_manager/action/delete_key.rb +51 -0
- data/lib/vagrant-github_key_manager/config.rb +17 -0
- data/lib/vagrant-github_key_manager/plugin.rb +40 -0
- data/lib/vagrant-github_key_manager/version.rb +5 -0
- data/lib/vagrant/ui.rb +30 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/vagrant-github_key_manager/config_spec.rb +17 -0
- data/vagrant-github_key_manager.gemspec +27 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d83861fc16c3cfe4a609bb05ee59b52e0f6b32be
|
4
|
+
data.tar.gz: 1ecc87fcb13febb09cf727a278c164fa92f4502e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 392ad702912f2d66ff41578848b2c370a78e3bb71282b324d68e82894f9568b4635bfdef39b662dd0020755c723fb93f9bd0d7d7c853ec804a4632beeb80eab0
|
7
|
+
data.tar.gz: f4f9c9566c55fa53b67e1fee89361f0775c226f42da8148365a18bbd334f10c6dea2e5143a8211fc7175ec9fecc4832491caec99668f3c8c39d98463908b5880
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in vagrant-github_key_manager.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'rspec'
|
8
|
+
gem 'rspec-core'
|
9
|
+
gem 'rake'
|
10
|
+
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => "v1.3.5"
|
11
|
+
end
|
12
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 haruyama-makoto
|
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,33 @@
|
|
1
|
+
# Vagrant::GithubKeyManager
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'vagrant-github_key_manager'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install vagrant-github_key_manager
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Reference
|
24
|
+
* https://github.com/jeremygiberson/vagrant-gitcredentials
|
25
|
+
* http://developer.github.com/v3/
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'vagrant/ui'
|
2
|
+
require "vagrant-github_key_manager/version"
|
3
|
+
require "vagrant-github_key_manager/plugin"
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module GithubKeyManager
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'vagrant/ui'
|
11
|
+
require 'io/console'
|
12
|
+
|
13
|
+
module Vagrant
|
14
|
+
module UI
|
15
|
+
class Basic
|
16
|
+
def ask(message, opts=nil)
|
17
|
+
super(message)
|
18
|
+
|
19
|
+
# We can't ask questions when the output isn't a TTY.
|
20
|
+
raise Errors::UIExpectsTTY if !$stdin.tty? && !Vagrant::Util::Platform.cygwin?
|
21
|
+
|
22
|
+
# Setup the options so that the new line is suppressed
|
23
|
+
opts ||= {}
|
24
|
+
opts[:new_line] = false if !opts.has_key?(:new_line)
|
25
|
+
opts[:prefix] = false if !opts.has_key?(:prefix)
|
26
|
+
|
27
|
+
# Output the data
|
28
|
+
say(:info, message, opts)
|
29
|
+
|
30
|
+
# Get the results and chomp off the newline. We do a logical OR
|
31
|
+
# here because `gets` can return a nil, for example in the case
|
32
|
+
# that ctrl-D is pressed on the input.
|
33
|
+
input = if opts[:echo] == false
|
34
|
+
noecho_input = $stdin.noecho(&:gets) || ""
|
35
|
+
print "\n"
|
36
|
+
noecho_input
|
37
|
+
else
|
38
|
+
$stdin.gets || ""
|
39
|
+
end
|
40
|
+
input.chomp
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
require 'json'
|
3
|
+
require 'net/https'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module GithubKeyManager
|
8
|
+
module Action
|
9
|
+
class AddKey
|
10
|
+
|
11
|
+
def initialize(app, env)
|
12
|
+
@app = app
|
13
|
+
@ui = env[:ui]
|
14
|
+
@machine = env[:machine]
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
config = env[:global_config].github_key_manager
|
19
|
+
github_api_url = config.github_api_url
|
20
|
+
ssh_key_title = config.ssh_key_title
|
21
|
+
|
22
|
+
# if we have a successful response, skip generating key
|
23
|
+
unless @machine.communicate.test('test -f ~/.ssh/github_key_id')
|
24
|
+
|
25
|
+
@ui.info("We will now generate an ssh key and add it to your github account.")
|
26
|
+
|
27
|
+
unless @machine.communicate.test('test -f ~/.ssh/github_rsa')
|
28
|
+
@machine.communicate.execute('ssh-keygen -N "" -f ~/.ssh/github_rsa')
|
29
|
+
@ui.info('Generate ssh key for github')
|
30
|
+
end
|
31
|
+
|
32
|
+
@ui.info("Register ssh key to your github account.")
|
33
|
+
github_username = @ui.ask("What is your github account name? ")
|
34
|
+
github_password = @ui.ask("What is your github account password? (not stored) ", echo: false)
|
35
|
+
|
36
|
+
execute_script = <<EOF
|
37
|
+
require "rubygems"
|
38
|
+
require "json"
|
39
|
+
require "net/https"
|
40
|
+
require "uri"
|
41
|
+
|
42
|
+
ssh_pub_key = File.read File.expand_path("~/.ssh/github_rsa.pub")
|
43
|
+
|
44
|
+
uri = URI.parse "#{github_api_url}"
|
45
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
46
|
+
https.use_ssl = uri.scheme == "https"
|
47
|
+
https.start do |https|
|
48
|
+
req = Net::HTTP::Post.new(uri.path)
|
49
|
+
req.basic_auth "#{github_username}", "#{github_password}"
|
50
|
+
github_ssh_key_settings = {
|
51
|
+
:title => "#{ssh_key_title}",
|
52
|
+
:key => ssh_pub_key
|
53
|
+
}
|
54
|
+
req.body = JSON.generate github_ssh_key_settings
|
55
|
+
|
56
|
+
response = https.request(req)
|
57
|
+
res_data = JSON.parse response.body
|
58
|
+
github_ssh_key_id = res_data["id"]
|
59
|
+
File.open(File.expand_path("~/.ssh/github_key_id"), "w") do |file|
|
60
|
+
file.puts github_ssh_key_id
|
61
|
+
end
|
62
|
+
end
|
63
|
+
`ssh-add -D`
|
64
|
+
`ssh-add ~/.ssh/github_rsa`
|
65
|
+
EOF
|
66
|
+
@machine.communicate.execute("ruby -e '#{execute_script}'")
|
67
|
+
#@machine.communicate.execute('eval $(ssh-agent)')
|
68
|
+
#@machine.communicate.execute('ssh-add ~/.ssh/github_rsa')
|
69
|
+
@ui.info("register ssh key to github")
|
70
|
+
end
|
71
|
+
|
72
|
+
@app.call(env)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module GithubKeyManager
|
3
|
+
module Action
|
4
|
+
class DeleteKey
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@ui = env[:ui]
|
8
|
+
@machine = env[:machine]
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
config = env[:global_config].github_key_manager
|
13
|
+
github_api_url = config.github_api_url
|
14
|
+
|
15
|
+
|
16
|
+
#@machine.communicate.execute("curl -X DELETE -u #{gitUsername}:#{gitPassword} #{endpoint}")
|
17
|
+
if @machine.communicate.test('test -f ~/.ssh/github_key_id')
|
18
|
+
@ui.info("We will now delete the registered ssh key to your github account.")
|
19
|
+
github_username = @ui.ask("What is your github account name? ")
|
20
|
+
github_password = @ui.ask("What is your github account password? (not stored) ", echo: false)
|
21
|
+
|
22
|
+
execute_script = <<EOF
|
23
|
+
require "rubygems"
|
24
|
+
require "json"
|
25
|
+
require "net/https"
|
26
|
+
require "uri"
|
27
|
+
|
28
|
+
github_ssh_key_id = (File.read File.expand_path("~/.ssh/github_key_id")).chomp
|
29
|
+
|
30
|
+
uri = URI.parse "#{github_api_url}"
|
31
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
32
|
+
https.use_ssl = uri.scheme == "https"
|
33
|
+
https.start do |https|
|
34
|
+
req = Net::HTTP::Delete.new("\#{uri.path}/\#{github_ssh_key_id}")
|
35
|
+
req.basic_auth "#{github_username}", "#{github_password}"
|
36
|
+
response = https.request(req)
|
37
|
+
File.delete File.expand_path("~/.ssh/github_key_id")
|
38
|
+
end
|
39
|
+
EOF
|
40
|
+
@machine.communicate.execute("ruby -e '#{execute_script}'")
|
41
|
+
@ui.info("delete ssh key")
|
42
|
+
end
|
43
|
+
@app.call(env)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module GithubKeyManager
|
5
|
+
class Config < Vagrant.plugin("2", :config)
|
6
|
+
attr_accessor :github_api_url
|
7
|
+
attr_accessor :ssh_key_title
|
8
|
+
|
9
|
+
def initialize(region_specific=false)
|
10
|
+
@github_api_url = 'https://api.github.com/user/keys'
|
11
|
+
@ssh_key_title = 'vagrant provision key'
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
begin
|
2
|
+
require "vagrant"
|
3
|
+
rescue LoadError
|
4
|
+
raise "The Vagrant AWS plugin must be run within Vagrant."
|
5
|
+
end
|
6
|
+
|
7
|
+
# This is a sanity check to make sure no one is attempting to install
|
8
|
+
# this into an early Vagrant version.
|
9
|
+
if Vagrant::VERSION < "1.2.0"
|
10
|
+
raise "The Vagrant AWS plugin is only compatible with Vagrant 1.2+"
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'vagrant-github_key_manager/action/add_key'
|
14
|
+
require 'vagrant-github_key_manager/action/delete_key'
|
15
|
+
|
16
|
+
module VagrantPlugins
|
17
|
+
module GithubKeyManager
|
18
|
+
class Plugin < Vagrant.plugin("2")
|
19
|
+
name 'vagrant-github_key_manager'
|
20
|
+
description <<-DESC
|
21
|
+
DESC
|
22
|
+
|
23
|
+
config 'github_key_manager' do
|
24
|
+
require_relative "config"
|
25
|
+
Config
|
26
|
+
end
|
27
|
+
|
28
|
+
action_hook(:github_key_manager, :machine_action_up) do |hook|
|
29
|
+
hook.append Action::AddKey
|
30
|
+
end
|
31
|
+
|
32
|
+
action_hook(:github_key_manager, :machine_action_destroy) do |hook|
|
33
|
+
hook.prepend Action::DeleteKey
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
data/lib/vagrant/ui.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'vagrant/ui'
|
2
|
+
require 'io/console'
|
3
|
+
|
4
|
+
module Vagrant
|
5
|
+
module UI
|
6
|
+
class Basic
|
7
|
+
def ask_noecho(message, opts=nil)
|
8
|
+
super(message)
|
9
|
+
|
10
|
+
# We can't ask questions when the output isn't a TTY.
|
11
|
+
raise Errors::UIExpectsTTY if !$stdin.tty? && !Vagrant::Util::Platform.cygwin?
|
12
|
+
|
13
|
+
# Setup the options so that the new line is suppressed
|
14
|
+
opts ||= {}
|
15
|
+
opts[:new_line] = false if !opts.has_key?(:new_line)
|
16
|
+
opts[:prefix] = false if !opts.has_key?(:prefix)
|
17
|
+
|
18
|
+
# Output the data
|
19
|
+
say(:info, message, opts)
|
20
|
+
|
21
|
+
# Get the results and chomp off the newline. We do a logical OR
|
22
|
+
# here because `gets` can return a nil, for example in the case
|
23
|
+
# that ctrl-D is pressed on the input.
|
24
|
+
input = $stdin.noecho(&:gets) || ""
|
25
|
+
input.chomp
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
Bundler.setup(:default, :test)
|
6
|
+
Bundler.require(:default, :test)
|
7
|
+
|
8
|
+
require 'rspec'
|
9
|
+
|
10
|
+
$TESTING=true
|
11
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
12
|
+
require 'vagrant-github_key_manager'
|
13
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "vagrant-github_key_manager/config"
|
2
|
+
|
3
|
+
describe VagrantPlugins::GithubKeyManager::Config do
|
4
|
+
let(:instance) { described_class.new }
|
5
|
+
|
6
|
+
describe :initialize do
|
7
|
+
|
8
|
+
context 'default' do
|
9
|
+
subject {instance}
|
10
|
+
it do
|
11
|
+
expect(instance.github_api_url).to eq 'https://api.github.com/user/keys'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -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 'vagrant-github_key_manager/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-github_key_manager"
|
8
|
+
spec.version = VagrantPlugins::GithubKeyManager::VERSION
|
9
|
+
spec.authors = ["SpringMT"]
|
10
|
+
spec.email = ["today.is.sky.blue.sky@gamil.com"]
|
11
|
+
spec.summary = %q{vagrant plugin for github key management}
|
12
|
+
spec.homepage = "https://github.com/SpringMT/vagrant-github_key_manager"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
|
23
|
+
spec.description = <<description
|
24
|
+
vagrant plugin for github key management
|
25
|
+
description
|
26
|
+
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-github_key_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SpringMT
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: |
|
42
|
+
vagrant plugin for github key management
|
43
|
+
email:
|
44
|
+
- today.is.sky.blue.sky@gamil.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/vagrant-github_key_manager.rb
|
55
|
+
- lib/vagrant-github_key_manager/action/add_key.rb
|
56
|
+
- lib/vagrant-github_key_manager/action/delete_key.rb
|
57
|
+
- lib/vagrant-github_key_manager/config.rb
|
58
|
+
- lib/vagrant-github_key_manager/plugin.rb
|
59
|
+
- lib/vagrant-github_key_manager/version.rb
|
60
|
+
- lib/vagrant/ui.rb
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
- spec/vagrant-github_key_manager/config_spec.rb
|
63
|
+
- vagrant-github_key_manager.gemspec
|
64
|
+
homepage: https://github.com/SpringMT/vagrant-github_key_manager
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.0.3
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: vagrant plugin for github key management
|
88
|
+
test_files:
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
- spec/vagrant-github_key_manager/config_spec.rb
|