Skip to content

Commit

Permalink
add new function
Browse files Browse the repository at this point in the history
  • Loading branch information
DevSecOps Workshop committed Jun 25, 2024
1 parent 8a1c9c4 commit 11f9a41
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions service.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,15 @@ def index():
# Bind to localhost for development purposes and attach to the address 127.0.0.1
# Replace with the following:
app.run(host="127.0.0.1")

@app.route("/api/product/hash", methods=["GET"])
def getProductHash():
import hashlib
products = db.get_products(db_connection, 100, 0)
product_id = int(request.args.get('pid', 0))
if product_id == 0:
return "error, specify a product id", 500
if product_id > len(products):
return "invalid product id", 500
hash = hashlib.md5(products[product_id].name.encode('utf-8')).hexdigest()
return hash

0 comments on commit 11f9a41

Please sign in to comment.