Show More
@@ -1,93 +1,91 b'' | |||||
1 | # RhodeCode VCSServer provides access to different vcs backends via network. |
|
1 | # RhodeCode VCSServer provides access to different vcs backends via network. | |
2 | # Copyright (C) 2014-2018 RhodeCode GmbH |
|
2 | # Copyright (C) 2014-2018 RhodeCode GmbH | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or modify |
|
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by |
|
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 3 of the License, or |
|
6 | # the Free Software Foundation; either version 3 of the License, or | |
7 | # (at your option) any later version. |
|
7 | # (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software Foundation, |
|
15 | # along with this program; if not, write to the Free Software Foundation, | |
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 |
|
17 | |||
18 | import sys |
|
18 | import sys | |
19 | import traceback |
|
19 | import traceback | |
20 | import logging |
|
20 | import logging | |
21 | import urlparse |
|
21 | import urlparse | |
22 |
|
22 | |||
23 | from vcsserver.lib.rc_cache import region_meta |
|
23 | from vcsserver.lib.rc_cache import region_meta | |
24 | log = logging.getLogger(__name__) |
|
24 | log = logging.getLogger(__name__) | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | class RepoFactory(object): |
|
27 | class RepoFactory(object): | |
28 | """ |
|
28 | """ | |
29 | Utility to create instances of repository |
|
29 | Utility to create instances of repository | |
30 |
|
30 | |||
31 | It provides internal caching of the `repo` object based on |
|
31 | It provides internal caching of the `repo` object based on | |
32 | the :term:`call context`. |
|
32 | the :term:`call context`. | |
33 | """ |
|
33 | """ | |
34 | repo_type = None |
|
34 | repo_type = None | |
35 |
|
35 | |||
36 | def __init__(self): |
|
36 | def __init__(self): | |
37 | self._cache_region = region_meta.dogpile_cache_regions['repo_object'] |
|
37 | self._cache_region = region_meta.dogpile_cache_regions['repo_object'] | |
38 |
|
38 | |||
39 | def _create_config(self, path, config): |
|
39 | def _create_config(self, path, config): | |
40 | config = {} |
|
40 | config = {} | |
41 | return config |
|
41 | return config | |
42 |
|
42 | |||
43 | def _create_repo(self, wire, create): |
|
43 | def _create_repo(self, wire, create): | |
44 | raise NotImplementedError() |
|
44 | raise NotImplementedError() | |
45 |
|
45 | |||
46 | def repo(self, wire, create=False): |
|
46 | def repo(self, wire, create=False): | |
47 | """ |
|
47 | """ | |
48 | Get a repository instance for the given path. |
|
48 | Get a repository instance for the given path. | |
49 |
|
49 | |||
50 | Uses internally the low level beaker API since the decorators introduce |
|
50 | Uses internally the low level beaker API since the decorators introduce | |
51 | significant overhead. |
|
51 | significant overhead. | |
52 | """ |
|
52 | """ | |
53 | region = self._cache_region |
|
53 | region = self._cache_region | |
54 | context = wire.get('context', None) |
|
54 | context = wire.get('context', None) | |
55 | repo_path = wire.get('path', '') |
|
55 | repo_path = wire.get('path', '') | |
56 | context_uid = '{}'.format(context) |
|
56 | context_uid = '{}'.format(context) | |
57 | cache = wire.get('cache', True) |
|
57 | cache = wire.get('cache', True) | |
58 | cache_on = context and cache |
|
58 | cache_on = context and cache | |
59 |
|
59 | |||
60 | @region.conditional_cache_on_arguments(condition=cache_on) |
|
60 | @region.conditional_cache_on_arguments(condition=cache_on) | |
61 | def create_new_repo(_repo_type, _repo_path, _context_uid): |
|
61 | def create_new_repo(_repo_type, _repo_path, _context_uid): | |
62 | return self._create_repo(wire, create) |
|
62 | return self._create_repo(wire, create) | |
63 |
|
63 | |||
64 | repo = create_new_repo(self.repo_type, repo_path, context_uid) |
|
64 | repo = create_new_repo(self.repo_type, repo_path, context_uid) | |
65 | return repo |
|
65 | return repo | |
66 |
|
66 | |||
67 |
|
67 | |||
68 | def obfuscate_qs(query_string): |
|
68 | def obfuscate_qs(query_string): | |
69 | if query_string is None: |
|
69 | if query_string is None: | |
70 | return None |
|
70 | return None | |
71 |
|
71 | |||
72 | parsed = [] |
|
72 | parsed = [] | |
73 | for k, v in urlparse.parse_qsl(query_string, keep_blank_values=True): |
|
73 | for k, v in urlparse.parse_qsl(query_string, keep_blank_values=True): | |
74 | if k in ['auth_token', 'api_key']: |
|
74 | if k in ['auth_token', 'api_key']: | |
75 | v = "*****" |
|
75 | v = "*****" | |
76 | parsed.append((k, v)) |
|
76 | parsed.append((k, v)) | |
77 |
|
77 | |||
78 | return '&'.join('{}{}'.format( |
|
78 | return '&'.join('{}{}'.format( | |
79 | k, '={}'.format(v) if v else '') for k, v in parsed) |
|
79 | k, '={}'.format(v) if v else '') for k, v in parsed) | |
80 |
|
80 | |||
81 |
|
81 | |||
82 | def raise_from_original(new_type): |
|
82 | def raise_from_original(new_type): | |
83 | """ |
|
83 | """ | |
84 | Raise a new exception type with original args and traceback. |
|
84 | Raise a new exception type with original args and traceback. | |
85 | """ |
|
85 | """ | |
86 | exc_type, exc_value, exc_traceback = sys.exc_info() |
|
86 | exc_type, exc_value, exc_traceback = sys.exc_info() | |
87 |
|
87 | |||
88 | traceback.format_exception(exc_type, exc_value, exc_traceback) |
|
|||
89 |
|
||||
90 | try: |
|
88 | try: | |
91 | raise new_type(*exc_value.args), None, exc_traceback |
|
89 | raise new_type(*exc_value.args), None, exc_traceback | |
92 | finally: |
|
90 | finally: | |
93 | del exc_traceback |
|
91 | del exc_traceback |
General Comments 0
You need to be logged in to leave comments.
Login now