pk 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -0
- data/bin/pk +2 -95
- data/bin/pkeys +5 -0
- data/lib/pk/helper.rb +19 -0
- data/lib/pk/ignore_file.rb +27 -0
- data/lib/pk/keys.rb +26 -0
- data/lib/pk/main.rb +18 -0
- data/lib/pk/team.rb +39 -0
- data/lib/pk/version.rb +1 -1
- data/pk.gemspec +2 -0
- metadata +26 -3
data/README.md
CHANGED
data/bin/pk
CHANGED
@@ -1,98 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'pk/main'
|
4
4
|
|
5
|
-
|
6
|
-
PKIGNORE_NAMES = %w(pkignore .pkignore).freeze
|
7
|
-
|
8
|
-
def initialize(path)
|
9
|
-
@ignore_list = PKIGNORE_NAMES.dup
|
10
|
-
PKIGNORE_NAMES.each do |filename|
|
11
|
-
file = File.expand_path(File.join(path, filename))
|
12
|
-
if File.exist? file
|
13
|
-
@ignore_list = @ignore_list + File.open(file, 'r').read.split("\n")
|
14
|
-
break
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def ignore_file?(filename)
|
20
|
-
ignore = false
|
21
|
-
@ignore_list.each do |ignore_pattern|
|
22
|
-
if File.fnmatch(ignore_pattern, filename, File::FNM_PATHNAME)
|
23
|
-
ignore = true
|
24
|
-
break
|
25
|
-
end
|
26
|
-
end
|
27
|
-
ignore
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
module Helper
|
32
|
-
|
33
|
-
def init
|
34
|
-
`mkdir -p ~/.pk/data/`
|
35
|
-
end
|
36
|
-
|
37
|
-
def all_members_of(team)
|
38
|
-
pkignore = PkIgnoreFile.new("~/.pk/data/#{team}")
|
39
|
-
[].tap do |list|
|
40
|
-
`ls ~/.pk/data/#{team}`.split.each do |filename|
|
41
|
-
list << filename unless pkignore.ignore_file?(filename)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class Team < Thor
|
48
|
-
include Helper
|
49
|
-
|
50
|
-
desc "add NAME, GIT_URL", "add team repo via git clone"
|
51
|
-
def add(name, git_url)
|
52
|
-
init
|
53
|
-
`git clone #{git_url} ~/.pk/data/#{name}`
|
54
|
-
end
|
55
|
-
|
56
|
-
desc "reload [TEAM]", "reload a team repo, or all teams if not specified"
|
57
|
-
def reload(team=nil)
|
58
|
-
init
|
59
|
-
teams = Dir["#{ENV["HOME"]}/.pk/data/*/"].map{|f| File.basename(f) }
|
60
|
-
teams = teams.select{|t| t == team} if team
|
61
|
-
teams.each do |t|
|
62
|
-
`cd ~/.pk/data/#{t} && git pull && cd -`
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
desc "list [TEAM]", "list all team, or team members if team is specified"
|
67
|
-
def list(team=nil)
|
68
|
-
init
|
69
|
-
if team
|
70
|
-
all_members_of(team).each do |m|
|
71
|
-
puts m
|
72
|
-
end
|
73
|
-
else
|
74
|
-
`ls ~/.pk/data`.split.each do |t|
|
75
|
-
puts t
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
class Pk < Thor
|
83
|
-
include Helper
|
84
|
-
|
85
|
-
desc "keys TEAM [MEMBER1,MEMBER2,..]", "print public keys of members in a specific team"
|
86
|
-
def keys(team, members=nil)
|
87
|
-
init
|
88
|
-
member_list = members ? members.split(',').compact : all_members_of(team)
|
89
|
-
member_list.each do |member|
|
90
|
-
puts `cat ~/.pk/data/#{team}/#{member}`
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
desc "team", "manage teams"
|
95
|
-
subcommand "team", Team
|
96
|
-
end
|
97
|
-
|
98
|
-
Pk.start
|
5
|
+
Pk::Main.start
|
data/bin/pkeys
ADDED
data/lib/pk/helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'pk/ignore_file'
|
2
|
+
|
3
|
+
module Pk
|
4
|
+
module Helper
|
5
|
+
|
6
|
+
def init
|
7
|
+
`mkdir -p ~/.pk/data/`
|
8
|
+
end
|
9
|
+
|
10
|
+
def all_members_of(team)
|
11
|
+
pkignore = Pk::IgnoreFile.new("~/.pk/data/#{team}")
|
12
|
+
[].tap do |list|
|
13
|
+
`ls ~/.pk/data/#{team}`.split.each do |filename|
|
14
|
+
list << filename unless pkignore.ignore_file?(filename)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Pk
|
2
|
+
class IgnoreFile
|
3
|
+
PKIGNORE_NAMES = %w(pkignore .pkignore).freeze
|
4
|
+
|
5
|
+
def initialize(path)
|
6
|
+
@ignore_list = PKIGNORE_NAMES.dup
|
7
|
+
PKIGNORE_NAMES.each do |filename|
|
8
|
+
file = File.expand_path(File.join(path, filename))
|
9
|
+
if File.exist? file
|
10
|
+
@ignore_list = @ignore_list + File.open(file, 'r').read.split("\n")
|
11
|
+
break
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def ignore_file?(filename)
|
17
|
+
ignore = false
|
18
|
+
@ignore_list.each do |ignore_pattern|
|
19
|
+
if File.fnmatch(ignore_pattern, filename, File::FNM_PATHNAME)
|
20
|
+
ignore = true
|
21
|
+
break
|
22
|
+
end
|
23
|
+
end
|
24
|
+
ignore
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/pk/keys.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'pk/helper'
|
3
|
+
require 'thor/group'
|
4
|
+
|
5
|
+
module Pk
|
6
|
+
class Keys < Thor::Group
|
7
|
+
include Helper
|
8
|
+
|
9
|
+
desc "print public keys of members in a specific team"
|
10
|
+
argument :team, :type => :string, :desc => "Team name"
|
11
|
+
argument :members, :optional => true, :type => :string, :desc => "Members separated by comma (,)"
|
12
|
+
|
13
|
+
def self.banner
|
14
|
+
"#{basename} TEAM [MEMBER1,MEMBER2,..]"
|
15
|
+
end
|
16
|
+
|
17
|
+
def keys
|
18
|
+
init
|
19
|
+
member_list = members ? members.split(',').compact : all_members_of(team)
|
20
|
+
member_list.each do |member|
|
21
|
+
puts `cat ~/.pk/data/#{team}/#{member}`
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/lib/pk/main.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'pk/helper'
|
3
|
+
require 'pk/team'
|
4
|
+
require 'pk/keys'
|
5
|
+
|
6
|
+
module Pk
|
7
|
+
class Main < Thor
|
8
|
+
include Helper
|
9
|
+
|
10
|
+
desc "keys TEAM [MEMBER1,MEMBER2,..]", "print public keys of members in a specific team"
|
11
|
+
def keys(team, members=nil)
|
12
|
+
Pk::Keys.start( [team, members] )
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "team", "manage teams"
|
16
|
+
subcommand "team", Team
|
17
|
+
end
|
18
|
+
end
|
data/lib/pk/team.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'pk/helper'
|
3
|
+
|
4
|
+
module Pk
|
5
|
+
class Team < Thor
|
6
|
+
include Helper
|
7
|
+
|
8
|
+
desc "add NAME, GIT_URL", "add team repo via git clone"
|
9
|
+
def add(name, git_url)
|
10
|
+
init
|
11
|
+
`git clone #{git_url} ~/.pk/data/#{name}`
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "reload [TEAM]", "reload a team repo, or all teams if not specified"
|
15
|
+
def reload(team=nil)
|
16
|
+
init
|
17
|
+
teams = Dir["#{ENV["HOME"]}/.pk/data/*/"].map{|f| File.basename(f) }
|
18
|
+
teams = teams.select{|t| t == team} if team
|
19
|
+
teams.each do |t|
|
20
|
+
`cd ~/.pk/data/#{t} && git pull && cd -`
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "list [TEAM]", "list all team, or team members if team is specified"
|
25
|
+
def list(team=nil)
|
26
|
+
init
|
27
|
+
if team
|
28
|
+
all_members_of(team).each do |m|
|
29
|
+
puts m
|
30
|
+
end
|
31
|
+
else
|
32
|
+
`ls ~/.pk/data`.split.each do |t|
|
33
|
+
puts t
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/lib/pk/version.rb
CHANGED
data/pk.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,13 +9,30 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-01-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
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'
|
14
30
|
description: Command line tool to collect and print public keys.
|
15
31
|
email:
|
16
32
|
- teohuiming@gmail.com
|
17
33
|
executables:
|
18
34
|
- pk
|
35
|
+
- pkeys
|
19
36
|
extensions: []
|
20
37
|
extra_rdoc_files: []
|
21
38
|
files:
|
@@ -25,7 +42,13 @@ files:
|
|
25
42
|
- README.md
|
26
43
|
- Rakefile
|
27
44
|
- bin/pk
|
45
|
+
- bin/pkeys
|
28
46
|
- lib/pk.rb
|
47
|
+
- lib/pk/helper.rb
|
48
|
+
- lib/pk/ignore_file.rb
|
49
|
+
- lib/pk/keys.rb
|
50
|
+
- lib/pk/main.rb
|
51
|
+
- lib/pk/team.rb
|
29
52
|
- lib/pk/version.rb
|
30
53
|
- pk.gemspec
|
31
54
|
homepage: https://github.com/teohm/pk
|