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/
 dist/
 node_modules/
 node_modules/
 
 
-secrets.sh
-
 ggsh.tgz
 ggsh.tgz

+ 0 - 5
README.md

@@ -15,10 +15,6 @@ GET /
         "version": string,
         "version": string,
         "status": string
         "status": string
     }
     }
-GET /googleApiKey
-    Returns {
-        "googleApiKey": string
-    }
 PUT /game
 PUT /game
     Header Authorization: Name string
     Header Authorization: Name string
     Accepts {
     Accepts {
@@ -99,6 +95,5 @@ POST /game/{ID}/guesses/{round}
 - Re-join a game you did not finish
 - Re-join a game you did not finish
 - Show current best on round summary
 - Show current best on round summary
 - Round summary should use dynamic map
 - Round summary should use dynamic map
-- Cache API key after first call to back-end
 - Styling and layout improvements
 - Styling and layout improvements
 - Optimize docker file or set up compose structure
 - 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__)
 app = Flask(__name__)
 CORS(app)
 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.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
 
 
 app.register_blueprint(game, url_prefix="/game")
 app.register_blueprint(game, url_prefix="/game")
@@ -34,13 +33,5 @@ def version():
     return jsonify({"version": "1", "status": "healthy"})
     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__":
 if __name__ == "__main__":
     app.run("0.0.0.0", 5000, debug=True)
     app.run("0.0.0.0", 5000, debug=True)

+ 3 - 4
server/game_api.py

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

+ 4 - 3
server/lib.py

@@ -4,13 +4,14 @@ import math
 import requests
 import requests
 import haversine
 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"
 metadata_url = "https://maps.googleapis.com/maps/api/streetview/metadata"
 mapcrunch_url = "http://www.mapcrunch.com/_r/"
 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 (latitude, longitude) of usable coord (where google has data).
     Returns None if, after trying several random points, no usable coords could be found.
     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"]:
     for lat, lng in points_js["points"]:
         params = {
         params = {
-            "key": key,
+            "key": google_api_key,
             "location": f"{lat},{lng}",
             "location": f"{lat},{lng}",
         }
         }
         js = requests.get(metadata_url, params=params).json()
         js = requests.get(metadata_url, params=params).json()