Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for "Move Workspace File" API Endpoint #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion sendsafely/SendSafely.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pgpy.constants import KeyFlags, HashAlgorithm, SymmetricKeyAlgorithm, CompressionAlgorithm, PubKeyAlgorithm
from sendsafely.Package import Package
from sendsafely.exceptions import GetPackagesException, GetUserInformationException, TrustedDeviceException, \
DeletePackageException, GetPackageInformationFailedException, GetKeycodeFailedException
DeletePackageException, GetPackageInformationFailedException, GetKeycodeFailedException, MoveFileException
from sendsafely.utilities import make_headers, _get_string_from_file


Expand Down Expand Up @@ -268,3 +268,19 @@ def get_sent_packages(self, row_index=0, page_size=100):
row_index += page_size
except Exception as e:
GetPackagesException(details=str(e))

def move_file(self, package_id, file_id, destination_directory_id):
"""
Moves the file with the specified id to the directory with the specified ID
"""
endpoint = "/package/" + package_id + "/directory/" + destination_directory_id + "/file/" + file_id
url = self.BASE_URL + endpoint
headers = make_headers(self.API_SECRET, self.API_KEY, endpoint)
try:
response = requests.post(url=url, headers=headers).json()
except Exception as e:
raise MoveFileException(details=e)

if response["response"] != "SUCCESS":
raise MoveFileException(details=response["message"])
return response
11 changes: 11 additions & 0 deletions sendsafely/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ def __init__(self, details=None):
display = self.message
super().__init__(display)

class MoveFileException(Exception):
"""Exception raised during file movement.
"""
def __init__(self, details=None):
self.message = "An error occurred during file movement."
self.details = details
display = self.details
if display is None:
display = self.message
super().__init__(display)


class FinalizePackageFailedException(Exception):
"""Exception raised while finalizing package.
Expand Down