Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 19, 2024
1 parent ec4cfed commit 6866520
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 37 deletions.
17 changes: 13 additions & 4 deletions exodus_gw/aws/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,21 @@ def definitions(self):
self._definitions = self.query_definitions()
return self._definitions

def _aliases(self, alias_types: list[str]) -> list[tuple[str, str, list[str]]]:
def _aliases(
self, alias_types: list[str]
) -> list[tuple[str, str, list[str]]]:
out: list[tuple[str, str, list[str]]] = []

for k, v in self.definitions.items():
if k in alias_types:
for alias in v:
out.append((alias["src"], alias["dest"],
alias.get("exclude_paths") or []))
out.append(
(
alias["src"],
alias["dest"],
alias.get("exclude_paths") or [],
)
)

return out

Expand Down Expand Up @@ -129,7 +136,9 @@ def aliases_for_flush(self) -> list[tuple[str, str, list[str]]]:
# this alias. If we don't traverse the alias from dest => src then we
# will miss the fact that /content/dist/rhel8/rhui paths should also
# have cache flushed.
out = out + [(dest, src, exclusions) for (src, dest, exclusions) in out]
out = out + [
(dest, src, exclusions) for (src, dest, exclusions) in out
]

return out

Expand Down
17 changes: 10 additions & 7 deletions exodus_gw/aws/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ def get_reader(cls, request):
return cls(request)


def uri_alias(uri: str, aliases: list[tuple[str, str, list[str]]]) -> list[str]:
def uri_alias(
uri: str, aliases: list[tuple[str, str, list[str]]]
) -> list[str]:
# Resolve every alias between paths within the uri (e.g.
# allow RHUI paths to be aliased to non-RHUI).
#
Expand Down Expand Up @@ -222,12 +224,13 @@ def add_out(new_uri: str) -> bool:
# Used to replicate old NetStorage-compatible behaviour. This will
# typically match non-rpm paths, such as /images/ or /isos/
if any([exclusion in uri for exclusion in exclude_paths]):
LOG.debug("Aliasing for %s was not applied as it matches one "
"of the following exclusion paths: %s.",
uri,
",".join(exclude_paths),
extra={"event": "publish", "success": True},
)
LOG.debug(
"Aliasing for %s was not applied as it matches one "
"of the following exclusion paths: %s.",
uri,
",".join(exclude_paths),
extra={"event": "publish", "success": True},
)
continue

new_uri = uri.replace(src, dest, 1)
Expand Down
4 changes: 2 additions & 2 deletions exodus_gw/routers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"type": "array",
"items": {"type": "string"},
"description": "Paths for which alias will not be resolved, "
"treated as an unanchored regex."
}
"treated as an unanchored regex.",
},
},
},
"uniqueItems": True,
Expand Down
5 changes: 3 additions & 2 deletions exodus_gw/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,9 @@ class Alias(BaseModel):
..., description="Target of the alias, relative to CDN root."
)
exclude_paths: list[str] | None = Field(
[], description="Paths for which alias will not be resolved, "
"treated as an unanchored regex."
[],
description="Paths for which alias will not be resolved, "
"treated as an unanchored regex.",
)


Expand Down
8 changes: 6 additions & 2 deletions exodus_gw/worker/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,12 @@ def deploy_config(
# If any original exclusion matches the uri, the uri wouldn't
# have been treated as an alias, thus cache flushing would be
# unnecessary.
if any([exclusion in published_path.web_uri
for exclusion in original_exclusions.get(src, [])]):
if any(
[
exclusion in published_path.web_uri
for exclusion in original_exclusions.get(src, [])
]
):
continue
LOG.info(
"Updated alias %s will flush cache for %s",
Expand Down
34 changes: 22 additions & 12 deletions tests/aws/test_uri_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,37 +145,47 @@ def test_uri_alias_limit(caplog: pytest.LogCaptureFixture):
(
"/content/dist/rhel9/9/x86_64/baseos/iso/PULP_MANIFEST",
[
("/content/dist/rhel9/9", "/content/dist/rhel9/9.5", ["/iso/"]),
(
"/content/dist/rhel9/9",
"/content/dist/rhel9/9.5",
["/iso/"],
),
],
# just returns the original
["/content/dist/rhel9/9/x86_64/baseos/iso/PULP_MANIFEST"],
"Aliasing for /content/dist/rhel9/9/x86_64/baseos/iso/PULP_MANIFEST "
"was not applied as it matches one of the following exclusion paths: /iso/."
"was not applied as it matches one of the following exclusion paths: /iso/.",
),
(
"/some/path/with/file/in/it",
[
("/some/path", "/another/different/path", ["/none/", "/here/"]),
("/another/different/path", "/this/wont/alias", ["/file/"])
(
"/some/path",
"/another/different/path",
["/none/", "/here/"],
),
("/another/different/path", "/this/wont/alias", ["/file/"]),
],
[
"/another/different/path/with/file/in/it",
"/some/path/with/file/in/it",
],
["/another/different/path/with/file/in/it",
"/some/path/with/file/in/it"],
"Aliasing for /another/different/path/with/file/in/it was not "
"applied as it matches one of the following exclusion paths: /file/."
"applied as it matches one of the following exclusion paths: /file/.",
),
(
"/my/base/content/path/cool_iso_tool.rpm",
[
("/my/base", "/your/own", ["/iso/"]),
],
["/your/own/content/path/cool_iso_tool.rpm",
"/my/base/content/path/cool_iso_tool.rpm"],
[
"/your/own/content/path/cool_iso_tool.rpm",
"/my/base/content/path/cool_iso_tool.rpm",
],
"Resolved alias:\\n\\tsrc: /my/base/content/path/cool_iso_tool.rpm"
"\\n\\tdest: /your/own/content/path/cool_iso_tool.rpm"
"\\n\\tdest: /your/own/content/path/cool_iso_tool.rpm",
),
],
ids=["basic", "transitive", "filename"],
)
def test_uri_alias_exclusions(input, aliases, output, log_message, caplog):
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from .async_utils import BlockDetector


DEFAULT_EXCLUDE_PATHS = ["/files/", "/images/", "/iso/"]


Expand Down
16 changes: 11 additions & 5 deletions tests/worker/test_cdn_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,23 @@ def test_flush_cdn_cache_typical(
{
"src": "/path/one",
"dest": "/path/one-dest",
"exclude_paths": ["/files/", "/images/",
"/iso/"],
"exclude_paths": [
"/files/",
"/images/",
"/iso/",
],
},
],
"rhui_alias": [
{
"src": "/path/rhui/two",
"dest": "/path/two",
"exclude_paths": ["/files/", "/images/",
"/iso/"],
},
"exclude_paths": [
"/files/",
"/images/",
"/iso/",
],
},
],
}
)
Expand Down
4 changes: 2 additions & 2 deletions tests/worker/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_deploy_config_with_flush(
{
"dest": "/content/testproduct/1.2.0",
"src": "/content/testproduct/1",
"exclude_paths": ["/newExclusion/"]
"exclude_paths": ["/newExclusion/"],
},
]
worker.deploy_config(updated_config, "test", NOW_UTC)
Expand Down Expand Up @@ -222,7 +222,7 @@ def test_deploy_config_with_flush(
"/content/dist/rhel/server/listing",
"/content/testproduct/1/file1",
"/content/testproduct/1/file2",
"/content/testproduct/1/newExclusion/file5"
"/content/testproduct/1/newExclusion/file5",
]

# And actor call should have been delayed by this long.
Expand Down

0 comments on commit 6866520

Please sign in to comment.