Skip to content

Commit

Permalink
⚰️ Drop requirements for GraphAPI everywhere in the SRE where they ar…
Browse files Browse the repository at this point in the history
…e used to seed the pulumi-azuread provider
  • Loading branch information
jemrobinson committed Oct 25, 2024
1 parent 7eb6fa0 commit 810d86e
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 49 deletions.
15 changes: 1 addition & 14 deletions data_safe_haven/commands/pulumi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import typer

from data_safe_haven import console
from data_safe_haven.config import ContextManager, DSHPulumiConfig, SHMConfig, SREConfig
from data_safe_haven.external import GraphApi
from data_safe_haven.config import ContextManager, DSHPulumiConfig, SREConfig
from data_safe_haven.infrastructure import SREProjectManager

pulumi_command_group = typer.Typer()
Expand All @@ -33,24 +32,12 @@ def run(
"""Run arbitrary Pulumi commands in a DSH project"""
context = ContextManager.from_file().assert_context()
pulumi_config = DSHPulumiConfig.from_remote(context)
shm_config = SHMConfig.from_remote(context)
sre_config = SREConfig.from_remote_by_name(context, sre_name)

graph_api = GraphApi.from_scopes(
scopes=[
"Application.ReadWrite.All",
"AppRoleAssignment.ReadWrite.All",
"Directory.ReadWrite.All",
"Group.ReadWrite.All",
],
tenant_id=shm_config.shm.entra_tenant_id,
)

project = SREProjectManager(
context=context,
config=sre_config,
pulumi_config=pulumi_config,
graph_api_token=graph_api.token,
)

stdout = project.run_pulumi_command(command)
Expand Down
12 changes: 1 addition & 11 deletions data_safe_haven/commands/sre.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def deploy(
config=sre_config,
pulumi_config=pulumi_config,
create_project=True,
graph_api_token=graph_api.token,
)
# Set Azure options
stack.add_option(
Expand Down Expand Up @@ -153,7 +152,6 @@ def deploy(

# Provision SRE with anything that could not be done in Pulumi
manager = SREProvisioningManager(
graph_api_token=graph_api.token,
location=sre_config.azure.location,
sre_name=sre_config.name,
sre_stack=stack,
Expand Down Expand Up @@ -183,15 +181,8 @@ def teardown(
"""Tear down a deployed a Secure Research Environment."""
logger = get_logger()
try:
# Load context and SHM config
# Load context
context = ContextManager.from_file().assert_context()
shm_config = SHMConfig.from_remote(context)

# Load GraphAPI as this may require user-interaction
graph_api = GraphApi.from_scopes(
scopes=["Application.ReadWrite.All", "Group.ReadWrite.All"],
tenant_id=shm_config.shm.entra_tenant_id,
)

# Load Pulumi and SRE configs
pulumi_config = DSHPulumiConfig.from_remote(context)
Expand All @@ -212,7 +203,6 @@ def teardown(
context=context,
config=sre_config,
pulumi_config=pulumi_config,
graph_api_token=graph_api.token,
create_project=True,
)
stack.teardown(force=force)
Expand Down
3 changes: 0 additions & 3 deletions data_safe_haven/infrastructure/programs/declarative_sre.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ def __init__(
self,
context: Context,
config: SREConfig,
graph_api_token: str,
) -> None:
self.context = context
self.config = config
self.graph_api_token = graph_api_token
self.stack_name = replace_separators(
f"shm-{context.name}-sre-{config.name}", "-"
)
Expand Down Expand Up @@ -293,7 +291,6 @@ def __call__(self) -> None:
dockerhub_credentials=dockerhub_credentials,
entra_application_id=entra.remote_desktop_application_id,
entra_application_url=entra.remote_desktop_url,
entra_auth_token=self.graph_api_token,
entra_tenant_id=shm_entra_tenant_id,
ldap_group_filter=ldap_group_filter,
ldap_group_search_base=ldap_group_search_base,
Expand Down
2 changes: 0 additions & 2 deletions data_safe_haven/infrastructure/programs/sre/remote_desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def __init__(
dockerhub_credentials: DockerHubCredentials,
entra_application_id: Input[str],
entra_application_url: Input[str],
entra_auth_token: str,
entra_tenant_id: Input[str],
ldap_group_filter: Input[str],
ldap_group_search_base: Input[str],
Expand All @@ -58,7 +57,6 @@ def __init__(
self.dockerhub_credentials = dockerhub_credentials
self.entra_application_id = entra_application_id
self.entra_application_url = entra_application_url
self.entra_auth_token = entra_auth_token
self.entra_tenant_id = entra_tenant_id
self.ldap_group_filter = ldap_group_filter
self.ldap_group_search_base = ldap_group_search_base
Expand Down
4 changes: 1 addition & 3 deletions data_safe_haven/infrastructure/project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,12 @@ def __init__(
pulumi_config: DSHPulumiConfig,
*,
create_project: bool = False,
graph_api_token: str | None = None,
) -> None:
"""Constructor"""
token = graph_api_token or ""
super().__init__(
context,
pulumi_config,
config.name,
DeclarativeSRE(context, config, token),
DeclarativeSRE(context, config),
create_project=create_project,
)
3 changes: 0 additions & 3 deletions data_safe_haven/provisioning/sre_provisioning_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
AzureContainerInstance,
AzurePostgreSQLDatabase,
AzureSdk,
GraphApi,
)
from data_safe_haven.infrastructure import SREProjectManager
from data_safe_haven.logging import get_logger
Expand All @@ -19,7 +18,6 @@ class SREProvisioningManager:

def __init__(
self,
graph_api_token: str,
location: AzureLocation,
sre_name: str,
sre_stack: SREProjectManager,
Expand All @@ -28,7 +26,6 @@ def __init__(
):
self._available_vm_skus: dict[str, dict[str, Any]] | None = None
self.location = location
self.graph_api = GraphApi.from_token(graph_api_token)
self.logger = get_logger()
self.sre_name = sre_name
self.subscription_name = subscription_name
Expand Down
5 changes: 0 additions & 5 deletions tests/commands/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ def mock_graph_api_get_application_by_name(mocker, request):
)


@fixture
def mock_graph_api_token(mocker):
mocker.patch.object(GraphApi, "token", return_value="dummy-token")


@fixture
def mock_imperative_shm_deploy(mocker):
mocker.patch.object(
Expand Down
3 changes: 0 additions & 3 deletions tests/commands/test_pulumi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def test_run_sre(
self,
runner,
local_project_settings, # noqa: ARG002
mock_graph_api_token, # noqa: ARG002
mock_install_plugins, # noqa: ARG002
mock_key_vault_key, # noqa: ARG002
mock_pulumi_config_no_key_from_remote, # noqa: ARG002
Expand All @@ -30,7 +29,6 @@ def test_run_sre_invalid_command(
self,
runner,
local_project_settings, # noqa: ARG002
mock_graph_api_token, # noqa: ARG002
mock_install_plugins, # noqa: ARG002
mock_key_vault_key, # noqa: ARG002
mock_pulumi_config_no_key_from_remote, # noqa: ARG002
Expand All @@ -48,7 +46,6 @@ def test_run_sre_invalid_name(
self,
runner,
local_project_settings, # noqa: ARG002
mock_graph_api_token, # noqa: ARG002
mock_install_plugins, # noqa: ARG002
mock_key_vault_key, # noqa: ARG002
mock_pulumi_config_no_key_from_remote, # noqa: ARG002
Expand Down
1 change: 0 additions & 1 deletion tests/commands/test_shm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def test_infrastructure_deploy(
runner,
mock_imperative_shm_deploy_then_exit, # noqa: ARG002
mock_graph_api_add_custom_domain, # noqa: ARG002
mock_graph_api_token, # noqa: ARG002
mock_shm_config_from_remote, # noqa: ARG002
mock_shm_config_remote_exists, # noqa: ARG002
mock_shm_config_upload, # noqa: ARG002
Expand Down
4 changes: 0 additions & 4 deletions tests/commands/test_sre.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def test_deploy(
self,
runner: CliRunner,
mock_azuresdk_get_subscription_name, # noqa: ARG002
mock_graph_api_token, # noqa: ARG002
mock_contextmanager_assert_context, # noqa: ARG002
mock_ip_1_2_3_4, # noqa: ARG002
mock_pulumi_config_from_remote_or_create, # noqa: ARG002
Expand All @@ -34,7 +33,6 @@ def test_no_application(
runner: CliRunner,
mock_azuresdk_get_subscription_name, # noqa: ARG002
mock_contextmanager_assert_context, # noqa: ARG002
mock_graph_api_token, # noqa: ARG002
mock_ip_1_2_3_4, # noqa: ARG002
mock_pulumi_config_from_remote_or_create, # noqa: ARG002
mock_shm_config_from_remote, # noqa: ARG002
Expand All @@ -56,7 +54,6 @@ def test_no_application_secret(
mocker: MockerFixture,
mock_azuresdk_get_subscription_name, # noqa: ARG002
mock_graph_api_get_application_by_name, # noqa: ARG002
mock_graph_api_token, # noqa: ARG002
mock_ip_1_2_3_4, # noqa: ARG002
mock_pulumi_config_from_remote_or_create, # noqa: ARG002
mock_shm_config_from_remote, # noqa: ARG002
Expand Down Expand Up @@ -104,7 +101,6 @@ class TestTeardownSRE:
def test_teardown(
self,
runner: CliRunner,
mock_graph_api_token, # noqa: ARG002
mock_ip_1_2_3_4, # noqa: ARG002
mock_pulumi_config_from_remote, # noqa: ARG002
mock_shm_config_from_remote, # noqa: ARG002
Expand Down

0 comments on commit 810d86e

Please sign in to comment.