Skip to content

Commit

Permalink
add functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarek-Rolski committed Jan 19, 2024
1 parent bd32487 commit 63b5188
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions sdk/rapid/rapid.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def create_user(self, user_name: str, user_email: str, user_permissions: list[st
"One or more of the provided permissions is invalid or duplicated"
)

def delete_user(self, user_name: str, user_id: str) -> None:
def delete_user(self, user_name: str, user_id: str):
"""
Deletes a client from the API based on their id
Expand All @@ -465,9 +465,78 @@ def delete_user(self, user_name: str, user_id: str) -> None:
),
timeout=TIMEOUT_PERIOD,
)
data = json.loads(response.content.decode("utf-8"))
if response.status_code == 200:
return None
return data

raise SubjectNotFoundException(
f"Failed to delete user with id: {user_id}, ensure it exists."
)

def list_subjects(self):
"""
List all current subjects within rAPId instance.
Returns:
A JSON response of the API's response.
"""
response = requests.get(
f"{self.auth.url}/subjects",
headers=self.generate_headers(),
timeout=TIMEOUT_PERIOD,
)
return json.loads(response.content.decode("utf-8"))

def list_layers(self):
"""
List all current layers within rAPId instance.
Returns:
A JSON response of the API's response.
"""
response = requests.get(
f"{self.auth.url}/layers",
headers=self.generate_headers(),
timeout=TIMEOUT_PERIOD,
)
return json.loads(response.content.decode("utf-8"))

def list_protected_domains(self):
"""
List all current protected domains within rAPId instance.
Returns:
A JSON response of the API's response.
"""
response = requests.get(
f"{self.auth.url}/protected_domains",
headers=self.generate_headers(),
timeout=TIMEOUT_PERIOD,
)
return json.loads(response.content.decode("utf-8"))

def delete_dataset(self, layer: str, domain: str, dataset: str):
"""
Deletes a dataset from the API based on their id
Args:
layer (str): The dataset layer to delete.
domain (str): The dataset domain to delete.
dataset (str): The dataset to delete.
Raises:
rapid.exceptions.DatasetNotFoundException: If the dataset does not exist.
"""
url = f"{self.auth.url}/datasets/{layer}/{domain}/{dataset}"
response = requests.delete(
url,
headers=self.generate_headers(),
timeout=TIMEOUT_PERIOD,
)
data = json.loads(response.content.decode("utf-8"))
if response.status_code == 200:
return data

raise DatasetNotFoundException(
f"Could not find dataset, {layer}/{domain}/{dataset} to delete", data
)

0 comments on commit 63b5188

Please sign in to comment.