sandman 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +87 -0
- data/Rakefile +12 -0
- data/bin/sandman +4 -0
- data/lib/sandman.rb +165 -0
- data/lib/sandman/version.rb +3 -0
- data/sandman.gemspec +26 -0
- metadata +138 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 pyro2927
|
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,87 @@
|
|
1
|
+
# Sandman
|
2
|
+
|
3
|
+
Sandman is meant to help manage ssh keys on [GitHub](https://github.com/) and [BitBucket](https://bitbucket.org/).
|
4
|
+
|
5
|
+
## Table of Contents
|
6
|
+
* [Installation](#installation)
|
7
|
+
* [Usage](#usage)
|
8
|
+
* [Setup](#setup)
|
9
|
+
* [Adding keys](#adding-keys)
|
10
|
+
* [Removing keys](#removing-keys)
|
11
|
+
* [Viewing keys](#viewing-keys)
|
12
|
+
* [TODO](#todo)
|
13
|
+
* [Contributing](#contributing)
|
14
|
+
|
15
|
+
_Generated with [tocify](https://github.com/pyro2927/tocify)_
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
gem 'sandman'
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install sandman
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Sandman is generally meant to be used from the command line, though I guess you could use it through a script if you want.
|
34
|
+
|
35
|
+
### Setup
|
36
|
+
|
37
|
+
To allow access to your GitHub and BitBucket accounts, you'll need to create a YAML formatted config file at `~/.sandman`. Sample config shown below:
|
38
|
+
|
39
|
+
---
|
40
|
+
:accounts:
|
41
|
+
- :login: pyro2927
|
42
|
+
:password: PASSWORD1
|
43
|
+
:type: Github
|
44
|
+
- :login: pyro2927
|
45
|
+
:password: LULZPASSWORD
|
46
|
+
:type: BitBucket
|
47
|
+
|
48
|
+
You can create a sample config by running `sandman createconfig`.
|
49
|
+
|
50
|
+
### Adding keys
|
51
|
+
|
52
|
+
Sandman can add keys pasted into the terminal, though it can also read them from a file. The name isn't required, though if you don't input one it will use the system's `hostname`.
|
53
|
+
|
54
|
+
$ sandman add "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3d5LXLEAOQBVooFVAxWHsolr..." awesomekey
|
55
|
+
$ sandman add ~/.ssh/id_rsa.pub
|
56
|
+
|
57
|
+
### Removing keys
|
58
|
+
|
59
|
+
Removing keys is just about as easy. To remove a key, you must pass in a string it starts with, or the name/title of the key.
|
60
|
+
|
61
|
+
$ sandman rem "ssh-rsa AAAAB3NzaC1yc2E"
|
62
|
+
$ sandman rem oldkey
|
63
|
+
|
64
|
+
**Warning: This checks against the starting text of your public key. If you run `sandman rem ssh`, it will remove all of them.**
|
65
|
+
|
66
|
+
### Viewing keys
|
67
|
+
|
68
|
+
Viewing keys will show your existing keys in any authenticated systems. By default, keys will be truncated to prevent wrapping in the terminal, though they can be printed fully with `showfull`.
|
69
|
+
|
70
|
+
$ sandman show
|
71
|
+
$ sandman showfull
|
72
|
+
|
73
|
+
## TODO
|
74
|
+
|
75
|
+
- [ ] Enable public key marging, syncing all accounts specified
|
76
|
+
- [ ] Allow arbitrary config file location
|
77
|
+
- [ ] Support OAuth
|
78
|
+
- [ ] Add in safeguards to prevent people from deleting all of their public keys
|
79
|
+
- [ ] Fix crazy nokogiri conflicts between dependancies
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
1. Fork it
|
84
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
85
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
86
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
87
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
require 'bundler/version'
|
3
|
+
require 'sandman/version'
|
4
|
+
require "bundler/gem_tasks"
|
5
|
+
|
6
|
+
task :build do
|
7
|
+
system 'gem build sandman.gemspec'
|
8
|
+
end
|
9
|
+
|
10
|
+
task :install do
|
11
|
+
system "gem install sandman-#{Sandman::VERSION}.gem"
|
12
|
+
end
|
data/bin/sandman
ADDED
data/lib/sandman.rb
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
require "sandman/version"
|
2
|
+
require "github_api"
|
3
|
+
require "bitbucket_rest_api"
|
4
|
+
|
5
|
+
module Sandman
|
6
|
+
@config = {:accounts => []}
|
7
|
+
@providers = Array.new
|
8
|
+
|
9
|
+
def self.filter_args(args)
|
10
|
+
Sandman.init
|
11
|
+
if args.count > 1
|
12
|
+
# try to automatically detect if we're being handed a file or key string
|
13
|
+
key = args[1]
|
14
|
+
if key.start_with?("ssh") == false && File.exist?(key)
|
15
|
+
key = File.read(key)
|
16
|
+
end
|
17
|
+
if args.count > 2
|
18
|
+
name = args[2]
|
19
|
+
else
|
20
|
+
name = `hostname`.strip
|
21
|
+
end
|
22
|
+
command = args[0]
|
23
|
+
if command == "add"
|
24
|
+
Sandman.add_key_to_providers(key, name)
|
25
|
+
elsif command.start_with?("rem") || command.start_with?("del")
|
26
|
+
Sandman.remove_key_from_providers(key)
|
27
|
+
end
|
28
|
+
elsif args.count == 1
|
29
|
+
command = args[0]
|
30
|
+
if command == "show"
|
31
|
+
Sandman.show_keys
|
32
|
+
elsif command == "showfull"
|
33
|
+
Sandman.show_keys(true)
|
34
|
+
elsif command == "sync" || command == "merge"
|
35
|
+
#TODO: merge this stuff
|
36
|
+
elsif command == "createconfig"
|
37
|
+
if File.exist? "#{Dir.home}/.sandman"
|
38
|
+
puts "Config file already exists"
|
39
|
+
else
|
40
|
+
@config[:accounts] << {:login => "", :password => "", :type => "Github"}
|
41
|
+
@config[:accounts] << {:login => "", :password => "", :type => "BitBucket"}
|
42
|
+
Sandman.write_config "#{Dir.home}/.sandman"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.init
|
50
|
+
if File.exist? "#{Dir.home}/.sandman"
|
51
|
+
Sandman.configure_with "#{Dir.home}/.sandman"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.configure_with(path_to_yaml_file)
|
56
|
+
begin
|
57
|
+
config = YAML::load(IO.read(path_to_yaml_file))
|
58
|
+
rescue Errno::ENOENT
|
59
|
+
log(:warning, "YAML config file not found, using defaults")
|
60
|
+
rescue Psych::SyntaxError
|
61
|
+
log(:warning, "YAML config file contains invalid syntax, using defaults")
|
62
|
+
end
|
63
|
+
|
64
|
+
configure(config)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.configure(opts = {})
|
68
|
+
@config = opts
|
69
|
+
opts[:accounts].each do |acct|
|
70
|
+
provider = Kernel.const_get(acct[:type]).new acct
|
71
|
+
@providers << provider
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.write_config(path_to_yaml_file)
|
76
|
+
IO.write(path_to_yaml_file, @config.to_yaml)
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.config
|
80
|
+
@config
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.keys_for_provider(p)
|
84
|
+
if p.kind_of? Github::Client
|
85
|
+
p.users.keys.all(p.login).body
|
86
|
+
elsif p.kind_of? BitBucket::Client
|
87
|
+
p.users.account.keys(p.login)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.all_keys
|
92
|
+
keys = Array.new
|
93
|
+
@providers.each do |p|
|
94
|
+
keys << Sandman.keys_for_provider(p)
|
95
|
+
end
|
96
|
+
keys.flatten
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.merge_keys_to_services
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.add_key_to_provider(p, key = "", title = "")
|
104
|
+
begin
|
105
|
+
if p.kind_of? Github::Client
|
106
|
+
p.users.keys.create({:title => title, :key => key})
|
107
|
+
puts "Key added to GitHub"
|
108
|
+
elsif p.kind_of? BitBucket::Client
|
109
|
+
p.users.account.new_key(p.login, {:label => title, :key => key})
|
110
|
+
puts "Key added to BitBucket"
|
111
|
+
end
|
112
|
+
rescue Exception => e
|
113
|
+
puts e.to_s
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.add_key_to_providers(key = "", title = "")
|
118
|
+
puts "Adding #{key} to providers..."
|
119
|
+
@providers.each do |p|
|
120
|
+
Sandman.add_key_to_provider(p, key, title)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.remove_key_from_provider(p, key)
|
125
|
+
begin
|
126
|
+
if p.kind_of? Github::Client
|
127
|
+
p.users.keys.delete(key[:id])
|
128
|
+
puts "Key removed from GitHub"
|
129
|
+
elsif p.kind_of? BitBucket::Client
|
130
|
+
p.users.account.delete_key(p.login, key[:pk])
|
131
|
+
puts "Key removed from BitBucket"
|
132
|
+
end
|
133
|
+
rescue Exception => e
|
134
|
+
puts e.to_s
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.remove_key_from_providers(key = "")
|
139
|
+
puts "Removing #{key} from providers..."
|
140
|
+
@providers.each do |p|
|
141
|
+
Sandman.keys_for_provider(p).each do |k|
|
142
|
+
if ( k[:key].split(" ")[0..1].join(" ").start_with?(key) || (k[:title].nil? == false && k[:title].downcase == key.downcase) || (k[:label].nil? == false && k[:label].downcase == key.downcase) )
|
143
|
+
Sandman.remove_key_from_provider(p, k)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.show_keys(long = false)
|
150
|
+
@providers.each do |p|
|
151
|
+
title = p.class.name.split("::").first + ": " + p.login
|
152
|
+
puts title
|
153
|
+
puts "=" * title.length
|
154
|
+
Sandman.keys_for_provider(p).each do |k|
|
155
|
+
if p.kind_of? Github::Client
|
156
|
+
line = "\t#{k[:title]}: #{k[:key]}"
|
157
|
+
elsif p.kind_of? BitBucket::Client
|
158
|
+
line = "\t#{k[:label]}: #{k[:key]}"
|
159
|
+
end
|
160
|
+
puts (long ? line : line[0..75])
|
161
|
+
end
|
162
|
+
puts "\n"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
data/sandman.gemspec
ADDED
@@ -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 'sandman/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sandman"
|
8
|
+
spec.version = Sandman::VERSION
|
9
|
+
spec.authors = ["pyro2927"]
|
10
|
+
spec.email = ["joseph@pintozzi.com"]
|
11
|
+
spec.description = "Sandman is a gem aimed at helping you manage your SSH keys between GitHub and Bitbucket"
|
12
|
+
spec.summary = "Sandman is a gem aimed at helping you manage your SSH keys between GitHub and Bitbucket"
|
13
|
+
spec.homepage = "https://github.com/pyro2927/sandman"
|
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_runtime_dependency "nokogiri"
|
22
|
+
spec.add_runtime_dependency "bitbucket_rest_api", "~> 0.1.3"
|
23
|
+
spec.add_runtime_dependency "github_api", "~> 0.10.2"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sandman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- pyro2927
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bitbucket_rest_api
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.1.3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.1.3
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: github_api
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.10.2
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.10.2
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.3'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.3'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Sandman is a gem aimed at helping you manage your SSH keys between GitHub
|
95
|
+
and Bitbucket
|
96
|
+
email:
|
97
|
+
- joseph@pintozzi.com
|
98
|
+
executables:
|
99
|
+
- sandman
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- .gitignore
|
104
|
+
- Gemfile
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- bin/sandman
|
109
|
+
- lib/sandman.rb
|
110
|
+
- lib/sandman/version.rb
|
111
|
+
- sandman.gemspec
|
112
|
+
homepage: https://github.com/pyro2927/sandman
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.8.23
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Sandman is a gem aimed at helping you manage your SSH keys between GitHub
|
137
|
+
and Bitbucket
|
138
|
+
test_files: []
|