def render(self, session, logger, dbuser, sandbox, start, get, comments, **arguments): if not dbuser: raise AuthorizationException("Cannot create a sandbox without an " "authenticated connection.") sandbox = self.force_my_sandbox(session, logger, dbuser, sandbox) # See `git check-ref-format --help` for naming restrictions. # We want to layer a few extra restrictions on top of that... validate_template_name("--sandbox", sandbox) Branch.get_unique(session, sandbox, preclude=True) # Check that the user has cleared up a directory of the same # name; if this is not the case the branch may be created (in git) # and added to the database - however CommandGet will fail roleing # back the database leaving the branch created in git templatesdir = self.config.get("broker", "templatesdir") sandboxdir = os.path.join(templatesdir, dbuser.name, sandbox) if os.path.exists(sandboxdir): raise ArgumentError("Sandbox directory %s already exists; " "cannot create branch." % sandboxdir) if not start: start = self.config.get("broker", "default_domain_start") dbstart = Branch.get_unique(session, start, compel=True) kingdir = self.config.get("broker", "kingdir") base_commit = run_git(["show-ref", "--hash", "refs/heads/" + dbstart.name], logger=logger, path=kingdir) compiler = self.config.get("panc", "pan_compiler") dbsandbox = Sandbox(name=sandbox, owner=dbuser, compiler=compiler, base_commit=base_commit, comments=comments) session.add(dbsandbox) session.flush() # Currently this will fail if the branch already exists... # That seems like the right behavior. It's an internal # consistency issue that would need to be addressed explicitly. run_git(["branch", sandbox, dbstart.name], logger=logger, path=kingdir) # If we arrive there the above "git branch" command has succeeded; # therefore we should comit the changes to the database. If this is # not done, and CommandGet fails (see dir check above), then the # git branch will be created but the database changes roled back. session.commit() if get == False: # The client knows to interpret an empty response as no action. return [] return CommandGet.render(self, session=session, logger=logger, dbuser=dbuser, sandbox=sandbox)
def render(self, session, logger, dbuser, sandbox, start, get, comments, **arguments): if not dbuser: raise AuthorizationException("Cannot create a sandbox without an " "authenticated connection.") sandbox = self.force_my_sandbox(session, logger, dbuser, sandbox) # See `git check-ref-format --help` for naming restrictions. # We want to layer a few extra restrictions on top of that... valid = re.compile('^[a-zA-Z0-9_.-]+$') if (not valid.match(sandbox)): raise ArgumentError("sandbox name '%s' is not valid" % sandbox) Branch.get_unique(session, sandbox, preclude=True) if not start: start = self.config.get("broker", "default_domain_start") dbstart = Branch.get_unique(session, start, compel=True) kingdir = self.config.get("broker", "kingdir") base_commit = run_git(["show-ref", "--hash", "refs/heads/" + dbstart.name], logger=logger, path=kingdir) compiler = self.config.get("panc", "pan_compiler") dbsandbox = Sandbox(name=sandbox, owner=dbuser, compiler=compiler, base_commit=base_commit, comments=comments) session.add(dbsandbox) session.flush() # Currently this will fail if the branch already exists... # That seems like the right behavior. It's an internal # consistency issue that would need to be addressed explicitly. run_git(["branch", sandbox, dbstart.name], logger=logger, path=kingdir) if get == False: # The client knows to interpret an empty response as no action. return [] return CommandGet.render(self, session=session, logger=logger, dbuser=dbuser, sandbox=sandbox)