Mercurial > kallithea
annotate kallithea/lib/middleware/simplegit.py @ 5986:b99e00fb6dd4
lock: simplify debug logging - use the actual response code
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Sat, 25 Jun 2016 02:57:44 +0200 |
parents | 52356a58c1f6 |
children | 81ff11476d16 |
rev | line source |
---|---|
903
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
1 # -*- coding: utf-8 -*- |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
5 # (at your option) any later version. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
989
diff
changeset
|
6 # |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 # This program is distributed in the hope that it will be useful, |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 # GNU General Public License for more details. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
989
diff
changeset
|
11 # |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
14 """ |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
15 kallithea.lib.middleware.simplegit |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
17 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
18 SimpleGit middleware for handling git protocol request (push/clone etc.) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
19 It's implemented with basic auth function |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
20 |
4211
1948ede028ef
RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4208
diff
changeset
|
21 This file was forked by the Kallithea project in July 2014. |
1948ede028ef
RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4208
diff
changeset
|
22 Original author and date, and relevant copyright and licensing information is below: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
23 :created_on: Apr 28, 2010 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
24 :author: marcink |
4211
1948ede028ef
RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4208
diff
changeset
|
25 :copyright: (c) 2013 RhodeCode GmbH, and others. |
4208
ad38f9f93b3b
Correct licensing information in individual files.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4203
diff
changeset
|
26 :license: GPLv3, see LICENSE.md for more details. |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
27 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
28 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
29 |
635
fd63782c4426
Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents:
625
diff
changeset
|
30 |
903
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
31 import os |
2052
320806ff6be2
fixes git-protocol with
Marcin Kuzminski <marcin@python-works.com>
parents:
2026
diff
changeset
|
32 import re |
903
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
33 import logging |
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
34 import traceback |
635
fd63782c4426
Fixed age, for new vcs implementation. Removed all obsolete date formatters
Marcin Kuzminski <marcin@python-works.com>
parents:
625
diff
changeset
|
35 |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 from paste.httpheaders import REMOTE_USER, AUTH_TYPE |
2668
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2578
diff
changeset
|
37 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError, \ |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
38 HTTPNotAcceptable |
4203
9daad8c50b37
Rename database classes (but not table names)
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4187
diff
changeset
|
39 from kallithea.model.db import User, Ui |
903
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
40 |
5618 | 41 from kallithea.lib.utils2 import safe_str, safe_unicode, fix_PATH, get_server_url, \ |
3577
238486bb71ab
Switched handling of RhodeCode extra params in consistent way
Marcin Kuzminski <marcin@python-works.com>
parents:
3522
diff
changeset
|
42 _set_extras |
5414
d9386a3924db
vcs: invalidate repo caches _after_ a push finishes
Mads Kiilerich <madski@unity3d.com>
parents:
5375
diff
changeset
|
43 from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
44 from kallithea.lib.utils import make_ui, is_valid_repo |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
45 from kallithea.lib.exceptions import HTTPLockedRC |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
46 from kallithea.lib.hooks import pre_pull |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
47 from kallithea.lib import auth_modules |
903
04c9bb9ca6d6
code docs, updates
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
48 |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 log = logging.getLogger(__name__) |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 |
1275
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
51 |
2061
9f0fe6777833
merge pull request #32 from codingtony
Marcin Kuzminski <marcin@python-works.com>
parents:
2060
diff
changeset
|
52 GIT_PROTO_PAT = re.compile(r'^/(.+)/(info/refs|git-upload-pack|git-receive-pack)') |
2052
320806ff6be2
fixes git-protocol with
Marcin Kuzminski <marcin@python-works.com>
parents:
2026
diff
changeset
|
53 |
2058
fb51a6fc10ae
updated CONTRIBUTORS
Marcin Kuzminski <marcin@python-works.com>
parents:
2057
diff
changeset
|
54 |
2060
572855f7a392
reverted git fix as it broke pushing
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
55 def is_git(environ): |
2061
9f0fe6777833
merge pull request #32 from codingtony
Marcin Kuzminski <marcin@python-works.com>
parents:
2060
diff
changeset
|
56 path_info = environ['PATH_INFO'] |
9f0fe6777833
merge pull request #32 from codingtony
Marcin Kuzminski <marcin@python-works.com>
parents:
2060
diff
changeset
|
57 isgit_path = GIT_PROTO_PAT.match(path_info) |
5375
0210d0b769d4
cleanup: pass log strings unformatted - avoid unnecessary % formatting when not logging
Mads Kiilerich <madski@unity3d.com>
parents:
5374
diff
changeset
|
58 log.debug('pathinfo: %s detected as Git %s', |
0210d0b769d4
cleanup: pass log strings unformatted - avoid unnecessary % formatting when not logging
Mads Kiilerich <madski@unity3d.com>
parents:
5374
diff
changeset
|
59 path_info, isgit_path is not None |
2100
f0649c7cf94a
fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents:
2090
diff
changeset
|
60 ) |
2061
9f0fe6777833
merge pull request #32 from codingtony
Marcin Kuzminski <marcin@python-works.com>
parents:
2060
diff
changeset
|
61 return isgit_path |
2052
320806ff6be2
fixes git-protocol with
Marcin Kuzminski <marcin@python-works.com>
parents:
2026
diff
changeset
|
62 |
2058
fb51a6fc10ae
updated CONTRIBUTORS
Marcin Kuzminski <marcin@python-works.com>
parents:
2057
diff
changeset
|
63 |
1761
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1630
diff
changeset
|
64 class SimpleGit(BaseVCSController): |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 |
1761
b265be1c6093
Wrapped calls for git and hg middleware in extra block that clears db Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
1630
diff
changeset
|
66 def _handle_request(self, environ, start_response): |
2060
572855f7a392
reverted git fix as it broke pushing
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
67 if not is_git(environ): |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 return self.application(environ, start_response) |
4448
8e26c46e9abe
https: introduce https_fixup config setting to enable the special https hacks
Mads Kiilerich <madski@unity3d.com>
parents:
4218
diff
changeset
|
69 if not self._check_ssl(environ): |
2668
f0851f37d6be
Implementes #509 require SSL flag now works for both git and mercurial.
Marcin Kuzminski <marcin@python-works.com>
parents:
2578
diff
changeset
|
70 return HTTPNotAcceptable('SSL REQUIRED !')(environ, start_response) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
71 |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
2969
diff
changeset
|
72 ip_addr = self._get_ip_addr(environ) |
1496
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
73 username = None |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
74 self._git_first_op = False |
898
9c4851dce8e6
fixed error propagation when using git/mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
756
diff
changeset
|
75 # skip passing error to error controller |
9c4851dce8e6
fixed error propagation when using git/mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
756
diff
changeset
|
76 environ['pylons.status_code_redirect'] = True |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
655
diff
changeset
|
77 |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
78 #====================================================================== |
1496
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
79 # EXTRACT REPOSITORY NAME FROM ENV |
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
80 #====================================================================== |
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
81 try: |
5616
890189aa2bfe
middleware: decode the repo_name received from http header to unicode
Mads Kiilerich <madski@unity3d.com>
parents:
5414
diff
changeset
|
82 str_repo_name = self.__get_repository(environ) |
890189aa2bfe
middleware: decode the repo_name received from http header to unicode
Mads Kiilerich <madski@unity3d.com>
parents:
5414
diff
changeset
|
83 repo_name = safe_unicode(str_repo_name) |
5375
0210d0b769d4
cleanup: pass log strings unformatted - avoid unnecessary % formatting when not logging
Mads Kiilerich <madski@unity3d.com>
parents:
5374
diff
changeset
|
84 log.debug('Extracted repo name is %s', repo_name) |
5616
890189aa2bfe
middleware: decode the repo_name received from http header to unicode
Mads Kiilerich <madski@unity3d.com>
parents:
5414
diff
changeset
|
85 except Exception as e: |
890189aa2bfe
middleware: decode the repo_name received from http header to unicode
Mads Kiilerich <madski@unity3d.com>
parents:
5414
diff
changeset
|
86 log.error('error extracting repo_name: %r', e) |
1496
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
87 return HTTPInternalServerError()(environ, start_response) |
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
88 |
2122
c137b8a81f8e
git+hg middleware do repo verification at earliest possible state, giving 404 as fast as possible. If repo is not found.
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
89 # quick check if that dir exists... |
3625
260a7a01b054
follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents:
3579
diff
changeset
|
90 if not is_valid_repo(repo_name, self.basepath, 'git'): |
2122
c137b8a81f8e
git+hg middleware do repo verification at earliest possible state, giving 404 as fast as possible. If repo is not found.
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
91 return HTTPNotFound()(environ, start_response) |
c137b8a81f8e
git+hg middleware do repo verification at earliest possible state, giving 404 as fast as possible. If repo is not found.
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
92 |
2060
572855f7a392
reverted git fix as it broke pushing
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
93 #====================================================================== |
572855f7a392
reverted git fix as it broke pushing
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
94 # GET ACTION PULL or PUSH |
572855f7a392
reverted git fix as it broke pushing
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
95 #====================================================================== |
572855f7a392
reverted git fix as it broke pushing
Marcin Kuzminski <marcin@python-works.com>
parents:
2058
diff
changeset
|
96 action = self.__get_action(environ) |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
97 |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
98 #====================================================================== |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
99 # CHECK ANONYMOUS PERMISSION |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
100 #====================================================================== |
1496
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
101 if action in ['pull', 'push']: |
5692
52356a58c1f6
middleware: allow git and hg users to use email address instead of the username
Andrew Shadura <andrew@shadura.me>
parents:
5618
diff
changeset
|
102 anonymous_user = User.get_default_user(cache=True) |
1496
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
103 username = anonymous_user.username |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
104 if anonymous_user.active: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
105 # ONLY check permissions if the user is activated |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
106 anonymous_perm = self._check_permission(action, anonymous_user, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
107 repo_name, ip_addr) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
108 else: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
109 anonymous_perm = False |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
110 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
111 if not anonymous_user.active or not anonymous_perm: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
112 if not anonymous_user.active: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
113 log.debug('Anonymous access is disabled, running ' |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
114 'authentication') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
115 |
3625
260a7a01b054
follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents:
3579
diff
changeset
|
116 if not anonymous_perm: |
1275
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
117 log.debug('Not enough credentials to access this ' |
2723276285ae
pep8ify middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
118 'repository as anonymous user') |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
119 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
120 username = None |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
121 #============================================================== |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
989
diff
changeset
|
122 # DEFAULT PERM FAILED OR ANONYMOUS ACCESS IS DISABLED SO WE |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
123 # NEED TO AUTHENTICATE AND ASK FOR AUTH USER PERMISSIONS |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
124 #============================================================== |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
125 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
126 # try to auth based on environ, container auth methods |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
127 log.debug('Running PRE-AUTH for container based authentication') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
128 pre_auth = auth_modules.authenticate('', '', environ) |
5337
dd87009b518b
auth: various minor cleanup of general auth functionality
Mads Kiilerich <madski@unity3d.com>
parents:
4527
diff
changeset
|
129 if pre_auth is not None and pre_auth.get('username'): |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
130 username = pre_auth['username'] |
5375
0210d0b769d4
cleanup: pass log strings unformatted - avoid unnecessary % formatting when not logging
Mads Kiilerich <madski@unity3d.com>
parents:
5374
diff
changeset
|
131 log.debug('PRE-AUTH got %s as username', username) |
1630
25d8e4836bc2
Improved container-based auth support for middleware
Liad Shani <liadff@gmail.com>
parents:
1620
diff
changeset
|
132 |
25d8e4836bc2
Improved container-based auth support for middleware
Liad Shani <liadff@gmail.com>
parents:
1620
diff
changeset
|
133 # If not authenticated by the container, running basic auth |
25d8e4836bc2
Improved container-based auth support for middleware
Liad Shani <liadff@gmail.com>
parents:
1620
diff
changeset
|
134 if not username: |
1401
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1293
diff
changeset
|
135 self.authenticate.realm = \ |
4218
f373f182b756
Drop rhodecode_ prefix for known setting names that are stored in kallithea_settings without prefix
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4212
diff
changeset
|
136 safe_str(self.config['realm']) |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
137 result = self.authenticate(environ) |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
138 if isinstance(result, str): |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
139 AUTH_TYPE.update(environ, 'basic') |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
140 REMOTE_USER.update(environ, result) |
1630
25d8e4836bc2
Improved container-based auth support for middleware
Liad Shani <liadff@gmail.com>
parents:
1620
diff
changeset
|
141 username = result |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
142 else: |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
143 return result.wsgi_application(environ, start_response) |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
144 |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
145 #============================================================== |
1630
25d8e4836bc2
Improved container-based auth support for middleware
Liad Shani <liadff@gmail.com>
parents:
1620
diff
changeset
|
146 # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
147 #============================================================== |
2500
94ef0b609d17
possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents:
2468
diff
changeset
|
148 try: |
5692
52356a58c1f6
middleware: allow git and hg users to use email address instead of the username
Andrew Shadura <andrew@shadura.me>
parents:
5618
diff
changeset
|
149 user = User.get_by_username_or_email(username) |
2500
94ef0b609d17
possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents:
2468
diff
changeset
|
150 if user is None or not user.active: |
94ef0b609d17
possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents:
2468
diff
changeset
|
151 return HTTPForbidden()(environ, start_response) |
94ef0b609d17
possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents:
2468
diff
changeset
|
152 username = user.username |
3631
10b4e34841a4
Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
153 except Exception: |
2500
94ef0b609d17
possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents:
2468
diff
changeset
|
154 log.error(traceback.format_exc()) |
94ef0b609d17
possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents:
2468
diff
changeset
|
155 return HTTPInternalServerError()(environ, start_response) |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
156 |
2500
94ef0b609d17
possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents:
2468
diff
changeset
|
157 #check permissions for this repository |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
2969
diff
changeset
|
158 perm = self._check_permission(action, user, repo_name, ip_addr) |
3625
260a7a01b054
follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents:
3579
diff
changeset
|
159 if not perm: |
2500
94ef0b609d17
possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents:
2468
diff
changeset
|
160 return HTTPForbidden()(environ, start_response) |
94ef0b609d17
possible fix for #486 undefined variable username
Marcin Kuzminski <marcin@python-works.com>
parents:
2468
diff
changeset
|
161 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
162 # extras are injected into UI object and later available |
4212
24c0d584ba86
General renaming to Kallithea
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4211
diff
changeset
|
163 # in hooks executed by kallithea |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
164 from kallithea import CONFIG |
2969
5085e51fba3a
Implemented #628: Pass server URL to rc-extensions hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
2869
diff
changeset
|
165 server_url = get_server_url(environ) |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
166 extras = { |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
2969
diff
changeset
|
167 'ip': ip_addr, |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
168 'username': username, |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
169 'action': action, |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
170 'repository': repo_name, |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
171 'scm': 'git', |
2858
dd2d5b65cae9
Also export config filename via extras.config in simplegit middleware (juste like for the simplehg one)
Vincent Caron <vcaron@bearstech.com>
parents:
2726
diff
changeset
|
172 'config': CONFIG['__file__'], |
2969
5085e51fba3a
Implemented #628: Pass server URL to rc-extensions hooks
Marcin Kuzminski <marcin@python-works.com>
parents:
2869
diff
changeset
|
173 'server_url': server_url, |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
174 'make_lock': None, |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
175 'locked_by': [None, None] |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
176 } |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
177 |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
178 #=================================================================== |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
179 # GIT REQUEST HANDLING |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
180 #=================================================================== |
3634
336184b9f4cf
fix unicode issues on logging in SCM middlewares
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
181 repo_path = os.path.join(safe_str(self.basepath),str_repo_name) |
5375
0210d0b769d4
cleanup: pass log strings unformatted - avoid unnecessary % formatting when not logging
Mads Kiilerich <madski@unity3d.com>
parents:
5374
diff
changeset
|
182 log.debug('Repository path is %s', repo_path) |
1496
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
183 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
184 # CHECK LOCKING only if it's not ANONYMOUS USER |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
185 if username != User.DEFAULT_USER: |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
186 log.debug('Checking locking on repository') |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
187 (make_lock, |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
188 locked, |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
189 locked_by) = self._check_locking_state( |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
190 environ=environ, action=action, |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
191 repo=repo_name, user_id=user.user_id |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
192 ) |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
193 # store the make_lock for later evaluation in hooks |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
194 extras.update({'make_lock': make_lock, |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
195 'locked_by': locked_by}) |
3823
972ad33c5610
removed duplicate code that set os.environ['RC_SCM_DATA']
Marcin Kuzminski <marcin@python-works.com>
parents:
3634
diff
changeset
|
196 |
2869
ccbdff90e5a0
fix for issue #578 git hooks sometimes cannot be executed due to different python they runned under, this commit tries to fix that by altering the PATH env variable using current python that rhodecode is running
Marcin Kuzminski <marcin@python-works.com>
parents:
2858
diff
changeset
|
197 fix_PATH() |
5375
0210d0b769d4
cleanup: pass log strings unformatted - avoid unnecessary % formatting when not logging
Mads Kiilerich <madski@unity3d.com>
parents:
5374
diff
changeset
|
198 log.debug('HOOKS extras is %s', extras) |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
199 baseui = make_ui('db') |
2209
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2207
diff
changeset
|
200 self.__inject_extras(repo_path, baseui, extras) |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2207
diff
changeset
|
201 |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
202 try: |
3277
5440ea1d0628
don't invalidate cache before handling hook
Marcin Kuzminski <marcin@python-works.com>
parents:
3135
diff
changeset
|
203 self._handle_githooks(repo_name, action, baseui, environ) |
5375
0210d0b769d4
cleanup: pass log strings unformatted - avoid unnecessary % formatting when not logging
Mads Kiilerich <madski@unity3d.com>
parents:
5374
diff
changeset
|
204 log.info('%s action on Git repo "%s" by "%s" from %s', |
0210d0b769d4
cleanup: pass log strings unformatted - avoid unnecessary % formatting when not logging
Mads Kiilerich <madski@unity3d.com>
parents:
5374
diff
changeset
|
205 action, str_repo_name, safe_str(username), ip_addr) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
206 app = self.__make_app(repo_name, repo_path, extras) |
5414
d9386a3924db
vcs: invalidate repo caches _after_ a push finishes
Mads Kiilerich <madski@unity3d.com>
parents:
5375
diff
changeset
|
207 result = app(environ, start_response) |
d9386a3924db
vcs: invalidate repo caches _after_ a push finishes
Mads Kiilerich <madski@unity3d.com>
parents:
5375
diff
changeset
|
208 if action == 'push': |
d9386a3924db
vcs: invalidate repo caches _after_ a push finishes
Mads Kiilerich <madski@unity3d.com>
parents:
5375
diff
changeset
|
209 result = WSGIResultCloseCallback(result, |
d9386a3924db
vcs: invalidate repo caches _after_ a push finishes
Mads Kiilerich <madski@unity3d.com>
parents:
5375
diff
changeset
|
210 lambda: self._invalidate_cache(repo_name)) |
d9386a3924db
vcs: invalidate repo caches _after_ a push finishes
Mads Kiilerich <madski@unity3d.com>
parents:
5375
diff
changeset
|
211 return result |
5374
d69aa464f373
cleanup: consistently use 'except ... as ...:'
Mads Kiilerich <madski@unity3d.com>
parents:
5337
diff
changeset
|
212 except HTTPLockedRC as e: |
5986
b99e00fb6dd4
lock: simplify debug logging - use the actual response code
Mads Kiilerich <madski@unity3d.com>
parents:
5692
diff
changeset
|
213 log.debug('Locked, response %s: %s', e.code, e.title) |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
214 return e(environ, start_response) |
1496
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
215 except Exception: |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
216 log.error(traceback.format_exc()) |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
217 return HTTPInternalServerError()(environ, start_response) |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
218 |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
219 def __make_app(self, repo_name, repo_path, extras): |
1496
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
220 """ |
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
221 Make an wsgi application using dulserver |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1813
diff
changeset
|
222 |
1496
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
223 :param repo_name: name of the repository |
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
224 :param repo_path: full path to the repository |
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
225 """ |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
226 |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
227 from kallithea.lib.middleware.pygrack import make_wsgi_app |
2382
034e4fe1ebb2
changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
2322
diff
changeset
|
228 app = make_wsgi_app( |
2468 | 229 repo_root=safe_str(self.basepath), |
2382
034e4fe1ebb2
changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
2322
diff
changeset
|
230 repo_name=repo_name, |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
231 extras=extras, |
2382
034e4fe1ebb2
changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
2322
diff
changeset
|
232 ) |
034e4fe1ebb2
changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
2322
diff
changeset
|
233 return app |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
234 |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
235 def __get_repository(self, environ): |
1496
f4fed0b32103
Rewrote git middleware with the same pattern as recent fix for #176
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
236 """ |
4089
a5888ca796b5
Fixed spelling of get's to gets
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
237 Gets repository name out of PATH_INFO header |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
989
diff
changeset
|
238 |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
239 :param environ: environ where PATH_INFO is stored |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
240 """ |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
241 try: |
1813
a8c66e870bd0
implements #285: Implemented non changeable urls for clone url, and web views
Marcin Kuzminski <marcin@python-works.com>
parents:
1761
diff
changeset
|
242 environ['PATH_INFO'] = self._get_by_id(environ['PATH_INFO']) |
2061
9f0fe6777833
merge pull request #32 from codingtony
Marcin Kuzminski <marcin@python-works.com>
parents:
2060
diff
changeset
|
243 repo_name = GIT_PROTO_PAT.match(environ['PATH_INFO']).group(1) |
3631
10b4e34841a4
Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents:
3625
diff
changeset
|
244 except Exception: |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
245 log.error(traceback.format_exc()) |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
246 raise |
2052
320806ff6be2
fixes git-protocol with
Marcin Kuzminski <marcin@python-works.com>
parents:
2026
diff
changeset
|
247 |
918
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
248 return repo_name |
b2d5868cc4b8
fixes #97 in simplehg and simplegit, force casting to headers
Marcin Kuzminski <marcin@python-works.com>
parents:
903
diff
changeset
|
249 |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
250 def __get_action(self, environ): |
2090
2632a49cb402
fixes issue #372
Marcin Kuzminski <marcin@python-works.com>
parents:
2061
diff
changeset
|
251 """ |
2632a49cb402
fixes issue #372
Marcin Kuzminski <marcin@python-works.com>
parents:
2061
diff
changeset
|
252 Maps git request commands into a pull or push command. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
989
diff
changeset
|
253 |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
254 :param environ: |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
255 """ |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
256 service = environ['QUERY_STRING'].split('=') |
2090
2632a49cb402
fixes issue #372
Marcin Kuzminski <marcin@python-works.com>
parents:
2061
diff
changeset
|
257 |
620
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
258 if len(service) > 1: |
19a62a5490fe
added base simple git middleware, for future usage
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
259 service_cmd = service[1] |
2058
fb51a6fc10ae
updated CONTRIBUTORS
Marcin Kuzminski <marcin@python-works.com>
parents:
2057
diff
changeset
|
260 mapping = { |
fb51a6fc10ae
updated CONTRIBUTORS
Marcin Kuzminski <marcin@python-works.com>
parents:
2057
diff
changeset
|
261 'git-receive-pack': 'push', |
fb51a6fc10ae
updated CONTRIBUTORS
Marcin Kuzminski <marcin@python-works.com>
parents:
2057
diff
changeset
|
262 'git-upload-pack': 'pull', |
fb51a6fc10ae
updated CONTRIBUTORS
Marcin Kuzminski <marcin@python-works.com>
parents:
2057
diff
changeset
|
263 } |
2090
2632a49cb402
fixes issue #372
Marcin Kuzminski <marcin@python-works.com>
parents:
2061
diff
changeset
|
264 op = mapping[service_cmd] |
2632a49cb402
fixes issue #372
Marcin Kuzminski <marcin@python-works.com>
parents:
2061
diff
changeset
|
265 self._git_stored_op = op |
2632a49cb402
fixes issue #372
Marcin Kuzminski <marcin@python-works.com>
parents:
2061
diff
changeset
|
266 return op |
625
d5372213db98
some hacking on simplegit middleware
Marcin Kuzminski <marcin@python-works.com>
parents:
620
diff
changeset
|
267 else: |
2090
2632a49cb402
fixes issue #372
Marcin Kuzminski <marcin@python-works.com>
parents:
2061
diff
changeset
|
268 # try to fallback to stored variable as we don't know if the last |
2632a49cb402
fixes issue #372
Marcin Kuzminski <marcin@python-works.com>
parents:
2061
diff
changeset
|
269 # operation is pull/push |
2632a49cb402
fixes issue #372
Marcin Kuzminski <marcin@python-works.com>
parents:
2061
diff
changeset
|
270 op = getattr(self, '_git_stored_op', 'pull') |
2632a49cb402
fixes issue #372
Marcin Kuzminski <marcin@python-works.com>
parents:
2061
diff
changeset
|
271 return op |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
272 |
2236
37c143aa8616
fixes issue #436 git push error
Marcin Kuzminski <marcin@python-works.com>
parents:
2209
diff
changeset
|
273 def _handle_githooks(self, repo_name, action, baseui, environ): |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2382
diff
changeset
|
274 """ |
2407
8a68e0292232
Change git & hg hooks to post. They shouldn't block as they are used just for logging actions. Futhermore post hooks have access to changesets, so it's much better flexible
Marcin Kuzminski <marcin@python-works.com>
parents:
2402
diff
changeset
|
275 Handles pull action, push is handled by post-receive hook |
2402
2eeb2ed72e55
Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents:
2382
diff
changeset
|
276 """ |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
277 from kallithea.lib.hooks import log_pull_action |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
278 service = environ['QUERY_STRING'].split('=') |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
279 |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
280 if len(service) < 2: |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
281 return |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
282 |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
283 from kallithea.model.db import Repository |
2209
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2207
diff
changeset
|
284 _repo = Repository.get_by_repo_name(repo_name) |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2207
diff
changeset
|
285 _repo = _repo.scm_instance |
2203
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
286 |
d9972f76322e
added emulation of pull hook for git-backend, and dummy git-push hook
Marcin Kuzminski <marcin@python-works.com>
parents:
2197
diff
changeset
|
287 _hooks = dict(baseui.configitems('hooks')) or {} |
2726
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
288 if action == 'pull': |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
289 # stupid git, emulate pre-pull hook ! |
aa17c7a1b8a5
Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents:
2716
diff
changeset
|
290 pre_pull(ui=baseui, repo=_repo._repo) |
4203
9daad8c50b37
Rename database classes (but not table names)
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4187
diff
changeset
|
291 if action == 'pull' and _hooks.get(Ui.HOOK_PULL): |
2236
37c143aa8616
fixes issue #436 git push error
Marcin Kuzminski <marcin@python-works.com>
parents:
2209
diff
changeset
|
292 log_pull_action(ui=baseui, repo=_repo._repo) |
2209
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2207
diff
changeset
|
293 |
5555
32cdc6f70f13
cleanup: stop using mutable default params
Jiří Suchan <yed@vanyli.net>
parents:
5414
diff
changeset
|
294 def __inject_extras(self, repo_path, baseui, extras=None): |
2209
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2207
diff
changeset
|
295 """ |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2207
diff
changeset
|
296 Injects some extra params into baseui instance |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2207
diff
changeset
|
297 |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2207
diff
changeset
|
298 :param baseui: baseui instance |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2207
diff
changeset
|
299 :param extras: dict with extra params to put into baseui |
19a6c23af14b
Implemented pull command for remote repos for git
Marcin Kuzminski <marcin@python-works.com>
parents:
2207
diff
changeset
|
300 """ |
5555
32cdc6f70f13
cleanup: stop using mutable default params
Jiří Suchan <yed@vanyli.net>
parents:
5414
diff
changeset
|
301 _set_extras(extras or {}) |