Mercurial > kallithea
comparison rhodecode/lib/middleware/simplegit.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
This imports changes between changesets 21af6c4eab3d and 6177597791c2 in
RhodeCode's original repository, including only changes to Python files and HTML.
RhodeCode clearly licensed its changes to these files under GPLv3
in their /LICENSE file, which states the following:
The Python code and integrated HTML are licensed under the GPLv3 license.
(See:
https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE
or
http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE
for an online copy of that LICENSE file)
Conservancy reviewed these changes and confirmed that they can be licensed as
a whole to the Kallithea project under GPLv3-only.
While some of the contents committed herein are clearly licensed
GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the
statement above from RhodeCode indicates that they intend GPLv3-only as their
license, per GPLv3ยง14 and other relevant sections of GPLv3.
author | Bradley M. Kuhn <bkuhn@sfconservancy.org> |
---|---|
date | Wed, 02 Jul 2014 19:03:13 -0400 |
parents | a5888ca796b5 |
children | 7e5f8c12a3fc |
comparison
equal
deleted
inserted
replaced
4115:8b7294a804a0 | 4116:ffd45b185016 |
---|---|
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """ | |
3 rhodecode.lib.middleware.simplegit | |
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
5 | |
6 SimpleGit middleware for handling git protocol request (push/clone etc.) | |
7 It's implemented with basic auth function | |
8 | |
9 :created_on: Apr 28, 2010 | |
10 :author: marcink | |
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> | |
12 :license: GPLv3, see COPYING for more details. | |
13 """ | |
14 # This program is free software: you can redistribute it and/or modify | 2 # This program is free software: you can redistribute it and/or modify |
15 # it under the terms of the GNU General Public License as published by | 3 # it under the terms of the GNU General Public License as published by |
16 # the Free Software Foundation, either version 3 of the License, or | 4 # the Free Software Foundation, either version 3 of the License, or |
17 # (at your option) any later version. | 5 # (at your option) any later version. |
18 # | 6 # |
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 # GNU General Public License for more details. | 10 # GNU General Public License for more details. |
23 # | 11 # |
24 # You should have received a copy of the GNU General Public License | 12 # You should have received a copy of the GNU General Public License |
25 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
14 """ | |
15 rhodecode.lib.middleware.simplegit | |
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
17 | |
18 SimpleGit middleware for handling git protocol request (push/clone etc.) | |
19 It's implemented with basic auth function | |
20 | |
21 :created_on: Apr 28, 2010 | |
22 :author: marcink | |
23 :copyright: (c) 2013 RhodeCode GmbH. | |
24 :license: GPLv3, see LICENSE for more details. | |
25 | |
26 """ | |
27 | |
26 | 28 |
27 import os | 29 import os |
28 import re | 30 import re |
29 import logging | 31 import logging |
30 import traceback | 32 import traceback |
31 | 33 |
32 from dulwich import server as dulserver | |
33 from dulwich.web import LimitedInputFilter, GunzipFilter | |
34 from rhodecode.lib.exceptions import HTTPLockedRC | |
35 from rhodecode.lib.hooks import pre_pull | |
36 | |
37 | |
38 class SimpleGitUploadPackHandler(dulserver.UploadPackHandler): | |
39 | |
40 def handle(self): | |
41 write = lambda x: self.proto.write_sideband(1, x) | |
42 | |
43 graph_walker = dulserver.ProtocolGraphWalker(self, | |
44 self.repo.object_store, | |
45 self.repo.get_peeled) | |
46 objects_iter = self.repo.fetch_objects( | |
47 graph_walker.determine_wants, graph_walker, self.progress, | |
48 get_tagged=self.get_tagged) | |
49 | |
50 # Did the process short-circuit (e.g. in a stateless RPC call)? Note | |
51 # that the client still expects a 0-object pack in most cases. | |
52 if objects_iter is None: | |
53 return | |
54 | |
55 self.progress("counting objects: %d, done.\n" % len(objects_iter)) | |
56 dulserver.write_pack_objects(dulserver.ProtocolFile(None, write), | |
57 objects_iter) | |
58 messages = ['thank you for using rhodecode'] | |
59 | |
60 for msg in messages: | |
61 self.progress(msg + "\n") | |
62 # we are done | |
63 self.proto.write("0000") | |
64 | |
65 | |
66 dulserver.DEFAULT_HANDLERS = { | |
67 #git-ls-remote, git-clone, git-fetch and git-pull | |
68 'git-upload-pack': SimpleGitUploadPackHandler, | |
69 #git-push | |
70 'git-receive-pack': dulserver.ReceivePackHandler, | |
71 } | |
72 | |
73 # not used for now until dulwich gets fixed | |
74 #from dulwich.repo import Repo | |
75 #from dulwich.web import make_wsgi_chain | |
76 | |
77 from paste.httpheaders import REMOTE_USER, AUTH_TYPE | 34 from paste.httpheaders import REMOTE_USER, AUTH_TYPE |
78 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError, \ | 35 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError, \ |
79 HTTPBadRequest, HTTPNotAcceptable | 36 HTTPNotAcceptable |
37 from rhodecode.model.db import User, RhodeCodeUi | |
80 | 38 |
81 from rhodecode.lib.utils2 import safe_str, fix_PATH, get_server_url,\ | 39 from rhodecode.lib.utils2 import safe_str, fix_PATH, get_server_url,\ |
82 _set_extras | 40 _set_extras |
83 from rhodecode.lib.base import BaseVCSController | 41 from rhodecode.lib.base import BaseVCSController |
84 from rhodecode.lib.auth import get_container_username | 42 from rhodecode.lib.utils import make_ui, is_valid_repo |
85 from rhodecode.lib.utils import is_valid_repo, make_ui | 43 from rhodecode.lib.exceptions import HTTPLockedRC |
86 from rhodecode.lib.compat import json | 44 from rhodecode.lib.hooks import pre_pull |
87 from rhodecode.model.db import User, RhodeCodeUi | 45 from rhodecode.lib import auth_modules |
88 | 46 |
89 log = logging.getLogger(__name__) | 47 log = logging.getLogger(__name__) |
90 | 48 |
91 | 49 |
92 GIT_PROTO_PAT = re.compile(r'^/(.+)/(info/refs|git-upload-pack|git-receive-pack)') | 50 GIT_PROTO_PAT = re.compile(r'^/(.+)/(info/refs|git-upload-pack|git-receive-pack)') |
137 # CHECK ANONYMOUS PERMISSION | 95 # CHECK ANONYMOUS PERMISSION |
138 #====================================================================== | 96 #====================================================================== |
139 if action in ['pull', 'push']: | 97 if action in ['pull', 'push']: |
140 anonymous_user = self.__get_user('default') | 98 anonymous_user = self.__get_user('default') |
141 username = anonymous_user.username | 99 username = anonymous_user.username |
142 anonymous_perm = self._check_permission(action, anonymous_user, | 100 if anonymous_user.active: |
143 repo_name, ip_addr) | 101 # ONLY check permissions if the user is activated |
144 | 102 anonymous_perm = self._check_permission(action, anonymous_user, |
145 if not anonymous_perm or not anonymous_user.active: | 103 repo_name, ip_addr) |
104 else: | |
105 anonymous_perm = False | |
106 | |
107 if not anonymous_user.active or not anonymous_perm: | |
108 if not anonymous_user.active: | |
109 log.debug('Anonymous access is disabled, running ' | |
110 'authentication') | |
111 | |
146 if not anonymous_perm: | 112 if not anonymous_perm: |
147 log.debug('Not enough credentials to access this ' | 113 log.debug('Not enough credentials to access this ' |
148 'repository as anonymous user') | 114 'repository as anonymous user') |
149 if not anonymous_user.active: | 115 |
150 log.debug('Anonymous access is disabled, running ' | 116 username = None |
151 'authentication') | |
152 #============================================================== | 117 #============================================================== |
153 # DEFAULT PERM FAILED OR ANONYMOUS ACCESS IS DISABLED SO WE | 118 # DEFAULT PERM FAILED OR ANONYMOUS ACCESS IS DISABLED SO WE |
154 # NEED TO AUTHENTICATE AND ASK FOR AUTH USER PERMISSIONS | 119 # NEED TO AUTHENTICATE AND ASK FOR AUTH USER PERMISSIONS |
155 #============================================================== | 120 #============================================================== |
156 | 121 |
157 # Attempting to retrieve username from the container | 122 # try to auth based on environ, container auth methods |
158 username = get_container_username(environ, self.config) | 123 log.debug('Running PRE-AUTH for container based authentication') |
124 pre_auth = auth_modules.authenticate('', '', environ) | |
125 if pre_auth and pre_auth.get('username'): | |
126 username = pre_auth['username'] | |
127 log.debug('PRE-AUTH got %s as username' % username) | |
159 | 128 |
160 # If not authenticated by the container, running basic auth | 129 # If not authenticated by the container, running basic auth |
161 if not username: | 130 if not username: |
162 self.authenticate.realm = \ | 131 self.authenticate.realm = \ |
163 safe_str(self.config['rhodecode_realm']) | 132 safe_str(self.config['rhodecode_realm']) |
257 app = make_wsgi_app( | 226 app = make_wsgi_app( |
258 repo_root=safe_str(self.basepath), | 227 repo_root=safe_str(self.basepath), |
259 repo_name=repo_name, | 228 repo_name=repo_name, |
260 extras=extras, | 229 extras=extras, |
261 ) | 230 ) |
262 app = GunzipFilter(LimitedInputFilter(app)) | |
263 return app | 231 return app |
264 | 232 |
265 def __get_repository(self, environ): | 233 def __get_repository(self, environ): |
266 """ | 234 """ |
267 Gets repository name out of PATH_INFO header | 235 Gets repository name out of PATH_INFO header |