##// END OF EJS Templates
vcs: Move code for parsing the repository names (url, vcs, acl) from vcs to simplevcs.
Martin Bornhold -
r889:4fa21815 default
parent child Browse files
Show More
@@ -26,6 +26,7 b" It's implemented with basic auth functio"
26 import os
26 import os
27 import logging
27 import logging
28 import importlib
28 import importlib
29 import re
29 from functools import wraps
30 from functools import wraps
30
31
31 from paste.httpheaders import REMOTE_USER, AUTH_TYPE
32 from paste.httpheaders import REMOTE_USER, AUTH_TYPE
@@ -104,6 +105,31 b' class SimpleVCS(object):'
104 auth_ret_code_detection)
105 auth_ret_code_detection)
105 self.ip_addr = '0.0.0.0'
106 self.ip_addr = '0.0.0.0'
106
107
108 def set_repo_names(self, environ):
109 """
110 This will populate the attributes acl_repo_name, url_repo_name and
111 vcs_repo_name on the current instance.
112 """
113 # TODO: martinb: Move to class or module scope.
114 pr_regex = re.compile(
115 '(?P<base_name>(?:[\w-]+)(?:/[\w-]+)*)/'
116 '(?P<repo_name>[\w-]+)'
117 '/pull-request/(?P<pr_id>\d+)/repository')
118
119 self.url_repo_name = self._get_repository_name(environ)
120 match = pr_regex.match(self.url_repo_name)
121
122 if match:
123 match_dict = match.groupdict()
124 self.acl_repo_name = '{base_name}/{repo_name}'.format(**match_dict)
125 self.vcs_repo_name = '{base_name}/.__shadow_{repo_name}_pr-{pr_id}'.format(
126 **match_dict)
127 self.pr_id = match_dict.get('pr_id')
128 else:
129 self.acl_repo_name = self.url_repo_name
130 self.vcs_repo_name = self.url_repo_name
131 self.pr_id = None
132
107 @property
133 @property
108 def repo_name(self):
134 def repo_name(self):
109 # TODO: johbo: Remove, switch to correct repo name attribute
135 # TODO: johbo: Remove, switch to correct repo name attribute
@@ -175,52 +175,37 b' class VCSMiddleware(object):'
175 # translate the _REPO_ID into real repo NAME for usage
175 # translate the _REPO_ID into real repo NAME for usage
176 # in middleware
176 # in middleware
177 environ['PATH_INFO'] = vcs_handler._get_by_id(environ['PATH_INFO'])
177 environ['PATH_INFO'] = vcs_handler._get_by_id(environ['PATH_INFO'])
178 repo_name = vcs_handler._get_repository_name(environ)
179
178
180 acl_repo_name = repo_name
179 # Set repo names for permission checks, vcs and web interaction.
181 vcs_repo_name = repo_name
180 vcs_handler.set_repo_names(environ)
182 url_repo_name = repo_name
183 pr_id = None
184
185 pr_regex = re.compile(
186 '(?P<base_name>(?:[\w-]+)(?:/[\w-]+)*)/'
187 '(?P<repo_name>[\w-]+)'
188 '/pull-request/(?P<pr_id>\d+)/repository')
189 match = pr_regex.match(repo_name)
190 if match:
191 match_dict = match.groupdict()
192 pr_id = match_dict.get('pr_id')
193 acl_repo_name = '{base_name}/{repo_name}'.format(**match_dict)
194 vcs_repo_name = '{base_name}/.__shadow_{repo_name}_pr-{pr_id}'.format(
195 **match_dict)
196
197 log.debug('repo_names %s', {
181 log.debug('repo_names %s', {
198 'acl_repo_name': acl_repo_name,
182 'acl_repo_name': vcs_handler.acl_repo_name,
199 'vcs_repo_name': vcs_repo_name,
183 'vcs_repo_name': vcs_handler.vcs_repo_name,
200 'url_repo_name': url_repo_name,
184 'url_repo_name': vcs_handler.url_repo_name,
201 })
185 })
202 log.debug('pull_request %s', pr_id)
186 log.debug('pull_request %s', vcs_handler.pr_id)
203
187
204 # check for type, presence in database and on filesystem
188 # check for type, presence in database and on filesystem
205 if not vcs_handler.is_valid_and_existing_repo(
189 if not vcs_handler.is_valid_and_existing_repo(
206 acl_repo_name, vcs_handler.basepath, vcs_handler.SCM):
190 vcs_handler.acl_repo_name,
191 vcs_handler.basepath,
192 vcs_handler.SCM):
207 return HTTPNotFound()(environ, start_response)
193 return HTTPNotFound()(environ, start_response)
208
194
209 # TODO: johbo: Needed for the Pyro4 backend and Mercurial only.
195 # TODO: johbo: Needed for the Pyro4 backend and Mercurial only.
210 # Remove once we fully switched to the HTTP backend.
196 # Remove once we fully switched to the HTTP backend.
211 environ['REPO_NAME'] = url_repo_name
197 environ['REPO_NAME'] = vcs_handler.url_repo_name
212
198
213 # register repo_name and it's config back to the handler
199 # register repo config back to the handler
214 vcs_handler.acl_repo_name = acl_repo_name
200 vcs_handler.repo_vcs_config = self.vcs_config(
215 vcs_handler.url_repo_name = url_repo_name
201 vcs_handler.acl_repo_name)
216 vcs_handler.vcs_repo_name = vcs_repo_name
217 vcs_handler.pr_id = pr_id
218 vcs_handler.repo_vcs_config = self.vcs_config(acl_repo_name)
219
202
203 # Wrap handler in middlewares if they are enabled.
220 vcs_handler = self.wrap_in_gzip_if_enabled(
204 vcs_handler = self.wrap_in_gzip_if_enabled(
221 vcs_handler, self.config)
205 vcs_handler, self.config)
222 vcs_handler, _ = wrap_in_appenlight_if_enabled(
206 vcs_handler, _ = wrap_in_appenlight_if_enabled(
223 vcs_handler, self.config, self.appenlight_client)
207 vcs_handler, self.config, self.appenlight_client)
208
224 return vcs_handler(environ, start_response)
209 return vcs_handler(environ, start_response)
225
210
226 return self.application(environ, start_response)
211 return self.application(environ, start_response)
General Comments 0
You need to be logged in to leave comments. Login now