brownbeagle-gitauth 0.0.4.1 → 0.0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/gitauth +12 -2
- data/lib/gitauth.rb +8 -1
- data/lib/gitauth/client.rb +6 -5
- data/lib/gitauth/group.rb +3 -2
- data/lib/gitauth/repo.rb +26 -6
- data/lib/gitauth/user.rb +5 -4
- data/lib/gitauth/web_app.rb +6 -5
- metadata +41 -1
data/bin/gitauth
CHANGED
@@ -69,7 +69,12 @@ GitAuth::Application.processing(ARGV) do |a|
|
|
69
69
|
end
|
70
70
|
|
71
71
|
if options[:admin]
|
72
|
-
|
72
|
+
key_contents = File.read(options[:admin]).strip
|
73
|
+
if GitAuth::User.create("admin", true, key_contents)
|
74
|
+
puts "Default admin user added with key '#{options[:admin]}'"
|
75
|
+
else
|
76
|
+
die! "Error adding default admin user with key at '#{options[:admin]}'"
|
77
|
+
end
|
73
78
|
end
|
74
79
|
|
75
80
|
end
|
@@ -115,12 +120,17 @@ GitAuth::Application.processing(ARGV) do |a|
|
|
115
120
|
end
|
116
121
|
end
|
117
122
|
|
123
|
+
a.option(:make_empty, "Initializes the repository to be empty / have an initial blank commit")
|
118
124
|
a.add("add-repo NAME [PATH=NAME]", "Creates a named repository, with an optional path on the file system") do |name, *args|
|
119
125
|
GitAuth.prepare
|
120
126
|
options = args.extract_options!
|
121
127
|
path = (args.shift || name)
|
122
|
-
if GitAuth::Repo.create(name, path)
|
128
|
+
if (repo = GitAuth::Repo.create(name, path))
|
123
129
|
puts "Successfully created repository '#{name}' located at '#{path}'"
|
130
|
+
if options[:make_empty]
|
131
|
+
puts "Attempting to make empty repository"
|
132
|
+
repo.make_empty!
|
133
|
+
end
|
124
134
|
else
|
125
135
|
die! "Unable to create repository '#{name}' in location '#{path}'"
|
126
136
|
end
|
data/lib/gitauth.rb
CHANGED
@@ -21,7 +21,7 @@ require 'ostruct'
|
|
21
21
|
|
22
22
|
module GitAuth
|
23
23
|
|
24
|
-
VERSION = [0, 0, 4,
|
24
|
+
VERSION = [0, 0, 4, 2]
|
25
25
|
BASE_DIR = Pathname.new(__FILE__).dirname.join("..").expand_path
|
26
26
|
LIB_DIR = BASE_DIR.join("lib", "gitauth")
|
27
27
|
GITAUTH_DIR = Pathname.new("~/.gitauth/").expand_path
|
@@ -94,6 +94,13 @@ module GitAuth
|
|
94
94
|
each_model(:load!)
|
95
95
|
end
|
96
96
|
|
97
|
+
def run(command)
|
98
|
+
GitAuth::Logger.info "Running command: #{command}"
|
99
|
+
result = system "#{command} 2> /dev/null 1> /dev/null"
|
100
|
+
GitAuth::Logger.info "Command was #{"not " if !result}successful"
|
101
|
+
return result
|
102
|
+
end
|
103
|
+
|
97
104
|
end
|
98
105
|
|
99
106
|
end
|
data/lib/gitauth/client.rb
CHANGED
@@ -21,18 +21,19 @@
|
|
21
21
|
|
22
22
|
module GitAuth
|
23
23
|
class Client
|
24
|
+
include GitAuth::Loggable
|
24
25
|
|
25
26
|
attr_accessor :user, :command
|
26
27
|
|
27
28
|
def initialize(user_name, command)
|
28
|
-
|
29
|
+
logger.debug "Initializing client with command: #{command.inspect} and user name #{user_name.inspect}"
|
29
30
|
@callbacks = Hash.new { |h,k| h[k] = [] }
|
30
31
|
@user = GitAuth::User.get(user_name.to_s.strip)
|
31
32
|
@command = command
|
32
33
|
end
|
33
34
|
|
34
35
|
def exit_with_error(error)
|
35
|
-
|
36
|
+
logger.warn "Exiting with error: #{error}"
|
36
37
|
$stderr.puts error
|
37
38
|
exit! 1
|
38
39
|
end
|
@@ -59,16 +60,16 @@ module GitAuth
|
|
59
60
|
exit_with_error "Ze repository you specified does not exist."
|
60
61
|
elsif user.can_execute?(command, repo)
|
61
62
|
git_shell_argument = "#{command.verb} '#{repo.real_path}'"
|
62
|
-
|
63
|
+
logger.info "Running command: #{git_shell_argument} for user: #{@user.name}"
|
63
64
|
exec("git-shell", "-c", git_shell_argument)
|
64
65
|
else
|
65
66
|
exit_with_error "These are not the droids you are looking for"
|
66
67
|
end
|
67
68
|
end
|
68
69
|
rescue Exception => e
|
69
|
-
|
70
|
+
logger.fatal "Exception: #{e.class.name}: #{e.message}"
|
70
71
|
e.backtrace.each do |l|
|
71
|
-
|
72
|
+
logger.fatal " => #{l}"
|
72
73
|
end
|
73
74
|
exit_with_error "Holy crap, we've imploded cap'n!"
|
74
75
|
end
|
data/lib/gitauth/group.rb
CHANGED
@@ -19,7 +19,8 @@
|
|
19
19
|
|
20
20
|
module GitAuth
|
21
21
|
class Group < SaveableClass(:groups)
|
22
|
-
|
22
|
+
include GitAuth::Loggable
|
23
|
+
|
23
24
|
attr_accessor :name, :members
|
24
25
|
|
25
26
|
def initialize(name)
|
@@ -73,7 +74,7 @@ module GitAuth
|
|
73
74
|
end
|
74
75
|
|
75
76
|
def self.get(name)
|
76
|
-
|
77
|
+
logger.debug "Getting group named #{name.inspect}"
|
77
78
|
real_name = name.to_s.gsub(/^@/, "")
|
78
79
|
self.all.detect { |g| g.name == real_name }
|
79
80
|
end
|
data/lib/gitauth/repo.rb
CHANGED
@@ -19,10 +19,12 @@
|
|
19
19
|
require 'fileutils'
|
20
20
|
module GitAuth
|
21
21
|
class Repo < SaveableClass(:repositories)
|
22
|
+
include GitAuth::Loggable
|
23
|
+
|
22
24
|
NAME_RE = /^([\w\_\-\.\+]+(\.git)?)$/i
|
23
25
|
|
24
26
|
def self.get(name)
|
25
|
-
|
27
|
+
logger.debug "Getting Repo w/ name: '#{name}'"
|
26
28
|
(all || []).detect { |r| r.name == name }
|
27
29
|
end
|
28
30
|
|
@@ -97,12 +99,28 @@ module GitAuth
|
|
97
99
|
|
98
100
|
def make_empty!
|
99
101
|
tmp_path = "/tmp/gitauth-#{rand(100000)}-#{Time.now.to_i}"
|
100
|
-
|
101
|
-
|
102
|
+
logger.info "Creating temporary dir at #{tmp_path}"
|
103
|
+
FileUtils.mkdir_p("#{tmp_path}/current-repo")
|
104
|
+
logger.info "Changing to new directory"
|
102
105
|
Dir.chdir("#{tmp_path}/current-repo") do
|
103
|
-
|
106
|
+
logger.info "Marking as git repo"
|
107
|
+
GitAuth.run "git init"
|
108
|
+
logger.info "Touching .gitignore"
|
109
|
+
GitAuth.run "touch .gitignore"
|
110
|
+
# Configure it
|
111
|
+
GitAuth.run "git config push.default current"
|
112
|
+
logger.info "Commiting"
|
113
|
+
GitAuth.run "git add ."
|
114
|
+
GitAuth.run "git commit -am 'Initialize Empty Repository'"
|
115
|
+
# Push the changes to the actual repository
|
116
|
+
logger.info "Adding origin #{self.real_path}"
|
117
|
+
GitAuth.run "git remote add origin '#{self.real_path}'"
|
118
|
+
logger.info "Pushing..."
|
119
|
+
GitAuth.run "git push origin master"
|
104
120
|
end
|
105
|
-
|
121
|
+
ensure
|
122
|
+
logger.info "Cleaning up old tmp file"
|
123
|
+
FileUtils.rm_rf(tmp_path) if File.directory?(tmp_path)
|
106
124
|
end
|
107
125
|
|
108
126
|
def execute_post_create_hook!
|
@@ -124,7 +142,9 @@ module GitAuth
|
|
124
142
|
@permissions[type].uniq!
|
125
143
|
end
|
126
144
|
|
127
|
-
def has_permissions_for(
|
145
|
+
def has_permissions_for(type, whom)
|
146
|
+
whom = GitAuth.get_user_or_group(whom) if whom.is_a?(String)
|
147
|
+
logger.info "Checking if #{whom.to_s} can #{type} #{self.name}"
|
128
148
|
!(@permissions[type] || []).detect do |reader|
|
129
149
|
reader = GitAuth.get_user_or_group(reader)
|
130
150
|
reader == whom || (reader.is_a?(Group) && reader.member?(whom, true))
|
data/lib/gitauth/user.rb
CHANGED
@@ -19,9 +19,10 @@
|
|
19
19
|
|
20
20
|
module GitAuth
|
21
21
|
class User < SaveableClass(:users)
|
22
|
-
|
22
|
+
include GitAuth::Loggable
|
23
|
+
|
23
24
|
def self.get(name)
|
24
|
-
|
25
|
+
logger.debug "Getting user for the name '#{name}'"
|
25
26
|
(all || []).detect { |r| r.name == name }
|
26
27
|
end
|
27
28
|
|
@@ -109,10 +110,10 @@ module GitAuth
|
|
109
110
|
def can_execute?(command, repo)
|
110
111
|
return if command.bad?
|
111
112
|
if command.write?
|
112
|
-
|
113
|
+
logger.debug "Checking if #{self.name} can push to #{repo.name}"
|
113
114
|
pushable?(repo)
|
114
115
|
else
|
115
|
-
|
116
|
+
logger.debug "Checking if #{self.name} can pull from #{repo.name}"
|
116
117
|
pullable?(repo)
|
117
118
|
end
|
118
119
|
end
|
data/lib/gitauth/web_app.rb
CHANGED
@@ -24,6 +24,7 @@ GitAuth.require_vendored 'sinatra'
|
|
24
24
|
require 'digest/sha2'
|
25
25
|
module GitAuth
|
26
26
|
class WebApp < Sinatra::Base
|
27
|
+
include GitAuth::Loggable
|
27
28
|
|
28
29
|
cattr_accessor :current_server
|
29
30
|
|
@@ -53,11 +54,11 @@ module GitAuth
|
|
53
54
|
def self.check_auth
|
54
55
|
if !has_auth?
|
55
56
|
if $stderr.tty?
|
56
|
-
|
57
|
+
logger.verbose = true
|
57
58
|
puts "For gitauth to continue, you need to provide a username and password."
|
58
59
|
update_auth
|
59
60
|
else
|
60
|
-
|
61
|
+
logger.fatal "You need to provide a username and password for GitAuth to function; Please run 'gitauth webapp` once"
|
61
62
|
exit!
|
62
63
|
end
|
63
64
|
end
|
@@ -68,20 +69,20 @@ module GitAuth
|
|
68
69
|
set options
|
69
70
|
handler = detect_rack_handler
|
70
71
|
handler_name = handler.name.gsub(/.*::/, '')
|
71
|
-
|
72
|
+
logger.info "Starting up web server on #{port}"
|
72
73
|
handler.run self, :Host => host, :Port => port do |server|
|
73
74
|
GitAuth::WebApp.current_server = server
|
74
75
|
set :running, true
|
75
76
|
end
|
76
77
|
rescue Errno::EADDRINUSE => e
|
77
|
-
|
78
|
+
logger.fatal "Server is already running on port #{port}"
|
78
79
|
end
|
79
80
|
|
80
81
|
def self.stop
|
81
82
|
if current_server.present?
|
82
83
|
current_server.respond_to?(:stop!) ? current_server.stop! : current_server.stop
|
83
84
|
end
|
84
|
-
|
85
|
+
logger.debug "Stopped Server."
|
85
86
|
end
|
86
87
|
|
87
88
|
use GitAuth::AuthSetupMiddleware
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brownbeagle-gitauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.4.
|
4
|
+
version: 0.0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darcy Laycock
|
@@ -36,6 +36,46 @@ dependencies:
|
|
36
36
|
name: Sutto-perennial
|
37
37
|
type: :runtime
|
38
38
|
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.2.3
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: thoughtbot-shoulda
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.0.0
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: redgreen
|
57
|
+
type: :development
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 1.0.0
|
64
|
+
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rr
|
67
|
+
type: :development
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 0.10.0
|
74
|
+
version:
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rack-test
|
77
|
+
type: :development
|
78
|
+
version_requirement:
|
39
79
|
version_requirements: !ruby/object:Gem::Requirement
|
40
80
|
requirements:
|
41
81
|
- - ">="
|