Show More
@@ -1,87 +1,88 b'' | |||||
1 | # Copyright (C) 2016-2023 RhodeCode GmbH |
|
1 | # Copyright (C) 2016-2023 RhodeCode GmbH | |
2 | # |
|
2 | # | |
3 | # This program is free software: you can redistribute it and/or modify |
|
3 | # This program is free software: you can redistribute it and/or modify | |
4 | # it under the terms of the GNU Affero General Public License, version 3 |
|
4 | # it under the terms of the GNU Affero General Public License, version 3 | |
5 | # (only), as published by the Free Software Foundation. |
|
5 | # (only), as published by the Free Software Foundation. | |
6 | # |
|
6 | # | |
7 | # This program is distributed in the hope that it will be useful, |
|
7 | # This program is distributed in the hope that it will be useful, | |
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10 | # GNU General Public License for more details. |
|
10 | # GNU General Public License for more details. | |
11 | # |
|
11 | # | |
12 | # You should have received a copy of the GNU Affero General Public License |
|
12 | # You should have received a copy of the GNU Affero General Public License | |
13 | # 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 | # |
|
14 | # | |
15 | # This program is dual-licensed. If you wish to learn more about the |
|
15 | # This program is dual-licensed. If you wish to learn more about the | |
16 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
16 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
18 |
|
18 | |||
19 | import sys |
|
19 | import sys | |
20 | import logging |
|
20 | import logging | |
21 | import subprocess |
|
21 | import subprocess | |
22 |
|
22 | |||
23 | from vcsserver import hooks |
|
23 | from vcsserver import hooks | |
24 | from .base import VcsServer |
|
24 | from .base import VcsServer | |
25 |
|
25 | |||
26 | log = logging.getLogger(__name__) |
|
26 | log = logging.getLogger(__name__) | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | class GitTunnelWrapper(object): |
|
29 | class GitTunnelWrapper(object): | |
30 | process = None |
|
30 | process = None | |
31 |
|
31 | |||
32 | def __init__(self, server): |
|
32 | def __init__(self, server): | |
33 | self.server = server |
|
33 | self.server = server | |
34 | self.stdin = sys.stdin |
|
34 | self.stdin = sys.stdin | |
35 | self.stdout = sys.stdout |
|
35 | self.stdout = sys.stdout | |
36 |
|
36 | |||
37 | def create_hooks_env(self): |
|
37 | def create_hooks_env(self): | |
38 | pass |
|
38 | pass | |
39 |
|
39 | |||
40 | def command(self): |
|
40 | def command(self): | |
41 | root = self.server.get_root_store() |
|
41 | root = self.server.get_root_store() | |
42 | command = "cd {root}; {git_path} {mode} '{root}{repo_name}'".format( |
|
42 | command = "cd {root}; {git_path} {mode} '{root}{repo_name}'".format( | |
43 | root=root, git_path=self.server.git_path, |
|
43 | root=root, git_path=self.server.git_path, | |
44 | mode=self.server.repo_mode, repo_name=self.server.repo_name) |
|
44 | mode=self.server.repo_mode, repo_name=self.server.repo_name) | |
45 | log.debug("Final CMD: %s", command) |
|
45 | log.debug("Final CMD: %s", command) | |
46 | return command |
|
46 | return command | |
47 |
|
47 | |||
48 | def run(self, extras): |
|
48 | def run(self, extras): | |
49 | action = "push" if self.server.repo_mode == "receive-pack" else "pull" |
|
49 | action = "push" if self.server.repo_mode == "receive-pack" else "pull" | |
50 | exit_code = self.server._check_permissions(action) |
|
50 | exit_code = self.server._check_permissions(action) | |
51 | if exit_code: |
|
51 | if exit_code: | |
52 | return exit_code |
|
52 | return exit_code | |
53 |
|
53 | |||
54 | scm_extras = self.server.update_environment(action=action, extras=extras) |
|
54 | scm_extras = self.server.update_environment(action=action, extras=extras) | |
55 |
|
55 | |||
56 | hook_response = hooks.git_pre_pull(scm_extras) |
|
56 | if action == "pull": | |
57 | pre_pull_messages = hook_response.output |
|
57 | hook_response = hooks.git_pre_pull(scm_extras) | |
58 | sys.stdout.write(pre_pull_messages) |
|
58 | pre_pull_messages = hook_response.output | |
|
59 | sys.stdout.write(pre_pull_messages) | |||
59 |
|
60 | |||
60 | self.create_hooks_env() |
|
61 | self.create_hooks_env() | |
61 | result = subprocess.run(self.command(), shell=True) |
|
62 | result = subprocess.run(self.command(), shell=True) | |
62 | result = result.returncode |
|
63 | result = result.returncode | |
63 |
|
64 | |||
64 | # Upload-pack == clone |
|
65 | # Upload-pack == clone | |
65 | if action == "pull": |
|
66 | if action == "pull": | |
66 | hook_response = hooks.git_post_pull(scm_extras) |
|
67 | hook_response = hooks.git_post_pull(scm_extras) | |
67 | post_pull_messages = hook_response.output |
|
68 | post_pull_messages = hook_response.output | |
68 | sys.stderr.write(post_pull_messages) |
|
69 | sys.stderr.write(post_pull_messages) | |
69 | return result |
|
70 | return result | |
70 |
|
71 | |||
71 |
|
72 | |||
72 | class GitServer(VcsServer): |
|
73 | class GitServer(VcsServer): | |
73 | backend = 'git' |
|
74 | backend = 'git' | |
74 | repo_user_agent = 'git' |
|
75 | repo_user_agent = 'git' | |
75 |
|
76 | |||
76 | def __init__(self, store, ini_path, repo_name, repo_mode, |
|
77 | def __init__(self, store, ini_path, repo_name, repo_mode, | |
77 | user, user_permissions, config, env): |
|
78 | user, user_permissions, config, env): | |
78 | super().\ |
|
79 | super().\ | |
79 | __init__(user, user_permissions, config, env) |
|
80 | __init__(user, user_permissions, config, env) | |
80 |
|
81 | |||
81 | self.store = store |
|
82 | self.store = store | |
82 | self.ini_path = ini_path |
|
83 | self.ini_path = ini_path | |
83 | self.repo_name = repo_name |
|
84 | self.repo_name = repo_name | |
84 | self._path = self.git_path = config.get('app:main', 'ssh.executable.git') |
|
85 | self._path = self.git_path = config.get('app:main', 'ssh.executable.git') | |
85 |
|
86 | |||
86 | self.repo_mode = repo_mode |
|
87 | self.repo_mode = repo_mode | |
87 | self.tunnel = GitTunnelWrapper(server=self) |
|
88 | self.tunnel = GitTunnelWrapper(server=self) |
General Comments 0
You need to be logged in to leave comments.
Login now