gitauth 0.0.5.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/gitauth.rb +19 -15
  2. data/lib/gitauth/web_app.rb +43 -43
  3. metadata +86 -34
@@ -20,18 +20,22 @@ require 'pathname'
20
20
 
21
21
  # Prepend lib dir + any vendored lib's to the front of the load
22
22
  # path to ensure they're loaded first.
23
- $LOAD_PATH.unshift(*Dir[Pathname(__FILE__).dirname.join("../{lib,vendor/*/lib}").expand_path])
23
+ $LOAD_PATH.unshift(*Dir[Pathname(__FILE__).dirname.join("../{lib,vendor/*/lib}").expand_path.to_s])
24
+
25
+ require 'rubygems'
26
+
27
+ gem 'perennial'
24
28
 
25
29
  require 'perennial'
26
30
 
27
31
  module GitAuth
28
32
  include Perennial
29
33
  include Loggable
30
-
31
- VERSION = [0, 0, 5, 2]
34
+
35
+ VERSION = [0, 1, 0]
32
36
  BASE_DIR = Pathname(__FILE__).dirname.join("..").expand_path
33
37
  GITAUTH_DIR = Pathname("~/.gitauth/").expand_path
34
-
38
+
35
39
  manifest do |m, l|
36
40
  Settings.root = File.dirname(__FILE__)
37
41
  Settings.default_settings_path = GITAUTH_DIR.join("settings.yml")
@@ -41,7 +45,7 @@ module GitAuth
41
45
  l.register_controller :web_app, 'GitAuth::WebApp'
42
46
  l.before_run { GitAuth.prepare }
43
47
  end
44
-
48
+
45
49
  require 'gitauth/message' # Basic error messages etc (as of yet unushed)
46
50
  require 'gitauth/saveable_class' # Simple YAML store for dumpables classes
47
51
  require 'gitauth/repo' # The basic GitAuth repo object
@@ -49,22 +53,22 @@ module GitAuth
49
53
  require 'gitauth/group' # The basic GitAuth group object (collection of users)
50
54
  require 'gitauth/command' # Processes / filters commands
51
55
  require 'gitauth/client' # Handles the actual SSH interaction / bringing it together
52
-
56
+
53
57
  autoload :AuthSetupMiddleware, 'gitauth/auth_setup_middleware'
54
58
  autoload :ApacheAuthentication, 'gitauth/apache_authentication'
55
59
  autoload :WebApp, 'gitauth/web_app'
56
-
60
+
57
61
  class << self
58
-
62
+
59
63
  def prepare
60
64
  GitAuth::Settings.setup!
61
65
  reload_models!
62
66
  end
63
-
67
+
64
68
  def version
65
69
  VERSION.join(".")
66
70
  end
67
-
71
+
68
72
  def msg(type, message)
69
73
  Message.new(type, message)
70
74
  end
@@ -83,18 +87,18 @@ module GitAuth
83
87
  [Repo, User, Group].each { |m| m.send(method) } if method.present?
84
88
  [Repo, User, Group].each(&blk) unless blk.nil?
85
89
  end
86
-
90
+
87
91
  def reload_models!
88
92
  each_model(:load!)
89
93
  end
90
-
94
+
91
95
  def run(command)
92
96
  GitAuth::Logger.info "Running command: #{command}"
93
97
  result = system "#{command} 2> /dev/null 1> /dev/null"
94
98
  GitAuth::Logger.info "Command was #{"not " if !result}successful"
95
99
  return result
96
100
  end
97
-
101
+
98
102
  end
99
-
100
- end
103
+
104
+ end
@@ -23,21 +23,21 @@ require 'digest/sha2'
23
23
  module GitAuth
24
24
  class WebApp < Sinatra::Base
25
25
  include GitAuth::Loggable
26
-
26
+
27
27
  cattr_accessor :current_server
28
-
28
+
29
29
  def self.has_auth?
30
30
  username = GitAuth::Settings["web_username"]
31
31
  password = GitAuth::Settings["web_password_hash"]
32
32
  !(username.blank? || password.blank?)
33
33
  end
34
-
34
+
35
35
  def self.update_auth
36
36
  raw_username = Readline.readline('GitAuth Username (default is \'gitauth\'): ')
37
37
  raw_username = 'gitauth' if raw_username.blank?
38
38
  raw_password = ''
39
39
  while raw_password.blank?
40
- system "stty -echo"
40
+ system "stty -echo"
41
41
  raw_password = Readline.readline('GitAuth Password: ')
42
42
  system "stty echo"
43
43
  print "\n"
@@ -45,7 +45,7 @@ module GitAuth
45
45
  end
46
46
  password_confirmation = nil
47
47
  while password_confirmation != raw_password
48
- system "stty -echo"
48
+ system "stty -echo"
49
49
  password_confirmation = Readline.readline('Confirm Password: ')
50
50
  system "stty echo"
51
51
  print "\n"
@@ -56,12 +56,12 @@ module GitAuth
56
56
  :web_password_hash => Digest::SHA256.hexdigest(raw_password)
57
57
  })
58
58
  end
59
-
59
+
60
60
  def self.check_auth
61
61
  GitAuth.prepare
62
62
  if !has_auth?
63
63
  if $stderr.tty?
64
- logger.verbose = true
64
+ logger.verbose = true
65
65
  puts "For gitauth to continue, you need to provide a username and password."
66
66
  update_auth
67
67
  else
@@ -70,21 +70,21 @@ module GitAuth
70
70
  end
71
71
  end
72
72
  end
73
-
73
+
74
74
  def self.run(options = {})
75
75
  check_auth
76
76
  set options
77
77
  handler = detect_rack_handler
78
78
  handler_name = handler.name.gsub(/.*::/, '')
79
79
  logger.info "Starting up web server on #{port}"
80
- handler.run self, :Host => host, :Port => port do |server|
80
+ handler.run self, :Port => port do |server|
81
81
  GitAuth::WebApp.current_server = server
82
82
  set :running, true
83
83
  end
84
84
  rescue Errno::EADDRINUSE => e
85
85
  logger.fatal "Server is already running on port #{port}"
86
86
  end
87
-
87
+
88
88
  def self.stop
89
89
  if current_server.present?
90
90
  current_server.respond_to?(:stop!) ? current_server.stop! : current_server.stop
@@ -92,17 +92,17 @@ module GitAuth
92
92
  exit!
93
93
  logger.debug "Stopped Server."
94
94
  end
95
-
95
+
96
96
  unless GitAuth::ApacheAuthentication.setup?
97
-
97
+
98
98
  use GitAuth::AuthSetupMiddleware
99
-
99
+
100
100
  use Rack::Auth::Basic do |username, password|
101
101
  [username, Digest::SHA256.hexdigest(password)] == [GitAuth::Settings["web_username"], GitAuth::Settings["web_password_hash"]]
102
102
  end
103
-
103
+
104
104
  end
105
-
105
+
106
106
  configure do
107
107
  set :port, 8998
108
108
  set :views, GitAuth::BASE_DIR.join("views")
@@ -110,21 +110,21 @@ module GitAuth
110
110
  set :static, true
111
111
  set :methodoverride, true
112
112
  end
113
-
113
+
114
114
  before { GitAuth.reload_models! }
115
-
115
+
116
116
  helpers do
117
117
  include Rack::Utils
118
118
  alias_method :h, :escape_html
119
-
119
+
120
120
  def link_to(text, link)
121
121
  "<a href='#{u link}'>#{text}</a>"
122
122
  end
123
-
123
+
124
124
  def u(url)
125
125
  "#{request.script_name}#{url}"
126
126
  end
127
-
127
+
128
128
  def delete_link(text, url)
129
129
  id = "deleteable-#{Digest::SHA256.hexdigest(url.to_s)[0, 6]}"
130
130
  html = "<div class='deletable-container' style='display: none; margin: 0; padding: 0;'>"
@@ -134,24 +134,24 @@ module GitAuth
134
134
  html << "<a href='#' onclick='if(confirm(\"Are you sure you want to do that? Deletion can not be reversed.\")) $(\"##{id}\").submit(); return false;'>#{text}</a>"
135
135
  return html
136
136
  end
137
-
137
+
138
138
  def auto_link(member)
139
139
  member = member.to_s
140
140
  url = (member[0] == ?@ ? "/groups/#{URI.encode(member[1..-1])}" : "/users/#{URI.encode(member)}")
141
141
  return link_to(member, url)
142
142
  end
143
-
143
+
144
144
  end
145
-
145
+
146
146
  get '/' do
147
147
  @repos = GitAuth::Repo.all
148
148
  @users = GitAuth::User.all
149
149
  @groups = GitAuth::Group.all
150
150
  erb :index
151
151
  end
152
-
152
+
153
153
  # Listing / Index Page
154
-
154
+
155
155
  get '/repos/:name' do
156
156
  @repo = GitAuth::Repo.get(params[:name])
157
157
  if @repo.nil?
@@ -159,18 +159,18 @@ module GitAuth
159
159
  else
160
160
  read_perms, write_perms = (@repo.permissions[:read]||[]), (@repo.permissions[:write]||[])
161
161
  @all_access = read_perms & write_perms
162
- @read_only = read_perms - @all_access
162
+ @read_only = read_perms - @all_access
163
163
  @write_only = write_perms - @all_access
164
164
  erb :repo
165
165
  end
166
166
  end
167
-
167
+
168
168
  get '/users/:name' do
169
169
  @user = GitAuth::User.get(params[:name])
170
170
  if @user.nil?
171
171
  redirect root_with_message("The given user couldn't be found.")
172
172
  else
173
- repos = GitAuth::Repo.all
173
+ repos = GitAuth::Repo.all
174
174
  read_perms = repos.select { |r| r.readable_by?(@user) }
175
175
  write_perms = repos.select { |r| r.writeable_by?(@user) }
176
176
  @all_access = read_perms & write_perms
@@ -180,7 +180,7 @@ module GitAuth
180
180
  erb :user
181
181
  end
182
182
  end
183
-
183
+
184
184
  get '/groups/:name' do
185
185
  @group = GitAuth::Group.get(params[:name])
186
186
  if @group.nil?
@@ -189,9 +189,9 @@ module GitAuth
189
189
  erb :group
190
190
  end
191
191
  end
192
-
192
+
193
193
  # Create and update repos
194
-
194
+
195
195
  post '/repos' do
196
196
  name = params[:repo][:name]
197
197
  path = params[:repo][:path]
@@ -208,7 +208,7 @@ module GitAuth
208
208
  redirect root_with_message("There was an error adding the repository.")
209
209
  end
210
210
  end
211
-
211
+
212
212
  post '/repos/:name' do
213
213
  repo = GitAuth::Repo.get(params[:name])
214
214
  if repo.nil?
@@ -233,7 +233,7 @@ module GitAuth
233
233
  redirect u("/repos/#{URI.encode(repo.name)}")
234
234
  end
235
235
  end
236
-
236
+
237
237
  delete '/repos/:name' do
238
238
  repo = GitAuth::Repo.get(params[:name])
239
239
  if repo.nil?
@@ -243,9 +243,9 @@ module GitAuth
243
243
  redirect root_with_message("Repository removed.")
244
244
  end
245
245
  end
246
-
246
+
247
247
  # Create, delete and update users
248
-
248
+
249
249
  post '/users' do
250
250
  name = params[:user][:name]
251
251
  admin = params[:user][:admin].to_s == "1"
@@ -256,7 +256,7 @@ module GitAuth
256
256
  redirect root_with_message("There was an error adding the requested user.")
257
257
  end
258
258
  end
259
-
259
+
260
260
  delete '/users/:name' do
261
261
  user = GitAuth::User.get(params[:name])
262
262
  if user.nil?
@@ -266,9 +266,9 @@ module GitAuth
266
266
  redirect root_with_message("User removed.")
267
267
  end
268
268
  end
269
-
269
+
270
270
  # Create and Update Groups
271
-
271
+
272
272
  post '/groups' do
273
273
  if GitAuth::Group.create(params[:group][:name])
274
274
  redirect root_with_message("Group added")
@@ -276,7 +276,7 @@ module GitAuth
276
276
  redirect root_with_message("There was an error adding the requested group.")
277
277
  end
278
278
  end
279
-
279
+
280
280
  post '/groups/:name' do
281
281
  group = GitAuth::Group.get(params[:name])
282
282
  if group.nil?
@@ -293,7 +293,7 @@ module GitAuth
293
293
  redirect u("/groups/#{URI.encode(group.name)}")
294
294
  end
295
295
  end
296
-
296
+
297
297
  delete '/groups/:name' do
298
298
  group = GitAuth::Group.get(params[:name])
299
299
  if group.nil?
@@ -303,12 +303,12 @@ module GitAuth
303
303
  redirect root_with_message("Group removed.")
304
304
  end
305
305
  end
306
-
306
+
307
307
  # Misc Helpers
308
-
308
+
309
309
  def root_with_message(message)
310
310
  u("/?message=#{URI.encode(message)}")
311
311
  end
312
-
312
+
313
313
  end
314
314
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5.2
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Darcy Laycock
@@ -9,79 +15,119 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-09-30 00:00:00 +08:00
18
+ date: 2011-06-26 00:00:00 +08:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: rack
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 1
32
+ - 0
23
33
  version: "1.0"
24
- version:
34
+ type: :runtime
35
+ version_requirements: *id001
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: sinatra
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
30
41
  requirements:
31
42
  - - ">="
32
43
  - !ruby/object:Gem::Version
44
+ hash: 59
45
+ segments:
46
+ - 0
47
+ - 9
48
+ - 0
33
49
  version: 0.9.0
34
- version:
50
+ type: :runtime
51
+ version_requirements: *id002
35
52
  - !ruby/object:Gem::Dependency
36
53
  name: perennial
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
40
57
  requirements:
41
58
  - - ">="
42
59
  - !ruby/object:Gem::Version
60
+ hash: 93
61
+ segments:
62
+ - 1
63
+ - 0
64
+ - 0
65
+ - 1
43
66
  version: 1.0.0.1
44
- version:
67
+ type: :runtime
68
+ version_requirements: *id003
45
69
  - !ruby/object:Gem::Dependency
46
70
  name: thoughtbot-shoulda
47
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
50
74
  requirements:
51
75
  - - ">="
52
76
  - !ruby/object:Gem::Version
77
+ hash: 15
78
+ segments:
79
+ - 2
80
+ - 0
81
+ - 0
53
82
  version: 2.0.0
54
- version:
83
+ type: :development
84
+ version_requirements: *id004
55
85
  - !ruby/object:Gem::Dependency
56
86
  name: redgreen
57
- type: :development
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
60
90
  requirements:
61
91
  - - ">="
62
92
  - !ruby/object:Gem::Version
93
+ hash: 23
94
+ segments:
95
+ - 1
96
+ - 0
97
+ - 0
63
98
  version: 1.0.0
64
- version:
99
+ type: :development
100
+ version_requirements: *id005
65
101
  - !ruby/object:Gem::Dependency
66
102
  name: rr
67
- type: :development
68
- version_requirement:
69
- version_requirements: !ruby/object:Gem::Requirement
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
70
106
  requirements:
71
107
  - - ">="
72
108
  - !ruby/object:Gem::Version
109
+ hash: 55
110
+ segments:
111
+ - 0
112
+ - 10
113
+ - 0
73
114
  version: 0.10.0
74
- version:
115
+ type: :development
116
+ version_requirements: *id006
75
117
  - !ruby/object:Gem::Dependency
76
118
  name: rack-test
77
- type: :development
78
- version_requirement:
79
- version_requirements: !ruby/object:Gem::Requirement
119
+ prerelease: false
120
+ requirement: &id007 !ruby/object:Gem::Requirement
121
+ none: false
80
122
  requirements:
81
123
  - - ">="
82
124
  - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
83
128
  version: "0"
84
- version:
129
+ type: :development
130
+ version_requirements: *id007
85
131
  description: A library to enable per user / group authentication on a read / write basis for git repositories running over ssh
86
132
  email: sutto@sutto.net
87
133
  executables:
@@ -120,7 +166,7 @@ files:
120
166
  - views/layout.erb
121
167
  - views/repo.erb
122
168
  - views/user.erb
123
- has_rdoc: false
169
+ has_rdoc: true
124
170
  homepage: http://brownbeagle.com.au/
125
171
  licenses: []
126
172
 
@@ -130,21 +176,27 @@ rdoc_options: []
130
176
  require_paths:
131
177
  - lib
132
178
  required_ruby_version: !ruby/object:Gem::Requirement
179
+ none: false
133
180
  requirements:
134
181
  - - ">="
135
182
  - !ruby/object:Gem::Version
183
+ hash: 3
184
+ segments:
185
+ - 0
136
186
  version: "0"
137
- version:
138
187
  required_rubygems_version: !ruby/object:Gem::Requirement
188
+ none: false
139
189
  requirements:
140
190
  - - ">="
141
191
  - !ruby/object:Gem::Version
192
+ hash: 3
193
+ segments:
194
+ - 0
142
195
  version: "0"
143
- version:
144
196
  requirements: []
145
197
 
146
198
  rubyforge_project:
147
- rubygems_version: 1.3.2
199
+ rubygems_version: 1.3.9.2
148
200
  signing_key:
149
201
  specification_version: 3
150
202
  summary: An authentication manager for Git repositories served over SSH