Added creation of SVN repos
authorSybren A. Stüvel <sybren@stuvel.eu>
Fri, 3 Nov 2017 13:35:50 +0000 (14:35 +0100)
committerSybren A. Stüvel <sybren@stuvel.eu>
Fri, 3 Nov 2017 13:37:35 +0000 (14:37 +0100)
svnman/cli.py
svnman/remote.py

index 2d7726e..da99f48 100644 (file)
@@ -25,6 +25,25 @@ def info(repo_id):
     log.info('Access : %s', sorted(repoinfo.access))
 
 
+@manager_svnman.command
+def create(repo_id, project_url, creator):
+    """Creates a new Subversion repository."""
+
+    from pillar.api.projects.utils import project_id
+    from . import current_svnman
+    from .remote import CreateRepo
+
+    pid = project_id(project_url)
+    creation_info = CreateRepo(
+        repo_id=repo_id,
+        project_id=str(pid),
+        creator=creator,
+    )
+
+    log.info('Creating repository %r', repo_id)
+    current_svnman.remote.create_repo(creation_info)
+
+
 @manager_svnman.command
 def grant(repo_id, username, password):
     """Allows the user access to the repository."""
index c0caa77..aeb66dd 100644 (file)
@@ -14,6 +14,13 @@ class RepoDescription:
     access: typing.List[str] = attrs_extra.string()
 
 
+@attr.s
+class CreateRepo:
+    repo_id: str = attrs_extra.string()
+    project_id: str = attrs_extra.string()
+    creator: str = attrs_extra.string()
+
+
 @attr.s
 class API:
     # The remote URL and credentials are separate. This way we can log the
@@ -64,6 +71,18 @@ class API:
 
         return RepoDescription(**resp.json())
 
+    def create_repo(self, create_repo: CreateRepo):
+        """Creates a new repository with the given ID.
+
+        :param create_repo: info required by the API
+        :raises svnman.exceptions.RepoAlreadyExists:
+        """
+
+        resp = self._request('POST', f'repo', json=attr.asdict(create_repo))
+        if resp.status_code == requests.codes.conflict:
+            raise exceptions.RepoAlreadyExists(create_repo.repo_id)
+        self._raise_for_status(resp)
+
     def modify_access(self,
                       repo_id: str,
                       grant: typing.List[typing.Tuple[str, str]],