##// END OF EJS Templates
refactor(ssh-wrapper): changed SSHVcsServer to SshVcsServer, updated call_service_api method.
ilin.s -
r5326:cede61e3 default
parent child Browse files
Show More
@@ -24,7 +24,6 b' from sqlalchemy import Table'
24
24
25 from rhodecode.lib.api_utils import call_service_api
25 from rhodecode.lib.api_utils import call_service_api
26 from rhodecode.lib.utils2 import AttributeDict
26 from rhodecode.lib.utils2 import AttributeDict
27 from rhodecode.lib.vcs.exceptions import ImproperlyConfiguredError
28
27
29 from .hg import MercurialServer
28 from .hg import MercurialServer
30 from .git import GitServer
29 from .git import GitServer
@@ -265,35 +264,6 b' class SshWrapperStandalone(SshWrapper):'
265 New version of SshWrapper designed to be depended only on service API
264 New version of SshWrapper designed to be depended only on service API
266 """
265 """
267 repos_path = None
266 repos_path = None
268 service_api_host: str
269 service_api_token: str
270 api_url: str
271
272 def __init__(self, command, connection_info, mode,
273 user, user_id, key_id: int, shell, ini_path: str, settings, env):
274
275 # validate our settings for making a standalone calls
276 try:
277 self.service_api_host = settings['app.service_api.host']
278 self.service_api_token = settings['app.service_api.token']
279 except KeyError:
280 raise ImproperlyConfiguredError(
281 "app.service_api.host or app.service_api.token are missing. "
282 "Please ensure that app.service_api.host and app.service_api.token are "
283 "defined inside of .ini configuration file."
284 )
285
286 try:
287 self.api_url = settings['rhodecode.api.url']
288 except KeyError:
289 raise ImproperlyConfiguredError(
290 "rhodecode.api.url is missing. "
291 "Please ensure that rhodecode.api.url is "
292 "defined inside of .ini configuration file."
293 )
294
295 super(SshWrapperStandalone, self).__init__(
296 command, connection_info, mode, user, user_id, key_id, shell, ini_path, settings, env)
297
267
298 @staticmethod
268 @staticmethod
299 def parse_user_related_data(user_data):
269 def parse_user_related_data(user_data):
@@ -326,7 +296,7 b' class SshWrapperStandalone(SshWrapper):'
326 exit_code = 1
296 exit_code = 1
327
297
328 elif scm_detected:
298 elif scm_detected:
329 data = call_service_api(self.service_api_host, self.service_api_token, self.api_url, {
299 data = call_service_api(self.settings, {
330 "method": "service_get_data_for_ssh_wrapper",
300 "method": "service_get_data_for_ssh_wrapper",
331 "args": {"user_id": user_id, "repo_name": scm_repo, "key_id": self.key_id}
301 "args": {"user_id": user_id, "repo_name": scm_repo, "key_id": self.key_id}
332 })
302 })
@@ -364,7 +334,7 b' class SshWrapperStandalone(SshWrapper):'
364 if repo_name.startswith('_'):
334 if repo_name.startswith('_'):
365 org_repo_name = repo_name
335 org_repo_name = repo_name
366 log.debug('translating UID repo %s', org_repo_name)
336 log.debug('translating UID repo %s', org_repo_name)
367 by_id_match = call_service_api(self.service_api_host, self.service_api_token, self.api_url, {
337 by_id_match = call_service_api(self.settings, {
368 'method': 'service_get_repo_name_by_id',
338 'method': 'service_get_repo_name_by_id',
369 "args": {"repo_id": repo_name}
339 "args": {"repo_id": repo_name}
370 })
340 })
@@ -28,7 +28,7 b' from rhodecode.lib.api_utils import call'
28 log = logging.getLogger(__name__)
28 log = logging.getLogger(__name__)
29
29
30
30
31 class SSHVcsServer(object):
31 class SshVcsServer(object):
32 repo_user_agent = None # set in child classes
32 repo_user_agent = None # set in child classes
33 _path = None # set executable path for hg/git/svn binary
33 _path = None # set executable path for hg/git/svn binary
34 backend = None # set in child classes
34 backend = None # set in child classes
@@ -62,11 +62,7 b' class SSHVcsServer(object):'
62 from rhodecode.model.scm import ScmModel
62 from rhodecode.model.scm import ScmModel
63 ScmModel().mark_for_invalidation(repo_name)
63 ScmModel().mark_for_invalidation(repo_name)
64 case 'celery':
64 case 'celery':
65 service_api_host = self.settings['app.service_api.host']
65 call_service_api(self.settings, {
66 service_api_token = self.settings['app.service_api.token']
67 api_url = self.settings['rhodecode.api.url']
68
69 call_service_api(service_api_host, service_api_token, api_url, {
70 "method": "service_mark_for_invalidation",
66 "method": "service_mark_for_invalidation",
71 "args": {"repo_name": repo_name}
67 "args": {"repo_name": repo_name}
72 })
68 })
@@ -21,7 +21,7 b' import logging'
21 import subprocess
21 import subprocess
22
22
23 from vcsserver import hooks
23 from vcsserver import hooks
24 from .base import SSHVcsServer
24 from .base import SshVcsServer
25
25
26 log = logging.getLogger(__name__)
26 log = logging.getLogger(__name__)
27
27
@@ -70,7 +70,7 b' class GitTunnelWrapper(object):'
70 return result
70 return result
71
71
72
72
73 class GitServer(SSHVcsServer):
73 class GitServer(SshVcsServer):
74 backend = 'git'
74 backend = 'git'
75 repo_user_agent = 'git'
75 repo_user_agent = 'git'
76
76
@@ -23,7 +23,7 b' import tempfile'
23 import textwrap
23 import textwrap
24 import collections
24 import collections
25
25
26 from .base import SSHVcsServer
26 from .base import SshVcsServer
27
27
28 from rhodecode.lib.api_utils import call_service_api
28 from rhodecode.lib.api_utils import call_service_api
29
29
@@ -94,7 +94,7 b' class MercurialTunnelWrapper(object):'
94 self.remove_configs()
94 self.remove_configs()
95
95
96
96
97 class MercurialServer(SSHVcsServer):
97 class MercurialServer(SshVcsServer):
98 backend = 'hg'
98 backend = 'hg'
99 repo_user_agent = 'mercurial'
99 repo_user_agent = 'mercurial'
100 cli_flags = ['phases', 'largefiles', 'extensions', 'experimental', 'hooks']
100 cli_flags = ['phases', 'largefiles', 'extensions', 'experimental', 'hooks']
@@ -111,10 +111,7 b' class MercurialServer(SSHVcsServer):'
111 def config_to_hgrc(self, repo_name):
111 def config_to_hgrc(self, repo_name):
112 # Todo: once transition is done only call to service api should exist
112 # Todo: once transition is done only call to service api should exist
113 if self.hooks_protocol == 'celery':
113 if self.hooks_protocol == 'celery':
114 service_api_host = self.settings['app.service_api.host']
114 data = call_service_api(self.settings, {
115 service_api_token = self.settings['app.service_api.token']
116 api_url = self.settings['rhodecode.api.url']
117 data = call_service_api(service_api_host, service_api_token, api_url, {
118 "method": "service_config_to_hgrc",
115 "method": "service_config_to_hgrc",
119 "args": {"cli_flags": self.cli_flags, "repo_name": repo_name}
116 "args": {"cli_flags": self.cli_flags, "repo_name": repo_name}
120 })
117 })
@@ -25,7 +25,7 b' import tempfile'
25 from subprocess import Popen, PIPE
25 from subprocess import Popen, PIPE
26 import urllib.parse
26 import urllib.parse
27
27
28 from .base import SSHVcsServer
28 from .base import SshVcsServer
29
29
30 log = logging.getLogger(__name__)
30 log = logging.getLogger(__name__)
31
31
@@ -218,7 +218,7 b' class SubversionTunnelWrapper(object):'
218 return self.return_code
218 return self.return_code
219
219
220
220
221 class SubversionServer(SSHVcsServer):
221 class SubversionServer(SshVcsServer):
222 backend = 'svn'
222 backend = 'svn'
223 repo_user_agent = 'svn'
223 repo_user_agent = 'svn'
224
224
@@ -20,16 +20,25 b' import urllib.parse'
20
20
21 from rhodecode.lib.vcs import CurlSession
21 from rhodecode.lib.vcs import CurlSession
22 from rhodecode.lib.ext_json import json
22 from rhodecode.lib.ext_json import json
23 from rhodecode.lib.vcs.exceptions import ImproperlyConfiguredError
23
24
24
25
25 def call_service_api(service_api_host, service_api_token, api_url, payload):
26 def call_service_api(settings, payload):
26
27 try:
28 api_host = settings['app.service_api.host']
29 api_token = settings['app.service_api.token']
30 api_url = settings['rhodecode.api.url']
31 except KeyError as exc:
32 raise ImproperlyConfiguredError(
33 f"{str(exc)} is missing. "
34 "Please ensure that app.service_api.host, app.service_api.token and rhodecode.api.url are "
35 "defined inside of .ini configuration file."
36 )
27 payload.update({
37 payload.update({
28 'id': 'service',
38 'id': 'service',
29 'auth_token': service_api_token
39 'auth_token': api_token
30 })
40 })
31
41 service_api_url = urllib.parse.urljoin(api_host, api_url)
32 service_api_url = urllib.parse.urljoin(service_api_host, api_url)
33 response = CurlSession().post(service_api_url, json.dumps(payload))
42 response = CurlSession().post(service_api_url, json.dumps(payload))
34
43
35 if response.status_code != 200:
44 if response.status_code != 200:
General Comments 0
You need to be logged in to leave comments. Login now