MCPcopy Create free account
hub / github.com/dvdotsenko/git_http_backend.py / basic_checks

Method basic_checks

git_http_backend.py:400–473  ·  view source on GitHub ↗

This function is shared by GitInfoRefs and SmartHTTPRPCHandler WSGI classes. It does the same basic steps - figure out working path, git command etc. dataObj - dictionary Because the dataObj passed in is mutable, it's a pointer. Once this function returns,

(self, dataObj, environ, start_response)

Source from the content-addressed store, hash-verified

398 return o or stdout, e or stderr, _p.returncode
399
400 def basic_checks(self, dataObj, environ, start_response):
401 '''
402 This function is shared by GitInfoRefs and SmartHTTPRPCHandler WSGI classes.
403 It does the same basic steps - figure out working path, git command etc.
404
405 dataObj - dictionary
406 Because the dataObj passed in is mutable, it's a pointer. Once this function returns,
407 this object, as created by calling class, will have the free-form updated data.
408
409 Returns non-None object if an error was triggered (and already prepared in start_response).
410 '''
411 selector_matches = (environ.get('wsgiorg.routing_args') or ([],{}))[1]
412
413 # making sure we have a compatible git command
414 git_command = selector_matches.get('git_command') or ''
415 if git_command not in ['git-upload-pack', 'git-receive-pack']: # TODO: this is bad for future compatibility. There may be more commands supported then.
416 return self.canned_handlers(environ, start_response, 'bad_request')
417
418 # TODO: Add "public" to "dynamic local" path conversion hook ups here.
419
420 #############################################################
421 # making sure local path is a valid git repo folder
422 #
423 repo_path = os.path.abspath(
424 os.path.join(
425 self.path_prefix,
426 (selector_matches.get('working_path') or '').decode('utf8').strip('/').strip('\\')
427 )
428 )
429 _pp = os.path.abspath(self.path_prefix)
430
431 # this saves us from "hackers" putting relative paths after repo marker.
432 if not repo_path.startswith(_pp):
433 return self.canned_handlers(environ, start_response, 'forbidden')
434
435 if not self.has_access(
436 environ = environ,
437 repo_path = repo_path,
438 git_command = git_command
439 ):
440 return self.canned_handlers(environ, start_response, 'forbidden')
441
442 try:
443 files = os.listdir(repo_path)
444 except:
445 files = []
446 if not self.git_folder_signature.issubset([i.lower() for i in files]):
447 if not ( self.repo_auto_create and git_command == 'git-receive-pack' ):
448 return self.canned_handlers(environ, start_response, 'not_found')
449 else:
450 # 1. traverse entire post-prefix path and check that each segment
451 # If it is ( a git folder OR a non-dir object ) forbid autocreate
452 # 2. Create folderS
453 # 3. Activate a bare git repo
454 _pf = _pp
455 _dirs = repo_path[len(_pp):].strip(os.sep).split(os.sep) or ['']
456 for _dir in _dirs:
457 _pf = os.path.join(_pf,_dir)

Callers 2

__call__Method · 0.80
__call__Method · 0.80

Calls 2

has_accessMethod · 0.95
canned_handlersMethod · 0.80

Tested by

no test coverage detected