Skip to content

Commit

Permalink
🔊 Replace Entra ID user with Entra user
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Craddock <[email protected]>
  • Loading branch information
jemrobinson and craddm authored May 9, 2024
1 parent e825812 commit f5ffc41
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
42 changes: 21 additions & 21 deletions data_safe_haven/external/api/graph_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def create_application(
delegated_scopes: Sequence[str] = [],
request_json: dict[str, Any] | None = None,
) -> dict[str, Any]:
"""Create an Entra ID application if it does not already exist
"""Create an Entra application if it does not already exist
Raises:
DataSafeHavenMicrosoftGraphError if the application could not be created
Expand Down Expand Up @@ -257,7 +257,7 @@ def create_application(
msg = "Maximum attempts to validate service principle permissions exceeded"
raise DataSafeHavenMicrosoftGraphError(msg)

# Return JSON representation of the Entra ID application
# Return JSON representation of the Entra application
return json_response
except Exception as exc:
msg = f"Could not create application '{application_name}'.\n{exc}"
Expand All @@ -266,7 +266,7 @@ def create_application(
def create_application_secret(
self, application_name: str, application_secret_name: str
) -> str:
"""Add a secret to an existing Entra ID application
"""Add a secret to an existing Entra application
Returns:
str: Contents of newly-created secret
Expand Down Expand Up @@ -312,19 +312,19 @@ def create_application_secret(
raise DataSafeHavenMicrosoftGraphError(msg) from exc

def create_group(self, group_name: str) -> None:
"""Create an Entra ID group if it does not already exist
"""Create an Entra group if it does not already exist
Raises:
DataSafeHavenMicrosoftGraphError if the group could not be created
"""
try:
if self.get_id_from_groupname(group_name):
self.logger.info(
f"Found existing Entra ID group '[green]{group_name}[/]'.",
f"Found existing Entra group '[green]{group_name}[/]'.",
)
return
self.logger.debug(
f"Creating Entra ID group '[green]{group_name}[/]'...",
f"Creating Entra group '[green]{group_name}[/]'...",
)
request_json = {
"description": group_name,
Expand All @@ -339,16 +339,16 @@ def create_group(self, group_name: str) -> None:
json=request_json,
).json()
self.logger.info(
f"Created Entra ID group '[green]{group_name}[/]'.",
f"Created Entra group '[green]{group_name}[/]'.",
)
except Exception as exc:
msg = f"Could not create Entra ID group '{group_name}'.\n{exc}"
msg = f"Could not create Entra group '{group_name}'.\n{exc}"
raise DataSafeHavenMicrosoftGraphError(msg) from exc

def ensure_application_service_principal(
self, application_name: str
) -> dict[str, Any]:
"""Create a service principal for an Entra ID application if it does not already exist
"""Create a service principal for an Entra application if it does not already exist
Raises:
DataSafeHavenMicrosoftGraphError if the service principal could not be created
Expand Down Expand Up @@ -470,7 +470,7 @@ def create_user(
email_address: str,
phone_number: str,
) -> None:
"""Create an Entra ID user if it does not already exist
"""Create an Entra user if it does not already exist
Raises:
DataSafeHavenMicrosoftGraphError if the user could not be created
Expand All @@ -482,12 +482,12 @@ def create_user(
user_id = self.get_id_from_username(username)
if user_id:
self.logger.debug(
f"Updating Entra ID user '[green]{username}[/]'...",
f"Updating Entra user '[green]{username}[/]'...",
)
final_verb = "Update"
else:
self.logger.debug(
f"Creating Entra ID user '[green]{username}[/]'...",
f"Creating Entra user '[green]{username}[/]'...",
)
final_verb = "Create"
# If they do not then create them
Expand Down Expand Up @@ -523,7 +523,7 @@ def create_user(
json={"accountEnabled": True},
)
self.logger.info(
f"{final_verb}d Entra ID user '[green]{username}[/]'.",
f"{final_verb}d Entra user '[green]{username}[/]'.",
)
except DataSafeHavenMicrosoftGraphError as exc:
msg = f"Could not {final_verb.lower()} user {username}.\n{exc}"
Expand Down Expand Up @@ -917,10 +917,10 @@ def read_application_permissions(
raise DataSafeHavenMicrosoftGraphError(msg) from exc

def read_domains(self) -> Sequence[dict[str, Any]]:
"""Get details of Entra ID domains
"""Get details of Entra domains
Returns:
JSON: A JSON list of Entra ID domains
JSON: A JSON list of Entra domains
Raises:
DataSafeHavenMicrosoftGraphError if domains could not be loaded
Expand All @@ -936,7 +936,7 @@ def read_groups(
self,
attributes: Sequence[str] | None = None,
) -> Sequence[dict[str, Any]]:
"""Get details of Entra ID groups
"""Get details of Entra groups
Returns:
JSON: A JSON list of Entra ID groups
Expand Down Expand Up @@ -969,10 +969,10 @@ def read_service_principals(self) -> Sequence[dict[str, Any]]:
def read_users(
self, attributes: Sequence[str] | None = None
) -> Sequence[dict[str, Any]]:
"""Get details of Entra ID users
"""Get details of Entra users
Returns:
JSON: A JSON list of Entra ID users
JSON: A JSON list of Entra users
Raises:
DataSafeHavenMicrosoftGraphError if users could not be loaded
Expand Down Expand Up @@ -1041,7 +1041,7 @@ def remove_user_from_group(
username: str,
group_name: str,
) -> None:
"""Remove a user from an Entra ID group
"""Remove a user from an Entra group
Raises:
DataSafeHavenMicrosoftGraphError if the user could not be removed
Expand Down Expand Up @@ -1076,13 +1076,13 @@ def remove_user_from_group(
def verify_custom_domain(
self, domain_name: str, expected_nameservers: Sequence[str]
) -> None:
"""Verify Entra ID custom domain
"""Verify Entra custom domain
Raises:
DataSafeHavenMicrosoftGraphError if domain could not be verified
"""
try:
# Create the Entra ID custom domain if it does not already exist
# Create the Entra custom domain if it does not already exist
domains = self.read_domains()
if not any(d["id"] == domain_name for d in domains):
msg = f"Domain {domain_name} has not been added to Entra ID."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def create(self, props: dict[str, Any]) -> CreateResult:
)

def delete(self, id_: str, props: dict[str, Any]) -> None:
"""Delete an Entra ID application."""
"""Delete an Entra application."""
# Use `id` as a no-op to avoid ARG002 while maintaining function signature
id(id_)
try:
Expand Down

0 comments on commit f5ffc41

Please sign in to comment.