-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from jsickcodes/edition-url-rewrites
Add logic for mapping paths to S3 keys
- Loading branch information
Showing
11 changed files
with
206 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,9 @@ jobs: | |
with: | ||
python-version: ${{ matrix.python }} | ||
|
||
- name: Install stable virtualenv # https://github.com/pre-commit/action/issues/135 | ||
run: pip install -U virtualenv==20.10.0 | ||
|
||
- name: Run pre-commit | ||
uses: pre-commit/[email protected] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: "ltdproxy" | ||
name: "ltd-proxy" | ||
labels: | ||
app.kubernetes.io/name: "ltd-proxy" | ||
spec: | ||
ports: | ||
- name: "ltdproxy-http" | ||
- name: "ltd-proxy-http" | ||
protocol: "TCP" | ||
port: 8080 | ||
targetPort: "app" | ||
selector: | ||
app.kubernetes.io/name: "ltdproxy" | ||
app.kubernetes.io/name: "ltd-proxy" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Domain model for mapping a request URL to a resource in the S3 bucket.""" | ||
|
||
from __future__ import annotations | ||
|
||
__all__ = ["map_s3_path"] | ||
|
||
|
||
def map_s3_path(bucket_prefix: str, request_path: str) -> str: | ||
"""Map a request URL to an S3 bucket key.""" | ||
# decompose the path into the project and whether it is a /v/ edition or | ||
# not | ||
parts = request_path.split("/") | ||
project_name = parts[0].lower() | ||
|
||
if (len(parts) >= 3) and parts[1].lower() == "v": | ||
edition_name = parts[2] | ||
edition_path = "/".join(parts[3:]) | ||
else: | ||
edition_name = "__main" # default edition | ||
edition_path = "/".join(parts[1:]) | ||
|
||
# if edition_path == "" or edition_path.endswith("/"): | ||
if request_path.endswith("/"): | ||
edition_path = f"{edition_path}index.html" | ||
|
||
if bucket_prefix == "": | ||
path_parts = [project_name, "v", edition_name, edition_path] | ||
else: | ||
path_parts = [ | ||
bucket_prefix, | ||
project_name, | ||
"v", | ||
edition_name, | ||
edition_path, | ||
] | ||
|
||
bucket_path = "/".join(path_parts) | ||
bucket_path = bucket_path.rstrip("/") # happens if edition_path is "" | ||
|
||
return bucket_path |
Oops, something went wrong.