summaryrefslogtreecommitdiff
path: root/gitlab/v4/objects
diff options
context:
space:
mode:
authorAbhishek Singh <abhiandthetruth@gmail.com>2022-11-02 13:59:06 +0530
committerGitHub <noreply@github.com>2022-11-02 09:29:06 +0100
commit892281e35e3d81c9e43ff6a974f920daa83ea8b2 (patch)
tree773a66ebeec30e993a2c81852de12a3ad4deac12 /gitlab/v4/objects
parente5dc72de9b3cdf0a7944ee0961fbdc6784c7f315 (diff)
downloadgitlab-892281e35e3d81c9e43ff6a974f920daa83ea8b2.tar.gz
feat(api): add support for remote project import from AWS S3 (#2357)
Diffstat (limited to 'gitlab/v4/objects')
-rw-r--r--gitlab/v4/objects/projects.py66
1 files changed, 64 insertions, 2 deletions
diff --git a/gitlab/v4/objects/projects.py b/gitlab/v4/objects/projects.py
index 446e4f5..65be581 100644
--- a/gitlab/v4/objects/projects.py
+++ b/gitlab/v4/objects/projects.py
@@ -807,6 +807,7 @@ class ProjectManager(CRUDMixin, RESTManager):
def get(self, id: Union[str, int], lazy: bool = False, **kwargs: Any) -> Project:
return cast(Project, super().get(id=id, lazy=lazy, **kwargs))
+ @exc.on_http_error(exc.GitlabImportError)
def import_project(
self,
file: str,
@@ -833,7 +834,7 @@ class ProjectManager(CRUDMixin, RESTManager):
Raises:
GitlabAuthenticationError: If authentication is not correct
- GitlabListError: If the server failed to perform the request
+ GitlabImportError: If the server failed to perform the request
Returns:
A representation of the import status.
@@ -851,6 +852,7 @@ class ProjectManager(CRUDMixin, RESTManager):
"/projects/import", post_data=data, files=files, **kwargs
)
+ @exc.on_http_error(exc.GitlabImportError)
def remote_import(
self,
url: str,
@@ -877,7 +879,7 @@ class ProjectManager(CRUDMixin, RESTManager):
Raises:
GitlabAuthenticationError: If authentication is not correct
- GitlabListError: If the server failed to perform the request
+ GitlabImportError: If the server failed to perform the request
Returns:
A representation of the import status.
@@ -894,6 +896,66 @@ class ProjectManager(CRUDMixin, RESTManager):
"/projects/remote-import", post_data=data, **kwargs
)
+ @exc.on_http_error(exc.GitlabImportError)
+ def remote_import_s3(
+ self,
+ path: str,
+ region: str,
+ bucket_name: str,
+ file_key: str,
+ access_key_id: str,
+ secret_access_key: str,
+ name: Optional[str] = None,
+ namespace: Optional[str] = None,
+ overwrite: bool = False,
+ override_params: Optional[Dict[str, Any]] = None,
+ **kwargs: Any,
+ ) -> Union[Dict[str, Any], requests.Response]:
+ """Import a project from an archive file stored on AWS S3.
+
+ Args:
+ region: AWS S3 region name where the file is stored
+ bucket_name: AWS S3 bucket name where the file is stored
+ file_key: AWS S3 file key to identify the file.
+ access_key_id: AWS S3 access key ID.
+ secret_access_key: AWS S3 secret access key.
+ path: Name and path for the new project
+ name: The name of the project to import. If not provided,
+ defaults to the path of the project.
+ namespace: The ID or path of the namespace that the project
+ will be imported to
+ overwrite: If True overwrite an existing project with the
+ same path
+ override_params: Set the specific settings for the project
+ **kwargs: Extra options to send to the server (e.g. sudo)
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabImportError: If the server failed to perform the request
+
+ Returns:
+ A representation of the import status.
+ """
+ data = {
+ "region": region,
+ "bucket_name": bucket_name,
+ "file_key": file_key,
+ "access_key_id": access_key_id,
+ "secret_access_key": secret_access_key,
+ "path": path,
+ "overwrite": str(overwrite),
+ }
+ if override_params:
+ for k, v in override_params.items():
+ data[f"override_params[{k}]"] = v
+ if name is not None:
+ data["name"] = name
+ if namespace:
+ data["namespace"] = namespace
+ return self.gitlab.http_post(
+ "/projects/remote-import-s3", post_data=data, **kwargs
+ )
+
def import_bitbucket_server(
self,
bitbucket_server_url: str,