Show More
@@ -0,0 +1,34 b'' | |||
|
1 | # Copyright (C) 2016-2023 RhodeCode GmbH | |
|
2 | # | |
|
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 | |
|
5 | # (only), as published by the Free Software Foundation. | |
|
6 | # | |
|
7 | # This program is distributed in the hope that it will be useful, | |
|
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
10 | # GNU General Public License for more details. | |
|
11 | # | |
|
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/>. | |
|
14 | # | |
|
15 | # This program is dual-licensed. If you wish to learn more about the | |
|
16 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
|
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
|
18 | ||
|
19 | import logging | |
|
20 | from pyramid.paster import setup_logging | |
|
21 | ||
|
22 | ||
|
23 | def setup_custom_logging(ini_path, debug): | |
|
24 | if debug: | |
|
25 | # enabled rhodecode.ini controlled logging setup | |
|
26 | setup_logging(ini_path) | |
|
27 | else: | |
|
28 | # configure logging in a mode that doesn't print anything. | |
|
29 | # in case of regularly configured logging it gets printed out back | |
|
30 | # to the client doing an SSH command. | |
|
31 | logger = logging.getLogger('') | |
|
32 | null = logging.NullHandler() | |
|
33 | # add the handler to the root logger | |
|
34 | logger.handlers = [null] |
@@ -1,86 +1,72 b'' | |||
|
1 | 1 | # Copyright (C) 2016-2023 RhodeCode GmbH |
|
2 | 2 | # |
|
3 | 3 | # This program is free software: you can redistribute it and/or modify |
|
4 | 4 | # it under the terms of the GNU Affero General Public License, version 3 |
|
5 | 5 | # (only), as published by the Free Software Foundation. |
|
6 | 6 | # |
|
7 | 7 | # This program is distributed in the hope that it will be useful, |
|
8 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 | 10 | # GNU General Public License for more details. |
|
11 | 11 | # |
|
12 | 12 | # You should have received a copy of the GNU Affero General Public License |
|
13 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
14 | 14 | # |
|
15 | 15 | # This program is dual-licensed. If you wish to learn more about the |
|
16 | 16 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
17 | 17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
18 | 18 | |
|
19 | 19 | import os |
|
20 | 20 | import sys |
|
21 | 21 | import time |
|
22 | 22 | import logging |
|
23 | 23 | |
|
24 | 24 | import click |
|
25 | 25 | |
|
26 | from pyramid.paster import setup_logging | |
|
27 | ||
|
28 | 26 | from rhodecode.lib.pyramid_utils import bootstrap |
|
29 | 27 | from rhodecode.lib.statsd_client import StatsdClient |
|
30 | 28 | from .backends import SshWrapper |
|
29 | from .utils import setup_custom_logging | |
|
31 | 30 | |
|
32 | 31 | log = logging.getLogger(__name__) |
|
33 | 32 | |
|
34 | 33 | |
|
35 | def setup_custom_logging(ini_path, debug): | |
|
36 | if debug: | |
|
37 | # enabled rhodecode.ini controlled logging setup | |
|
38 | setup_logging(ini_path) | |
|
39 | else: | |
|
40 | # configure logging in a mode that doesn't print anything. | |
|
41 | # in case of regularly configured logging it gets printed out back | |
|
42 | # to the client doing an SSH command. | |
|
43 | logger = logging.getLogger('') | |
|
44 | null = logging.NullHandler() | |
|
45 | # add the handler to the root logger | |
|
46 | logger.handlers = [null] | |
|
47 | ||
|
48 | 34 | |
|
49 | 35 | @click.command() |
|
50 | 36 | @click.argument('ini_path', type=click.Path(exists=True)) |
|
51 | 37 | @click.option( |
|
52 | 38 | '--mode', '-m', required=False, default='auto', |
|
53 | 39 | type=click.Choice(['auto', 'vcs', 'git', 'hg', 'svn', 'test']), |
|
54 | 40 | help='mode of operation') |
|
55 | 41 | @click.option('--user', help='Username for which the command will be executed') |
|
56 | 42 | @click.option('--user-id', help='User ID for which the command will be executed') |
|
57 | 43 | @click.option('--key-id', help='ID of the key from the database') |
|
58 | 44 | @click.option('--shell', '-s', is_flag=True, help='Allow Shell') |
|
59 | 45 | @click.option('--debug', is_flag=True, help='Enabled detailed output logging') |
|
60 | 46 | def main(ini_path, mode, user, user_id, key_id, shell, debug): |
|
61 | 47 | setup_custom_logging(ini_path, debug) |
|
62 | 48 | |
|
63 | 49 | command = os.environ.get('SSH_ORIGINAL_COMMAND', '') |
|
64 | 50 | if not command and mode not in ['test']: |
|
65 | 51 | raise ValueError( |
|
66 | 52 | 'Unable to fetch SSH_ORIGINAL_COMMAND from environment.' |
|
67 | 53 | 'Please make sure this is set and available during execution ' |
|
68 | 54 | 'of this script.') |
|
69 | 55 | connection_info = os.environ.get('SSH_CONNECTION', '') |
|
70 | 56 | time_start = time.time() |
|
71 | 57 | with bootstrap(ini_path, env={'RC_CMD_SSH_WRAPPER': '1'}) as env: |
|
72 | 58 | statsd = StatsdClient.statsd |
|
73 | 59 | try: |
|
74 | 60 | ssh_wrapper = SshWrapper( |
|
75 | 61 | command, connection_info, mode, |
|
76 | 62 | user, user_id, key_id, shell, ini_path, env) |
|
77 | 63 | except Exception: |
|
78 | 64 | log.exception('Failed to execute SshWrapper') |
|
79 | 65 | sys.exit(-5) |
|
80 | 66 | return_code = ssh_wrapper.wrap() |
|
81 | 67 | operation_took = time.time() - time_start |
|
82 | 68 | if statsd: |
|
83 | 69 | operation_took_ms = round(1000.0 * operation_took) |
|
84 | 70 | statsd.timing("rhodecode_ssh_wrapper_timing.histogram", operation_took_ms, |
|
85 | 71 | use_decimals=False) |
|
86 | 72 | sys.exit(return_code) |
@@ -1,72 +1,70 b'' | |||
|
1 | 1 | # Copyright (C) 2016-2023 RhodeCode GmbH |
|
2 | 2 | # |
|
3 | 3 | # This program is free software: you can redistribute it and/or modify |
|
4 | 4 | # it under the terms of the GNU Affero General Public License, version 3 |
|
5 | 5 | # (only), as published by the Free Software Foundation. |
|
6 | 6 | # |
|
7 | 7 | # This program is distributed in the hope that it will be useful, |
|
8 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 | 10 | # GNU General Public License for more details. |
|
11 | 11 | # |
|
12 | 12 | # You should have received a copy of the GNU Affero General Public License |
|
13 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
14 | 14 | # |
|
15 | 15 | # This program is dual-licensed. If you wish to learn more about the |
|
16 | 16 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
17 | 17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
18 | 18 | |
|
19 | 19 | import os |
|
20 | 20 | import sys |
|
21 | 21 | import time |
|
22 | 22 | import logging |
|
23 | 23 | |
|
24 | 24 | import click |
|
25 | 25 | |
|
26 | from pyramid.paster import setup_logging | |
|
27 | ||
|
28 | 26 | from rhodecode.lib.statsd_client import StatsdClient |
|
29 | 27 | from .backends import SshWrapperStandalone |
|
30 |
from . |
|
|
28 | from .utils import setup_custom_logging | |
|
31 | 29 | |
|
32 | 30 | log = logging.getLogger(__name__) |
|
33 | 31 | |
|
34 | 32 | |
|
35 | 33 | @click.command() |
|
36 | 34 | @click.argument('ini_path', type=click.Path(exists=True)) |
|
37 | 35 | @click.option( |
|
38 | 36 | '--mode', '-m', required=False, default='auto', |
|
39 | 37 | type=click.Choice(['auto', 'vcs', 'git', 'hg', 'svn', 'test']), |
|
40 | 38 | help='mode of operation') |
|
41 | 39 | @click.option('--user', help='Username for which the command will be executed') |
|
42 | 40 | @click.option('--user-id', help='User ID for which the command will be executed') |
|
43 | 41 | @click.option('--key-id', help='ID of the key from the database') |
|
44 | 42 | @click.option('--shell', '-s', is_flag=True, help='Allow Shell') |
|
45 | 43 | @click.option('--debug', is_flag=True, help='Enabled detailed output logging') |
|
46 | 44 | def main(ini_path, mode, user, user_id, key_id, shell, debug): |
|
47 | 45 | setup_custom_logging(ini_path, debug) |
|
48 | 46 | |
|
49 | 47 | command = os.environ.get('SSH_ORIGINAL_COMMAND', '') |
|
50 | 48 | if not command and mode not in ['test']: |
|
51 | 49 | raise ValueError( |
|
52 | 50 | 'Unable to fetch SSH_ORIGINAL_COMMAND from environment.' |
|
53 | 51 | 'Please make sure this is set and available during execution ' |
|
54 | 52 | 'of this script.') |
|
55 | 53 | connection_info = os.environ.get('SSH_CONNECTION', '') |
|
56 | 54 | time_start = time.time() |
|
57 | 55 | env = {'RC_CMD_SSH_WRAPPER': '1'} |
|
58 | 56 | statsd = StatsdClient.statsd |
|
59 | 57 | try: |
|
60 | 58 | ssh_wrapper = SshWrapperStandalone( |
|
61 | 59 | command, connection_info, mode, |
|
62 | 60 | user, user_id, key_id, shell, ini_path, env) |
|
63 | 61 | except Exception: |
|
64 | 62 | log.exception('Failed to execute SshWrapper') |
|
65 | 63 | sys.exit(-5) |
|
66 | 64 | return_code = ssh_wrapper.wrap() |
|
67 | 65 | operation_took = time.time() - time_start |
|
68 | 66 | if statsd: |
|
69 | 67 | operation_took_ms = round(1000.0 * operation_took) |
|
70 | 68 | statsd.timing("rhodecode_ssh_wrapper_timing.histogram", operation_took_ms, |
|
71 | 69 | use_decimals=False) |
|
72 | 70 | sys.exit(return_code) |
General Comments 0
You need to be logged in to leave comments.
Login now