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

Fix storage account network acls retrieved from properties #1620

Merged
merged 1 commit into from
May 3, 2024
Merged
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
6 changes: 2 additions & 4 deletions src/databricks/labs/ucx/azure/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class StorageAccount:
id: AzureResource
name: str
location: str
default_network_action: str # "Deny" or "Allow"
default_network_action: str # "Unknown", "Deny" or "Allow"

@classmethod
def from_raw_resource(cls, raw: RawResource) -> "StorageAccount":
Expand All @@ -125,9 +125,7 @@ def from_raw_resource(cls, raw: RawResource) -> "StorageAccount":
if location == "":
raise KeyError(f"Missing location: {raw}")

default_network_action = raw.get("networkAcls", {}).get("defaultAction", "")
if default_network_action == "":
raise KeyError(f"Missing networkAcls.defaultAction: {raw}")
default_network_action = raw.get("properties", {}).get("networkAcls", {}).get("defaultAction", "Unknown")

storage_account = cls(id=raw.id, name=name, location=location, default_network_action=default_network_action)
return storage_account
Expand Down
12 changes: 8 additions & 4 deletions tests/unit/azure/azure/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,20 @@
"name": "sto2",
"id": "subscriptions/002/resourceGroups/rg1/storageAccounts/sto2",
"location": "westeu",
"networkAcls": {
"defaultAction": "Allow"
"properties": {
"networkAcls": {
"defaultAction": "Allow"
}
}
},
{
"name": "sto3",
"id": "subscriptions/002/resourceGroups/rg1/storageAccounts/sto3",
"location": "westeu",
"networkAcls": {
"defaultAction": "Deny"
"properties": {
"networkAcls": {
"defaultAction": "Deny"
}
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/azure/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ def test_role_assignments_container():
assert role_assignment.resource == AzureResource(resource_id)


@pytest.mark.parametrize("missing_field", ["id", "name", "location", "networkAcls"])
@pytest.mark.parametrize("missing_field", ["id", "name", "location"])
def test_storage_account_missing_fields(missing_field: str):
"""A KeyError should be raised when the fields are missing."""
raw = {
"name": "sto3",
"id": "subscriptions/002/resourceGroups/rg1/storageAccounts/sto3",
"location": "westeu",
"networkAcls": {"defaultAction": "Deny"},
"properties": {"networkAcls": {"defaultAction": "Deny"}},
}
raw.pop(missing_field)
with pytest.raises(KeyError):
Expand Down
Loading