Skip to content

Commit

Permalink
Location service deployment updates (#20)
Browse files Browse the repository at this point in the history
* update code for azure deployment
  • Loading branch information
ryan-lam authored Oct 18, 2023
1 parent cc8615d commit 30a42c3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions location_service/.env.sample
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DATABASE_URI="postgresql+psycopg2://user:password@host:port/database"
AUTH_KEY=""
3 changes: 2 additions & 1 deletion location_service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM python:3.11.4-buster
RUN pip install --upgrade cython pip

ENV DATABASE_URI=""
ENV AUTH_KEY=""

WORKDIR /usr/location_service

Expand All @@ -12,4 +13,4 @@ COPY . .


EXPOSE 5000
CMD [ "python", "src/main.py" ]
CMD [ "python", "src/main.py", "--create-table", "true", "--seed-filename", "./uw_sample_gpx.csv"]
10 changes: 9 additions & 1 deletion location_service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ and the service will be running on [localhost:5000](http://localhost:5000/)
### `/all` [GET]

Retruns all the data in the `location_service` database
Expected body:

```
{
auth_key: <String>
}
```

### `/location` [POST]

Expand All @@ -41,7 +48,8 @@ Expected body:
```
{
lat: <Float>,
lon: <Float>
lon: <Float>,
auth_key: <String>
}
```

Expand Down
12 changes: 12 additions & 0 deletions location_service/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

load_dotenv()
DATABASE_URI = os.environ.get("DATABASE_URI")
AUTH_KEY = os.environ.get("AUTH_KEY")


parser = ArgumentParser()
Expand Down Expand Up @@ -74,13 +75,21 @@ def seed_from_csv(filename):
db.session.commit()


def authorized(auth_key):
return auth_key == AUTH_KEY


@app.route("/", methods=["GET"])
def index():
return "location service"


@app.route("/all", methods=["GET"])
def all():
body = json.loads(request.data)
auth_key = body.get("auth_key", None)
if not authorized(auth_key):
return "Not authorized", 401
locations = db.session.query(Location).order_by(asc(Location.id))
return [l.to_dict() for l in locations]

Expand All @@ -90,6 +99,9 @@ def closest_location():
body = json.loads(request.data)
lat = body.get("lat", None)
lon = body.get("lon", None)
auth_key = body.get("auth_key", None)
if not authorized(auth_key):
return "Not authorized", 401
if lat is None or lon is None:
return "Invalid request body", 400
location = (
Expand Down

0 comments on commit 30a42c3

Please sign in to comment.