From 416f4de4d596b1dab268a47c6c9cb3740a2a0b1f Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Fri, 20 Jan 2023 14:32:20 -0600 Subject: [PATCH 01/31] add a devcontainer --- .devcontainer/Dockerfile | 12 +++++++++++ .devcontainer/devcontainer.json | 29 ++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 35 ++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..fffdd89 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,12 @@ +FROM mcr.microsoft.com/devcontainers/python:0-3.11 + +ENV PYTHONUNBUFFERED 1 + +# [Optional] If your requirements rarely change, uncomment this section to add them to the image. +COPY requirements.txt /tmp/pip-tmp/ +RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \ + && rm -rf /tmp/pip-tmp + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..b4be2cb --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,29 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/postgres +{ + "name": "Python 3 & PostgreSQL", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + "features": { + "ghcr.io/devcontainers/features/azure-cli:1": {}, + "ghcr.io/devcontainers-contrib/features/heroku-cli:1": {}, + "ghcr.io/stuartleeks/dev-container-features/azure-cli-persistence:0": {} + } + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // This can be used to network with other containers or the host. + // "forwardPorts": [5000, 5432], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "pip install --user -r requirements.txt", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..f2e9705 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,35 @@ +version: '3.8' + +services: + app: + build: + context: .. + dockerfile: .devcontainer/Dockerfile + + volumes: + - ../..:/workspaces:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:db + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + db: + image: postgres:latest + restart: unless-stopped + volumes: + - postgres-data:/var/lib/postgresql/data + environment: + POSTGRES_USER: postgres + POSTGRES_DB: postgres + POSTGRES_PASSWORD: postgres + + # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + +volumes: + postgres-data: From 01a70db5f98c1c9dadd03e12f8eba2ffc6ea241b Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Fri, 20 Jan 2023 14:38:20 -0600 Subject: [PATCH 02/31] tweaks to editorconfig --- .editorconfig | 32 ++++++++++++++++++++++++++++++++ .gitattributes | 3 +++ .gitignore | 9 +-------- .vscode/extensions.json | 5 +++++ 4 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .vscode/extensions.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f3d7921 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,32 @@ +# top-most .editorconfig file +# See Also: https://EditorConfig.org +root = true + +# By default indent with 4 spaces +[*] +indent_style = space +indent_size = 4 +#insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 +# Note: this is not currently supported by all editors or their editorconfig plugins. +#max_line_length = 132 + +# Makefiles need tab indentation +[{Makefile,*.mk}] +indent_style = tab +tab_width = 8 +end_of_line = lf + +# Set some end_of_line rules. +# See Also: .gitattributes + +[{*.ps1,*.cmd,*.bat}] +end_of_line = crlf + +[*.sh] +end_of_line = lf + +[{*.yml,*.yaml}] +indent_style = space +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5f2e203 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +*.sh text eol=lf +*.ps1 text eol=crlf +*.bat text eol=crlf diff --git a/.gitignore b/.gitignore index 3919f0c..a01ee28 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1 @@ -/media -/__pycache__ -error.log -/db/podcast.db -/test -cover.png -temp -temp_conversion.mp3 \ No newline at end of file +.*.swp diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..189adec --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "editorconfig.editorconfig" + ] +} \ No newline at end of file From 5f3682c7ad58b52f5a83699f126309982abcbb20 Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Fri, 20 Jan 2023 14:38:36 -0600 Subject: [PATCH 03/31] be consistent and use python 3.8 like the heroku config says --- .devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index fffdd89..04ba2bb 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/devcontainers/python:0-3.11 +FROM mcr.microsoft.com/devcontainers/python:0-3.8 ENV PYTHONUNBUFFERED 1 From 529551792baef66bfe16cfd783c576aaf09c37fc Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Fri, 20 Jan 2023 20:48:48 +0000 Subject: [PATCH 04/31] add proxy caching support --- .devcontainer/devcontainer.json | 8 +++++++- .devcontainer/docker-compose.yml | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b4be2cb..aa5d43b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,11 +5,17 @@ "dockerComposeFile": "docker-compose.yml", "service": "app", "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + "containerEnv": { + // Support local proxy caches for rebuilding the container more quickly. + "http_proxy": "${localEnv:http_proxy}", + "https_proxy": "${localEnv:https_proxy}", + "no_proxy": "${localEnv:no_proxy}" + }, "features": { "ghcr.io/devcontainers/features/azure-cli:1": {}, "ghcr.io/devcontainers-contrib/features/heroku-cli:1": {}, "ghcr.io/stuartleeks/dev-container-features/azure-cli-persistence:0": {} - } + } // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index f2e9705..c88e6f6 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -5,6 +5,10 @@ services: build: context: .. dockerfile: .devcontainer/Dockerfile + args: + http_proxy: ${http_proxy} + https_proxy: ${https_proxy} + no_proxy: ${no_proxy} volumes: - ../..:/workspaces:cached From 72ad3a66cc4b8adc557d38ae6c834d5b1113c4ed Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Fri, 20 Jan 2023 20:48:56 +0000 Subject: [PATCH 05/31] make some shebang paths work --- .devcontainer/Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 04ba2bb..603900e 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -10,3 +10,7 @@ RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requ # [Optional] Uncomment this section to install additional OS packages. # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # && apt-get -y install --no-install-recommends + +# Make the shebang path used in the original python scripts available in this container. +RUN mkdir -p /Library/Frameworks/Python.framework/Versions/3.8/bin \ + && ln -s /usr/local/bin/python3.8 /Library/Frameworks/Python.framework/Versions/3.8/bin/ \ No newline at end of file From fdc6b9704898270f4fd1c1c6a151442d0a1b419f Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Fri, 20 Jan 2023 15:01:06 -0600 Subject: [PATCH 06/31] add support for an environment file --- .devcontainer/devcontainer.json | 3 ++- .devcontainer/docker-compose.yml | 2 ++ .gitignore | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index aa5d43b..850419a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,7 +15,8 @@ "ghcr.io/devcontainers/features/azure-cli:1": {}, "ghcr.io/devcontainers-contrib/features/heroku-cli:1": {}, "ghcr.io/stuartleeks/dev-container-features/azure-cli-persistence:0": {} - } + }, + "initializeCommand": "touch ${localWorkspaceFolder}/.env" // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index c88e6f6..11ed8fc 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -16,6 +16,8 @@ services: # Overrides default command so things don't shut down after the process ends. command: sleep infinity + env_file: ../.env + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. network_mode: service:db diff --git a/.gitignore b/.gitignore index a01ee28..060c880 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .*.swp +.env \ No newline at end of file From db0829bcee4628cc310d392ff4afb61da069d823 Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Fri, 20 Jan 2023 21:06:39 +0000 Subject: [PATCH 07/31] quick hack to make the pinned flask version work with old dependencies --- requirements.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 428f288..a6085cf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,7 @@ psycopg2-binary==2.8.6 flask-accept==0.0.6 APScheduler==3.0.0 werkzeug==0.16.0 -gunicorn \ No newline at end of file +gunicorn +# https://github.com/pallets/flask/issues/4494#issuecomment-1080041085 +Jinja2==3.0.3 +itsdangerous==2.0.1 \ No newline at end of file From cdfc60ccaeed273002dbfffbebd4c7b868d848ae Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Fri, 20 Jan 2023 21:54:16 +0000 Subject: [PATCH 08/31] reformat json --- .editorconfig | 4 ++++ app.json | 54 +++++++++++++++++++++++++++------------------------ 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/.editorconfig b/.editorconfig index f3d7921..31c1079 100644 --- a/.editorconfig +++ b/.editorconfig @@ -30,3 +30,7 @@ end_of_line = lf [{*.yml,*.yaml}] indent_style = space indent_size = 2 + +[*.json] +indent_style = space +indent_size = 2 \ No newline at end of file diff --git a/app.json b/app.json index a3da193..ecd125c 100644 --- a/app.json +++ b/app.json @@ -1,27 +1,31 @@ { - "name": "Podcast Sync for Garmin Server", - "description": "Server component for Podcast Connect IQ application.", - "repository": "https://gitlab.com/ravenfeld/server-podcastsyncgarmin", - "logo": "https://www8.garmin.com/HiRes/logos/GarminLogo.jpg", - "keywords": ["garmin", "podcast", "connectiq"], - "addons": [ - { - "plan": "heroku-postgresql" - } - ], - "success_url": "/", - "env": { - "NUMBER_MAX_USER": { - "description": "Maximum number of users using the application ?", - "value": "1" - }, - "PODCASTING_INDEX_KEY": { - "description": "API KEY for podcast search. https://api.podcastindex.org/", - "required":"false" - }, - "PODCASTING_INDEX_SECRET": { - "description": "API SECRET for podcast search. https://api.podcastindex.org/", - "required":"false" - } - } + "name": "Podcast Sync for Garmin Server", + "description": "Server component for Podcast Connect IQ application.", + "repository": "https://gitlab.com/ravenfeld/server-podcastsyncgarmin", + "logo": "https://www8.garmin.com/HiRes/logos/GarminLogo.jpg", + "keywords": [ + "garmin", + "podcast", + "connectiq" + ], + "addons": [ + { + "plan": "heroku-postgresql" + } + ], + "success_url": "/", + "env": { + "NUMBER_MAX_USER": { + "description": "Maximum number of users using the application ?", + "value": "1" + }, + "PODCASTING_INDEX_KEY": { + "description": "API KEY for podcast search. https://api.podcastindex.org/", + "required": "false" + }, + "PODCASTING_INDEX_SECRET": { + "description": "API SECRET for podcast search. https://api.podcastindex.org/", + "required": "false" + } + } } From 189584c1f957c614e2a525a473d3345a07b22db7 Mon Sep 17 00:00:00 2001 From: Brian Kroth Date: Fri, 20 Jan 2023 21:55:49 +0000 Subject: [PATCH 09/31] add support for some basic authentication before allowing to create new users --- app.json | 4 ++++ server.py | 4 ++++ templates/create_user.html | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/app.json b/app.json index ecd125c..970f40a 100644 --- a/app.json +++ b/app.json @@ -26,6 +26,10 @@ "PODCASTING_INDEX_SECRET": { "description": "API SECRET for podcast search. https://api.podcastindex.org/", "required": "false" + }, + "ADMIN_PASS": { + "description": "A password to use for restriction access to admin functions (e.g. creating logins).", + "value": "" } } } diff --git a/server.py b/server.py index b053d87..525f07a 100644 --- a/server.py +++ b/server.py @@ -172,6 +172,10 @@ def get_list_episode_sync_watch(user_id): @app.route('/create_user', methods=['POST']) @accept('application/json') def create_user(): + expected_admin_pass = os.environ['ADMIN_PASS'] + admin_pass = request.form.get('admin_pass') + if admin_pass != expected_admin_pass: + return Response(json.dumps({'error': 'Unauthorized'}), status=403, mimetype='application/json') login = request.form.get('login') password = request.form.get('password') result = manager_podcast.create_account(login, password) diff --git a/templates/create_user.html b/templates/create_user.html index db65df5..41ec09e 100644 --- a/templates/create_user.html +++ b/templates/create_user.html @@ -39,6 +39,12 @@

+
+ + +