github_authorized_keys 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/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/bin/github_authorized_keys +6 -0
- data/examples/github_authorized_keys.yml +5 -0
- data/github_authorized_keys.gemspec +26 -0
- data/lib/github_authorized_keys.rb +70 -0
- data/lib/github_authorized_keys/version.rb +3 -0
- data/spec/github_authorized_keys_spec.rb +49 -0
- data/spec/spec_helper.rb +16 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d27f9e695c82ac4fa6a37c54df29d2b214af3e26
|
4
|
+
data.tar.gz: cf82c49da946569be4bba8e50da2278afc30e8fe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ada77ca609b770fc391087cb676321dfad30aa318ec5f1f2ce08d611289e455c460dbe2666859a4d13bd22e2e1ac21bf13ad67fa03294a466e8f66bd46a866f0
|
7
|
+
data.tar.gz: 0a57a72e14f611e6c8840b220f2e7828471733d84fd8c2c26673dcbf6ffc3e33b421688af412c8506eb02a01a10c4cb14a36eb30addaaf3f65de7ad9f3222ad8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Michael D'Auria
|
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,45 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/crowdtap/github_authorized_keys.png)](https://travis-ci.org/crowdtap/github_authorized_keys)
|
2
|
+
|
3
|
+
# GithubAuthorizedKeys
|
4
|
+
|
5
|
+
This will enable you to automatically generate an authorized_keys file based on members of a GitHub organization.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Usually you will want this as a global gem:
|
10
|
+
|
11
|
+
$ gem install github_authorized_keys
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Once installed, you will have a binary that you can use:
|
16
|
+
|
17
|
+
$ github_authorized_keys
|
18
|
+
|
19
|
+
By default, it will search for a configuration in your home folder `~/.github_authorized_keys.yml`.
|
20
|
+
If you would like to use an alternative, simply pass it along on the command line:
|
21
|
+
|
22
|
+
$ github_authorized_keys my_github_authorized_keys.yml
|
23
|
+
|
24
|
+
The executable will output to `STDOUT`, so if you would like to do this is cron for example:
|
25
|
+
|
26
|
+
@daily github_authorized_keys > /home/deploy/.ssh/authorized_keys
|
27
|
+
|
28
|
+
## Configuration
|
29
|
+
|
30
|
+
The format looks like so:
|
31
|
+
|
32
|
+
---
|
33
|
+
organization: 'my-organization'
|
34
|
+
oauth_token: 'github-oauth-token'
|
35
|
+
additional_keys:
|
36
|
+
- '# a comment'
|
37
|
+
- 'ssh-rsa 1'
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'github_authorized_keys/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "github_authorized_keys"
|
8
|
+
spec.version = GithubAuthorizedKeys::VERSION
|
9
|
+
spec.authors = ["Michael D'Auria"]
|
10
|
+
spec.email = ["michael.dauria@gmail.com"]
|
11
|
+
spec.description = %q{Pulls all of the keys for all members of an organization from GitHub}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = "https://github.com/crowdtap/github_authorized_keys"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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 "json", "~> 1.3"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module GithubAuthorizedKeys
|
6
|
+
class CLI
|
7
|
+
attr_reader :config, :headers
|
8
|
+
|
9
|
+
def run(config_file)
|
10
|
+
begin
|
11
|
+
load_config(config_file)
|
12
|
+
@headers = {'User-Agent' => "#{config['organization']} authorized_keys generator"}
|
13
|
+
|
14
|
+
authorized_keys = [
|
15
|
+
'### THIS FILE IS AUTOMATICALLY GENERATED',
|
16
|
+
]
|
17
|
+
if config.include?('additional_keys')
|
18
|
+
authorized_keys.concat(config['additional_keys'])
|
19
|
+
end
|
20
|
+
|
21
|
+
fetch_members.each do |member|
|
22
|
+
authorized_keys << "# #{member['login']}"
|
23
|
+
fetch_keys(member['login']).each do |ssh_key|
|
24
|
+
authorized_keys << ssh_key['key']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
authorized_keys.join("\n")
|
29
|
+
rescue Errno::ENOENT
|
30
|
+
$stderr.puts "Unable to read configuration file: '#{config_file}'" unless $testing
|
31
|
+
read_original_authorized_keys
|
32
|
+
rescue
|
33
|
+
read_original_authorized_keys
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def github_http_get(url, headers)
|
38
|
+
unless @github_http
|
39
|
+
@github_http = Net::HTTP.new('api.github.com', 443)
|
40
|
+
@github_http.use_ssl = true
|
41
|
+
@github_http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
42
|
+
end
|
43
|
+
|
44
|
+
JSON.parse(@github_http.request_get(url, headers).body)
|
45
|
+
end
|
46
|
+
|
47
|
+
def fetch_members
|
48
|
+
github_http_get("/orgs/#{config['organization']}/members?#{config['oauth_token']}", headers)
|
49
|
+
end
|
50
|
+
|
51
|
+
def fetch_keys(login)
|
52
|
+
github_http_get("/users/#{login}/keys?#{config['oauth_token']}", headers)
|
53
|
+
end
|
54
|
+
|
55
|
+
def load_config(config_file)
|
56
|
+
config_file ||= "#{ENV['HOME']}/.github_authorized_keys.yml"
|
57
|
+
@config = YAML.load_file(config_file)
|
58
|
+
end
|
59
|
+
|
60
|
+
def read_original_authorized_keys
|
61
|
+
File.open("#{ENV['HOME']}/.ssh/authorized_keys") do |file|
|
62
|
+
while(line = file.gets)
|
63
|
+
puts line
|
64
|
+
end
|
65
|
+
end
|
66
|
+
rescue
|
67
|
+
'' # file does not exist
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GithubAuthorizedKeys::CLI do
|
4
|
+
before do
|
5
|
+
@config = { 'organization' => 'some-org', 'oauth_token' => 'token' }
|
6
|
+
subject.stub(:load_config)
|
7
|
+
subject.stub(:fetch_members => [
|
8
|
+
{'login'=>'first'},
|
9
|
+
{'login'=>'second'},
|
10
|
+
{'login'=>'third'}
|
11
|
+
])
|
12
|
+
subject.stub(:fetch_keys).and_return(
|
13
|
+
[{'key' => 'ssh-rsa 1'}],
|
14
|
+
[{'key' => 'ssh-rsa 2'}],
|
15
|
+
[{'key' => 'ssh-rsa 3'},{'key' => 'ssh-rsa 4'}]
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "will spit out the original authorized_keys file on error" do
|
20
|
+
subject.stub(:read_original_authorized_keys => 'original authorized keys')
|
21
|
+
subject.run('nonexistant').should == 'original authorized keys'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "is ok that there were no provided additional keys" do
|
25
|
+
subject.stub(:config => @config)
|
26
|
+
expected = [
|
27
|
+
'### THIS FILE IS AUTOMATICALLY GENERATED',
|
28
|
+
'# first', 'ssh-rsa 1',
|
29
|
+
'# second', 'ssh-rsa 2',
|
30
|
+
'# third', 'ssh-rsa 3', 'ssh-rsa 4'
|
31
|
+
].join("\n")
|
32
|
+
|
33
|
+
subject.run(nil).should == expected
|
34
|
+
end
|
35
|
+
|
36
|
+
it "generates a proper authorized_keys file" do
|
37
|
+
@config.merge!({'additional_keys'=>['ssh-rsa a','ssh-rsa b']})
|
38
|
+
subject.stub(:config => @config)
|
39
|
+
expected = [
|
40
|
+
'### THIS FILE IS AUTOMATICALLY GENERATED',
|
41
|
+
'ssh-rsa a', 'ssh-rsa b',
|
42
|
+
'# first', 'ssh-rsa 1',
|
43
|
+
'# second', 'ssh-rsa 2',
|
44
|
+
'# third', 'ssh-rsa 3', 'ssh-rsa 4'
|
45
|
+
].join("\n")
|
46
|
+
|
47
|
+
subject.run(nil).should == expected
|
48
|
+
end
|
49
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$testing = true
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.require
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
config.filter_run :focus
|
10
|
+
|
11
|
+
# Run specs in random order to surface order dependencies. If you find an
|
12
|
+
# order dependency and want to debug it, you can fix the order by providing
|
13
|
+
# the seed, which is printed after each run.
|
14
|
+
# --seed 1234
|
15
|
+
config.order = 'default'
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github_authorized_keys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael D'Auria
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2013-05-29 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
prerelease: false
|
16
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: "1.3"
|
21
|
+
name: json
|
22
|
+
type: :runtime
|
23
|
+
requirement: *id001
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: "1.3"
|
31
|
+
name: bundler
|
32
|
+
type: :development
|
33
|
+
requirement: *id002
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- &id004
|
39
|
+
- ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
42
|
+
name: rake
|
43
|
+
type: :development
|
44
|
+
requirement: *id003
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- *id004
|
50
|
+
name: rspec
|
51
|
+
type: :development
|
52
|
+
requirement: *id005
|
53
|
+
description: Pulls all of the keys for all members of an organization from GitHub
|
54
|
+
email:
|
55
|
+
- michael.dauria@gmail.com
|
56
|
+
executables:
|
57
|
+
- github_authorized_keys
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .rspec
|
65
|
+
- .travis.yml
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/github_authorized_keys
|
71
|
+
- examples/github_authorized_keys.yml
|
72
|
+
- github_authorized_keys.gemspec
|
73
|
+
- lib/github_authorized_keys.rb
|
74
|
+
- lib/github_authorized_keys/version.rb
|
75
|
+
- spec/github_authorized_keys_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
homepage: https://github.com/crowdtap/github_authorized_keys
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- *id004
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- *id004
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.0.3
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Pulls all of the keys for all members of an organization from GitHub
|
100
|
+
test_files:
|
101
|
+
- spec/github_authorized_keys_spec.rb
|
102
|
+
- spec/spec_helper.rb
|