Add basic api for entity_ident
This commit is contained in:
parent
acafa000e8
commit
b856819a25
@ -1,31 +1,37 @@
|
|||||||
import jsonify as jsonify
|
from bson import json_util
|
||||||
from flask import Flask
|
from flask import Flask, request
|
||||||
from flask_pymongo import PyMongo
|
from flask_pymongo import PyMongo
|
||||||
|
|
||||||
# make sure mongoDB (container) is running and accessible
|
|
||||||
|
|
||||||
# see https://flask-pymongo.readthedocs.io/en/latest/
|
|
||||||
from pymongo import MongoClient
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config["MONGO_URI"] = "mongodb://mongo:27017/entities"
|
app.config["MONGO_URI"] = "mongodb://mongo:27017/entities"
|
||||||
mongo = PyMongo(app)
|
mongo = PyMongo(app)
|
||||||
|
|
||||||
@app.route("/")
|
|
||||||
def index():
|
|
||||||
test_results = mongo.db.cars.find()
|
|
||||||
results = []
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
result = test_results.next()
|
|
||||||
results.append(result)
|
|
||||||
except StopIteration:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return str(results)
|
@app.route('/api/v1/resources/cars', methods=['GET'])
|
||||||
|
def get_cars():
|
||||||
|
query_parameters = request.args
|
||||||
|
vin = query_parameters.get('vin')
|
||||||
|
|
||||||
|
if vin is not None:
|
||||||
|
cars = [car for car in mongo.db.cars.find({'vin': vin})]
|
||||||
|
else:
|
||||||
|
cars = [car for car in mongo.db.cars.find({})]
|
||||||
|
|
||||||
|
return json_util.dumps({'cursor': cars})
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/api/v1/resources/traffic_lights', methods=['GET'])
|
||||||
|
def get_traffic_lights():
|
||||||
|
query_parameters = request.args
|
||||||
|
tl_id = query_parameters.get('id')
|
||||||
|
|
||||||
|
if tl_id is not None:
|
||||||
|
traffic_lights = [traffic_light for traffic_light in mongo.db.trafficLights.find({'id': tl_id})]
|
||||||
|
else:
|
||||||
|
traffic_lights = [traffic_light for traffic_light in mongo.db.trafficLights.find({})]
|
||||||
|
|
||||||
|
return json_util.dumps({'cursor': traffic_lights})
|
||||||
|
|
||||||
#if __name__ == '__main__':
|
|
||||||
# app.run()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0')
|
app.run(host='0.0.0.0')
|
||||||
|
|||||||
@ -12,6 +12,6 @@
|
|||||||
{
|
{
|
||||||
"oem": "SATURN",
|
"oem": "SATURN",
|
||||||
"modelType": "Vue2",
|
"modelType": "Vue2",
|
||||||
"vin": "5GZCZ43D13S812715"
|
"vin": "5GZCZ43D13S812716"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -3,13 +3,15 @@ kind: Ingress
|
|||||||
metadata:
|
metadata:
|
||||||
name: minimal-ingress
|
name: minimal-ingress
|
||||||
annotations:
|
annotations:
|
||||||
nginx.ingress.kubernetes.io/rewrite-target: /
|
kubernetes.io/ingress.class: "nginx"
|
||||||
|
nginx.ingress.kubernetes.io/add-base-url: "true"
|
||||||
|
nginx.ingress.kubernetes.io/rewrite-target: /$1
|
||||||
|
nginx.ingress.kubernetes.io/service-upstream: "true"
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- http:
|
- http:
|
||||||
paths:
|
paths:
|
||||||
- path: /testpath
|
- path: /entity-ident/(.+)
|
||||||
pathType: Prefix
|
|
||||||
backend:
|
backend:
|
||||||
serviceName: entity-ident
|
serviceName: entity-ident
|
||||||
servicePort: 5000
|
servicePort: 5000
|
||||||
Loading…
x
Reference in New Issue
Block a user