Skip to content

Commit 4d4fe34

Browse files
Merge pull request #13 from nsidc/clean
Code/comment cleanup and reorganization
2 parents 4494a40 + 38029d5 commit 4d4fe34

File tree

18 files changed

+486
-443
lines changed

18 files changed

+486
-443
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v0.4.0
2+
3+
- Reorganize code to make it clearer what routes serve EDD vs the python script.
4+
- Improve Swagger API docs.
5+
16
# v0.3.0
27

38
- Add flask-cors, using the same config that hermes-api did. Allow all nsidc.org

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ RUN mkdir -p /tmp/ssl && /opt/conda/bin/openssl req -x509 -nodes -days 365 -newk
1313

1414
EXPOSE 5000
1515

16-
CMD /bin/bash -c "gunicorn --certfile=/tmp/ssl/dat.crt --keyfile=/tmp/ssl/dat.key --bind 0.0.0.0:5000 --workers 9 dat_backend.app:app"
16+
CMD /bin/bash -c "gunicorn --certfile=/tmp/ssl/dat.crt --keyfile=/tmp/ssl/dat.key --bind 0.0.0.0:5000 --workers 9 dat_backend:app"

docker-compose.dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services:
33
build: .
44
volumes:
55
- "./src:/tmp/"
6-
command: '/bin/bash -c "PYTHONPATH=./ python dat_backend/app.py"'
6+
command: '/bin/bash -c "PYTHONPATH=./ python dat_backend/dev_server.py"'
77

88
server:
99
build: ./nginx

docker-compose.production.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
services:
22
api:
3-
image: "ghcr.io/nsidc/data-access-tool-api:v0.3.0"
3+
image: "ghcr.io/nsidc/data-access-tool-api:v0.4.0"
44
server:
5-
image: "ghcr.io/nsidc/data-access-tool-server:v0.3.0"
5+
image: "ghcr.io/nsidc/data-access-tool-server:v0.4.0"

pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "data-access-tool-backend"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
authors = [
55
{ name = "NSIDC", email = "nsidc@nsidc.org" },
66
]
@@ -36,7 +36,7 @@ ignore_missing_imports = true
3636

3737

3838
[too.bumpversion]
39-
current_version = "0.3.0"
39+
current_version = "0.4.0"
4040
commit = false
4141
tag = false
4242

@@ -49,3 +49,8 @@ replace = ':v{new_version}'
4949
filename = "pyproject.toml"
5050
search = 'version = "{current_version}"'
5151
replace = 'version = "{new_version}"'
52+
53+
[[tool.bumpversion.files]]
54+
filename = "src/dat_backend/__init__.py"
55+
search = '__version__ = "{current_version}"'
56+
replace = '__version__ = "{new_version}"'

src/dat_backend/__init__.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os
2+
import logging
3+
import re
4+
5+
import flask_restx as frx
6+
from flask import Flask
7+
from flask_cors import CORS
8+
9+
from dat_backend.reverse_proxy import ReverseProxied
10+
11+
__version__ = "0.4.0"
12+
13+
app = Flask(__name__)
14+
# Enable CORS, allowing all nsidc.org domains.
15+
CORS(
16+
app,
17+
origins=[re.compile(r"^https?:\/\/(.*\.)?nsidc\.org")],
18+
expose_headers=["content-disposition"],
19+
supports_credentials=True,
20+
)
21+
api = frx.Api(
22+
app,
23+
version=__version__,
24+
title="Data Access Tool API",
25+
description="Backend services for the Data Access Tool.",
26+
)
27+
28+
app.wsgi_app = ReverseProxied(app.wsgi_app) # type: ignore[method-assign]
29+
30+
app.logger.setLevel(logging.INFO)
31+
32+
secret_key = os.environ.get("DAT_FLASK_SECRET_KEY")
33+
app.secret_key = secret_key
34+
35+
36+
# Imports of modules containing routes come after . This is necessary so that all of the
37+
# APIs are defined when this file is done initializing.
38+
from dat_backend.routes.earthdata_download import auth, get_links # noqa
39+
from dat_backend.routes import status, python_script # noqa
40+
41+
if __name__ == "__main__":
42+
# `ssl_context` option:
43+
# https://werkzeug.palletsprojects.com/en/2.3.x/serving/#werkzeug.serving.run_simple
44+
app.run(host="0.0.0.0", debug=True, ssl_context="adhoc")

0 commit comments

Comments
 (0)