Browse Source

Putting an API key that is only for the static streetview api in the back-end, removing unneeded api endpoint

Kirk Trombley 5 years ago
parent
commit
7ca163d654
5 changed files with 8 additions and 24 deletions
  1. 0 2
      .gitignore
  2. 0 5
      README.md
  3. 1 10
      server/app.py
  4. 3 4
      server/game_api.py
  5. 4 3
      server/lib.py

+ 0 - 2
.gitignore

@@ -7,6 +7,4 @@ __pycache__/
 dist/
 node_modules/
 
-secrets.sh
-
 ggsh.tgz

+ 0 - 5
README.md

@@ -15,10 +15,6 @@ GET /
         "version": string,
         "status": string
     }
-GET /googleApiKey
-    Returns {
-        "googleApiKey": string
-    }
 PUT /game
     Header Authorization: Name string
     Accepts {
@@ -99,6 +95,5 @@ POST /game/{ID}/guesses/{round}
 - Re-join a game you did not finish
 - Show current best on round summary
 - Round summary should use dynamic map
-- Cache API key after first call to back-end
 - Styling and layout improvements
 - Optimize docker file or set up compose structure

+ 1 - 10
server/app.py

@@ -16,8 +16,7 @@ from game_api import game
 app = Flask(__name__)
 CORS(app)
 
-app.config["GOOGLE_API_KEY"] = os.environ["GOOGLE_API_KEY"]
-app.config["SQLALCHEMY_DATABASE_URI"] = os.environ["DATABASE_URI"]
+app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("DATABASE_URI", "sqlite:////tmp/terrassumptions.db")
 app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
 
 app.register_blueprint(game, url_prefix="/game")
@@ -34,13 +33,5 @@ def version():
     return jsonify({"version": "1", "status": "healthy"})
 
 
-@app.route("/googleApiKey")
-def google_api_key():
-    """
-    Return the google API key configured for the application
-    """
-    return jsonify({"googleApiKey": app.config["GOOGLE_API_KEY"]})
-
-
 if __name__ == "__main__":
     app.run("0.0.0.0", 5000, debug=True)

+ 3 - 4
server/game_api.py

@@ -1,7 +1,7 @@
 from functools import wraps
 import uuid
 
-from flask import Blueprint, abort, request, current_app, jsonify
+from flask import Blueprint, abort, request, jsonify
 
 from db import db, Game, CoordSet, GuessSet
 from lib import generate_coord, score
@@ -43,13 +43,12 @@ def create_game():
         # basically impossible collision, but let's be safe
         game_id = str(uuid.uuid4())
 
-    key = current_app.config["GOOGLE_API_KEY"]
     cs = CoordSet()
     for round_num in "12345":
-        coord = generate_coord(key)
+        coord = generate_coord()
         while coord is None:
             # very unlikely, but it is possible for generate_coord to fail
-            coord = generate_coord(key)
+            coord = generate_coord()
         cs.set_coord(round_num, *coord)
     db.session.add(cs)
     db.session.commit()

+ 4 - 3
server/lib.py

@@ -4,13 +4,14 @@ import math
 import requests
 import haversine
 
+# Google API key, with access to Street View Static API
+google_api_key = "AIzaSyAqjCYR6Szph0X0H_iD6O1HenFhL9jySOo"
 metadata_url = "https://maps.googleapis.com/maps/api/streetview/metadata"
 mapcrunch_url = "http://www.mapcrunch.com/_r/"
 
 
-def generate_coord(key):
+def generate_coord():
     """
-    Takes in a Google API key.
     Returns (latitude, longitude) of usable coord (where google has data).
     Returns None if, after trying several random points, no usable coords could be found.
 
@@ -21,7 +22,7 @@ def generate_coord(key):
 
     for lat, lng in points_js["points"]:
         params = {
-            "key": key,
+            "key": google_api_key,
             "location": f"{lat},{lng}",
         }
         js = requests.get(metadata_url, params=params).json()