diff options
| author | John L. Villalovos <john@sodarock.com> | 2022-01-09 00:53:12 -0800 |
|---|---|---|
| committer | John L. Villalovos <john@sodarock.com> | 2022-01-09 00:53:12 -0800 |
| commit | 99e1f8bad3e52ca6fb2dc6b876a262c6fee39e41 (patch) | |
| tree | 6a11bdaf3e49a3dec844255d74a860798e8acc68 /gitlab/v4/objects/projects.py | |
| parent | ac812727c26c9bde4ee5c1115029f2ff4ab1964b (diff) | |
| download | gitlab-jlvillal/encoded_id_alt.tar.gz | |
fix: use url-encoded ID in all paths ALTERNATE METHODjlvillal/encoded_id_alt
An alternative to https://github.com/python-gitlab/python-gitlab/pull/1819
Make sure all usage of the ID in the URL path is encoded. Normally it
isn't an issue as most IDs are integers or strings which don't contain
a slash ('/'). But when the ID is a string with a slash character it
will break things.
Add a test case that shows this fixes wikis issue with subpages which
use the slash character.
Closes: #1079
Diffstat (limited to 'gitlab/v4/objects/projects.py')
| -rw-r--r-- | gitlab/v4/objects/projects.py | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/gitlab/v4/objects/projects.py b/gitlab/v4/objects/projects.py index 74671c8..58666ce 100644 --- a/gitlab/v4/objects/projects.py +++ b/gitlab/v4/objects/projects.py @@ -197,7 +197,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the relation could not be created """ - path = f"/projects/{self.get_id()}/fork/{forked_from_id}" + path = f"/projects/{self.encoded_id}/fork/{forked_from_id}" self.manager.gitlab.http_post(path, **kwargs) @cli.register_custom_action("Project") @@ -212,7 +212,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server failed to perform the request """ - path = f"/projects/{self.get_id()}/fork" + path = f"/projects/{self.encoded_id}/fork" self.manager.gitlab.http_delete(path, **kwargs) @cli.register_custom_action("Project") @@ -227,7 +227,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server failed to perform the request """ - path = f"/projects/{self.get_id()}/languages" + path = f"/projects/{self.encoded_id}/languages" return self.manager.gitlab.http_get(path, **kwargs) @cli.register_custom_action("Project") @@ -242,7 +242,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server failed to perform the request """ - path = f"/projects/{self.get_id()}/star" + path = f"/projects/{self.encoded_id}/star" server_data = self.manager.gitlab.http_post(path, **kwargs) if TYPE_CHECKING: assert isinstance(server_data, dict) @@ -260,7 +260,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server failed to perform the request """ - path = f"/projects/{self.get_id()}/unstar" + path = f"/projects/{self.encoded_id}/unstar" server_data = self.manager.gitlab.http_post(path, **kwargs) if TYPE_CHECKING: assert isinstance(server_data, dict) @@ -278,7 +278,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server failed to perform the request """ - path = f"/projects/{self.get_id()}/archive" + path = f"/projects/{self.encoded_id}/archive" server_data = self.manager.gitlab.http_post(path, **kwargs) if TYPE_CHECKING: assert isinstance(server_data, dict) @@ -296,7 +296,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server failed to perform the request """ - path = f"/projects/{self.get_id()}/unarchive" + path = f"/projects/{self.encoded_id}/unarchive" server_data = self.manager.gitlab.http_post(path, **kwargs) if TYPE_CHECKING: assert isinstance(server_data, dict) @@ -324,7 +324,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server failed to perform the request """ - path = f"/projects/{self.get_id()}/share" + path = f"/projects/{self.encoded_id}/share" data = { "group_id": group_id, "group_access": group_access, @@ -345,7 +345,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO GitlabAuthenticationError: If authentication is not correct GitlabDeleteError: If the server failed to perform the request """ - path = f"/projects/{self.get_id()}/share/{group_id}" + path = f"/projects/{self.encoded_id}/share/{group_id}" self.manager.gitlab.http_delete(path, **kwargs) # variables not supported in CLI @@ -373,7 +373,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO GitlabCreateError: If the server failed to perform the request """ variables = variables or {} - path = f"/projects/{self.get_id()}/trigger/pipeline" + path = f"/projects/{self.encoded_id}/trigger/pipeline" post_data = {"ref": ref, "token": token, "variables": variables} attrs = self.manager.gitlab.http_post(path, post_data=post_data, **kwargs) if TYPE_CHECKING: @@ -393,7 +393,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO GitlabHousekeepingError: If the server failed to perform the request """ - path = f"/projects/{self.get_id()}/housekeeping" + path = f"/projects/{self.encoded_id}/housekeeping" self.manager.gitlab.http_post(path, **kwargs) # see #56 - add file attachment features @@ -478,7 +478,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO Returns: The uncompressed tar archive of the repository """ - path = f"/projects/{self.get_id()}/snapshot" + path = f"/projects/{self.encoded_id}/snapshot" result = self.manager.gitlab.http_get( path, streamed=streamed, raw=True, **kwargs ) @@ -506,7 +506,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO A list of dicts describing the resources found. """ data = {"scope": scope, "search": search} - path = f"/projects/{self.get_id()}/search" + path = f"/projects/{self.encoded_id}/search" return self.manager.gitlab.http_list(path, query_data=data, **kwargs) @cli.register_custom_action("Project") @@ -521,7 +521,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server failed to perform the request """ - path = f"/projects/{self.get_id()}/mirror/pull" + path = f"/projects/{self.encoded_id}/mirror/pull" self.manager.gitlab.http_post(path, **kwargs) @cli.register_custom_action("Project", ("to_namespace",)) @@ -577,7 +577,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO Returns: The artifacts if `streamed` is False, None otherwise. """ - path = f"/projects/{self.get_id()}/jobs/artifacts/{ref_name}/download" + path = f"/projects/{self.encoded_id}/jobs/artifacts/{ref_name}/download" result = self.manager.gitlab.http_get( path, job=job, streamed=streamed, raw=True, **kwargs ) @@ -622,7 +622,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO """ path = ( - f"/projects/{self.get_id()}/jobs/artifacts/{ref_name}/raw/" + f"/projects/{self.encoded_id}/jobs/artifacts/{ref_name}/raw/" f"{artifact_path}?job={job}" ) result = self.manager.gitlab.http_get( |
