Skip to content

Commit e58e5bb

Browse files
Merge branch 'main' into connectum-based-scraper
2 parents a570931 + 1b277bb commit e58e5bb

File tree

13 files changed

+73
-45
lines changed

13 files changed

+73
-45
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ insert_final_newline = true
1010
max_line_length = 120
1111
indent_size = 2
1212
indent_style = space
13+
14+
[*.py]
15+
indent_size = 4

.env

+4
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ JWT_KEY=CHANGE_ME
1212

1313
# main api
1414
MEILI_MASTER_KEY=CHANGE_ME
15+
16+
# calendar
17+
CONNECTUM_OAUTH_CLIENT_SECRET=CHANGE_ME
18+
CONNECTUM_OAUTH_CLIENT_ID=CHANGE_ME

.github/workflows/update-data.yml

+8
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,16 @@ jobs:
3030
export PYTHONPATH=$PYTHONPATH:..
3131
python3 main.py
3232
ls -lah results
33+
sed -i 's/Bestelmeyer S\u00fcd/Zentralgeb\u00e4ude 2/g' results/buildings_roomfinder.json
34+
sed -i 's/Bestelmeyer Nord/Zentralgeb\u00e4ude 7/g' results/buildings_roomfinder.json
35+
sed -i 's/Bestelmeyer S\u00fcd/Zentralgeb\u00e4ude 2/g' results/maps_roomfinder.json
36+
sed -i 's/Bestelmeyer Nord/Zentralgeb\u00e4ude 7/g' results/maps_roomfinder.json
37+
sed -i 's/Bestelmeyer S\u00fcd/Zentralgeb\u00e4ude 2/g' results/rooms_roomfinder.json
38+
sed -i 's/Bestelmeyer Nord/Zentralgeb\u00e4ude 7/g' results/rooms_roomfinder.json
3339
env:
3440
TQDM_MININTERVAL: 100
41+
CONNECTUM_OAUTH_CLIENT_ID: ${{ secrets.CONECTUM_OAUTH_CLIENT_ID }}
42+
CONNECTUM_OAUTH_CLIENT_SECRET: ${{ secrets.CONECTUM_OAUTH_CLIENT_SECRET }}
3543
working-directory: data/external
3644
- name: Fix linting errors
3745
continue-on-error: true

data/compile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
structure,
1919
tumonline,
2020
)
21-
from utils import DEBUG_MODE, setup_logging
21+
from utils import DEV_MODE, setup_logging
2222

2323

2424
# pylint: disable=too-many-locals,too-many-statements
@@ -130,7 +130,7 @@ def main() -> None:
130130

131131

132132
if __name__ == "__main__":
133-
setup_logging(level=logging.DEBUG if DEBUG_MODE else logging.INFO)
133+
setup_logging(level=logging.DEBUG if DEV_MODE else logging.INFO)
134134

135135
# Pillow prints all imported modules to the debug stream
136136
logging.getLogger("PIL").setLevel(logging.INFO)

data/processors/images.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
from typing import Any, NamedTuple, TypeVar
1010

1111
import pydantic
12-
import utils
1312
import yaml
14-
from external.models.common import PydanticConfiguration
1513
from PIL import Image
1614
from pydantic import Field
1715
from pydantic.networks import HttpUrl
1816

17+
import utils
18+
from external.models.common import PydanticConfiguration
19+
1920

2021
class UrlStr(PydanticConfiguration):
2122
text: str
@@ -219,9 +220,6 @@ def _extract_offsets(_id: str, _index: int, img_path: Path, img_sources: dict[st
219220

220221
def _get_hash_lut() -> dict[str, str]:
221222
"""Get a lookup table for the hash of the image files content and offset if present"""
222-
if not DEV_MODE:
223-
return {}
224-
logging.info("Since GIT_COMMIT_SHA is unset, we assume this is acting in In Dev mode.")
225223
logging.info("Only files, with sha256(file-content)_sha256(offset) not present in the .hash_lut.json will be used")
226224
if HASH_LUT.is_file():
227225
with open(HASH_LUT, encoding="utf-8") as file:
@@ -268,13 +266,12 @@ def resize_and_crop() -> None:
268266
for img_path in IMAGE_SOURCE.glob("*.webp"):
269267
_id, _index = parse_image_filename(img_path.name)
270268
offsets = _extract_offsets(_id, _index, img_path, img_sources)
269+
actual_hash = _gen_file_hash(img_path, offsets)
270+
if actual_hash == expected_hashes_lut.get(img_path.name, ""):
271+
continue # skip this image, since it (and its offsets) have not changed
271272
if DEV_MODE:
272-
actual_hash = _gen_file_hash(img_path, offsets)
273-
if actual_hash == expected_hashes_lut.get(img_path.name, ""):
274-
continue # skip this image, since it (and its offsets) have not changed
275273
logging.debug(f"Image '{img_path.name}' has changed, resizing and cropping...")
276274
executor.submit(_refresh_for_all_resolutions, RefreshResolutionOrder(img_path, offsets))
277-
if DEV_MODE:
278-
_save_hash_lut(img_sources)
279-
resize_and_crop_time = time.time() - start_time
280-
logging.info(f"Resize and crop took {resize_and_crop_time:.2f}s")
275+
_save_hash_lut(img_sources)
276+
resize_and_crop_time = time.time() - start_time
277+
logging.info(f"Resize and crop took {resize_and_crop_time:.2f}s")

data/processors/sitemap.py

-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import requests
1010
from defusedxml import ElementTree as defusedET
1111

12-
from utils import DEBUG_MODE
13-
1412
OLD_DATA_URL = "https://nav.tum.de/cdn/api_data.json"
1513

1614

@@ -35,10 +33,6 @@ class SimplifiedSitemaps(TypedDict):
3533

3634
def generate_sitemap() -> None:
3735
"""Generate a sitemap that diffs changes since to the currently online data"""
38-
if DEBUG_MODE:
39-
logging.info("Skipping sitemap generation in Dev Mode (GIT_COMMIT_SHA is unset)")
40-
return
41-
4236
# Load exported data. This function is intentionally not using the data object
4337
# directly, but re-parsing the output file instead, because the export not
4438
# export all fields. This way we're also guaranteed to have the same types

data/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
with open(TRANSLATION_BUFFER_PATH, encoding="utf-8") as yaml_file:
1616
TRANSLATION_BUFFER = yaml.load(yaml_file)
1717

18-
DEBUG_MODE = "GIT_COMMIT_SHA" not in os.environ
18+
DEV_MODE = "GIT_COMMIT_SHA" not in os.environ
1919

2020

2121
class TranslatableStr(dict):

deployment/README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ On every of these nodes we run the following supporting services:
2424

2525
- [traefik](https://traefik.io/) as a reverse proxy
2626
- [cert-manager](https://cert-manager.io/) to manage the https-certificate via [Let's Encrypt](https://letsencrypt.org/)
27-
- [prometeus](https://prometheus.io/), [allertmanager](https://prometheus.io/docs/alerting/latest/alertmanager/) and [grafana](https://grafana.com/) for monitoring purposes
27+
- [prometeus](https://prometheus.io/), [allertmanager](https://prometheus.io/docs/alerting/latest/alertmanager/)
28+
and [grafana](https://grafana.com/) for monitoring purposes
2829
- [argocd](https://argo-cd.readthedocs.io/) to manage the deployments
2930
- [uptime-kuma](https://github.com/louislam/uptime-kuma) to monitor the uptime of the services
3031

@@ -46,11 +47,16 @@ Namely:
4647

4748
- we don't publish our `GITHUB_TOKEN` to git. (used to pass feedback from the webclient to github)
4849
- we don't publish the `JWT_KEY` to git. (used to generate tokens to ratelimt feedback creation)
49-
- we don't publish the `MEILI_MASTER_KEY` to git. (used as aditional layer of network hardening between the webclient and the server)
50+
- we don't publish the `MEILI_MASTER_KEY` to git. (used as aditional layer of network hardening between the webclient
51+
and the server)
52+
- we don't publish the `CONNECTUM_OAUTH_CLIENT_{SECRET,ID}` to git. (used to connect to the calendar and possibly
53+
further apis in the future)
5054

5155
Deployment happen automatically on push to main, or on push to a PR.
52-
For PRs we only execute this deployment request, if the autor is a member of the `@TUM-Dev/navigatum`-group or a member authorises this PR to run actions.
53-
The reasoning is, that we don't want strangers to be able to fork our project, change the deployment to something malicious and make us deploy it.
56+
For PRs we only execute this deployment request, if the autor is a member of the `@TUM-Dev/navigatum`-group or a member
57+
authorises this PR to run actions.
58+
The reasoning is, that we don't want strangers to be able to fork our project, change the deployment to something
59+
malicious and make us deploy it.
5460

5561
### ansible
5662

deployment/k3s/templates/deployments/server-deployment.yaml

+21-7
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ spec:
8181
- name: mieli-search
8282
image: {{ $.Values.mielisearch.image.repository }}:{{ $.Values.mielisearch.image.tag }}
8383
imagePullPolicy: IfNotPresent
84-
{{ if $.Values.server.MEILI_MASTER_KEY }}
8584
envFrom:
8685
- secretRef:
87-
name: server-api-keys # MEILI_MASTER_KEY
86+
name: server-api-keys # GITHUB_TOKEN, JWT_KEY, CONNECTUM_OAUTH_CLIENT_{SECRET,ID}
87+
- secretRef:
88+
name: server-search-key # MEILI_MASTER_KEY
8889
env:
8990
- name: MEILI_ENV
9091
value: production
91-
{{ end }}
9292
ports:
9393
- containerPort: 7700
9494
name: http
@@ -117,7 +117,20 @@ spec:
117117
port: http
118118
periodSeconds: 10
119119
failureThreshold: 2
120-
{{ if $.Values.server.MEILI_MASTER_KEY }}
120+
{{ if $.Values.server.MEILI_MASTER_KEY }}
121+
---
122+
apiVersion: v1
123+
kind: Secret
124+
type: Opaque
125+
metadata:
126+
name: server-search-key
127+
namespace: {{ $.Values.namespace }}
128+
labels:
129+
app.kubernetes.io/part-of: navigatum
130+
app.kubernetes.io/name: api
131+
data:
132+
MEILI_MASTER_KEY: {{ $.Values.server.MEILI_MASTER_KEY }}
133+
{{ end }}
121134
---
122135
apiVersion: v1
123136
kind: Secret
@@ -129,7 +142,8 @@ metadata:
129142
app.kubernetes.io/part-of: navigatum
130143
app.kubernetes.io/name: api
131144
data:
132-
{{ if $.Values.server.MEILI_MASTER_KEY }}
133145
MEILI_MASTER_KEY: {{ $.Values.server.MEILI_MASTER_KEY }}
134-
{{ end }}
135-
{{ end }}
146+
GITHUB_TOKEN: {{ $.Values.server.GITHUB_TOKEN }}
147+
JWT_KEY: {{ $.Values.server.JWT_KEY }}
148+
CONNECTUM_OAUTH_CLIENT_SECRET: {{ $.Values.server.CONNECTUM_OAUTH_CLIENT_SECRET }}
149+
CONNECTUM_OAUTH_CLIENT_ID: {{ $.Values.server.CONNECTUM_OAUTH_CLIENT_ID }}

deployment/k3s/values.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ namespace: navigatum
22
tag: main
33
url: nav.tum.de
44
server:
5+
CONNECTUM_OAUTH_CLIENT_SECRET: ""
6+
CONNECTUM_OAUTH_CLIENT_ID: ""
57
MEILI_MASTER_KEY: ""
68
GITHUB_TOKEN: ""
79
JWT_KEY: ""

server/Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/main-api/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ actix-web = { version = "4.5.1", default-features = false, features = ["macros",
3131
actix-cors = "0.7.0"
3232
rustls = { version = "0.23.5", default-features = false, features = ["ring"] } # the aws' fips complient libary has weird bingen issues which require deeper looking into
3333

34-
cached = { version = "0.51.0", features = ["default", "async", "tokio", "disk_store"] }
34+
cached = { version = "0.51.1", features = ["default", "async", "tokio", "disk_store"] }
3535
futures = "0.3.30"
3636
unicode-truncate = "1.0.0"
3737

server/main-api/src/calendar/fetch/connectum.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl CalendarEntryFetcher for APIRequestor {
4242
.secret()
4343
.clone();
4444
let url = format!(
45-
"https://review.campus.tum.de/RSYSTEM/co/connectum/api/rooms/{tumonline_id}/calendars"
45+
"https://campus.tum.de/tumonline/co/connectum/api/rooms/{tumonline_id}/calendars"
4646
);
4747

4848
let events: Vec<Event> = self
@@ -109,20 +109,20 @@ impl APIRequestor {
109109
Ok(())
110110
}
111111
async fn fetch_oauth_token(&self) -> Result<BasicTokenResponse, crate::BoxedError> {
112-
let client_id = env::var("TUMONLINE_OAUTH_CLIENT_ID")
112+
let client_id = env::var("CONNECTUM_OAUTH_CLIENT_ID")
113113
.map_err(|e| {
114-
error!("TUMONLINE_OAUTH_CLIENT_ID needs to be set: {e:?}");
115-
io::Error::other("please configure the environment variable TUMONLINE_OAUTH_CLIENT_ID to use this endpoint")
114+
error!("CONNECTUM_OAUTH_CLIENT_ID needs to be set: {e:?}");
115+
io::Error::other("please configure the environment variable CONNECTUM_OAUTH_CLIENT_ID to use this endpoint")
116116
})?;
117-
let client_secret = env::var("TUMONLINE_OAUTH_CLIENT_SECRET")
117+
let client_secret = env::var("CONNECTUM_OAUTH_CLIENT_SECRET")
118118
.map_err(|e| {
119-
error!("TUMONLINE_OAUTH_CLIENT_SECRET needs to be set: {e:?}");
120-
io::Error::other("please configure the environment variable TUMONLINE_OAUTH_CLIENT_SECRET to use this endpoint")
119+
error!("CONNECTUM_OAUTH_CLIENT_SECRET needs to be set: {e:?}");
120+
io::Error::other("please configure the environment variable CONNECTUM_OAUTH_CLIENT_SECRET to use this endpoint")
121121
})?;
122122

123-
// for urls see https://review.campus.tum.de/RSYSTEM/co/public/sec/auth/realms/CAMPUSonline/.well-known/openid-configuration
124-
let auth_url = Url::parse("https://review.campus.tum.de/RSYSTEM/co/public/sec/auth/realms/CAMPUSonline/protocol/openid-connect/auth")?;
125-
let token_url = Url::parse("https://review.campus.tum.de/RSYSTEM/co/public/sec/auth/realms/CAMPUSonline/protocol/openid-connect/token")?;
123+
// for urls see https://campus.tum.de/tumonline/co/public/sec/auth/realms/CAMPUSonline/.well-known/openid-configuration
124+
let auth_url = Url::parse("https://campus.tum.de/tumonline/co/public/sec/auth/realms/CAMPUSonline/protocol/openid-connect/auth")?;
125+
let token_url = Url::parse("https://campus.tum.de/tumonline/co/public/sec/auth/realms/CAMPUSonline/protocol/openid-connect/token")?;
126126

127127
let token = BasicClient::new(
128128
ClientId::new(client_id),

0 commit comments

Comments
 (0)