From 479f1f35834a479d26b47e975b7b465ef0e6dc1a Mon Sep 17 00:00:00 2001 From: Kristian-Knudsen Date: Wed, 29 Nov 2023 17:05:11 +0100 Subject: [PATCH 1/4] Minor updates in functionality --- .github/workflows/pipeline.yml | 17 +++- .gitignore | 51 ++++++++++- README.md | 13 ++- dev-docker-compose.yml | 4 +- prod-docker-compose.yml | 4 +- setup.cfg | 15 ++++ setup.py | 4 + src/__pycache__/app.cpython-310.pyc | Bin 0 -> 4218 bytes src/app.py | 132 ++++++++++++++++------------ 9 files changed, 167 insertions(+), 73 deletions(-) create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 src/__pycache__/app.cpython-310.pyc diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index fab05db..197e747 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -1,4 +1,4 @@ -name: Linting Pipeline +name: General Pipeline on: pull_request: @@ -7,7 +7,7 @@ on: jobs: linter: - name: PyLint check + name: Lint runs-on: ubuntu-latest steps: - name: linter checkout @@ -15,4 +15,15 @@ jobs: with: fetch-depth: 0 - run: pip install -r requirements.txt - - run: pylint ./**/*.py \ No newline at end of file + - run: pylint ./**/*.py + + testing: + name: Unit test + runs-on: ubuntu-latest + steps: + - name: checkout and testing + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - run: pip install -r requirements.txt + - run: "python3 -m unittest discover -s src -p 'test_*.py'" diff --git a/.gitignore b/.gitignore index b694934..7fd4608 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,50 @@ -.venv \ No newline at end of file +# Created by https://www.toptal.com/developers/gitignore/api/python,flask,git +# Edit at https://www.toptal.com/developers/gitignore?templates=python,flask,git + +### Flask ### +instance/* +!instance/.gitignore +.webassets-cache +.env + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# Flask stuff: +instance/ + +# Environments +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +### Git ### +*.orig +*.BACKUP.* +*.BASE.* +*.LOCAL.* +*.REMOTE.* +*_BACKUP_*.txt +*_BASE_*.txt +*_LOCAL_*.txt +*_REMOTE_*.txt diff --git a/README.md b/README.md index 4040a3d..fcebeed 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,15 @@ docker-compose -f dev-docker-compose.yml up 4. Access the api at the specified host and port (if not changed: http://localhost:5000/) ## Documentation -Use postman and import the documentation from the file "P5-Metadata-api.postman_collection.json" +Use Postman and import the documentation from the file "P5-Metadata-api.postman_collection.json" ## To make changes 1) Clone the repository from [here](https://github.com/Knox-AAU/Metadata-api) 2) Make the changes you want to make -3) Push them into a branch -4) Make a pull request -5) Ensure pipelines pass +3) Update the api documentation +4) Push them into a branch +5) Make a pull request +6) Ensure pipelines pass ## To use linter ```bash @@ -29,6 +30,4 @@ pylint ./**/*.py ``` ## TODO -- Remove testing functions -- Remove testing functions from documentation -- Update the functionality such that if a triple already exists in the database, then ignore the triple and store the metadata in the JSON object in the database connected to that triple +See: https://github.com/orgs/Knox-AAU/projects/26/ \ No newline at end of file diff --git a/dev-docker-compose.yml b/dev-docker-compose.yml index 3e01c5a..6c6858d 100644 --- a/dev-docker-compose.yml +++ b/dev-docker-compose.yml @@ -5,8 +5,8 @@ services: image: python:3.9 container_name: metadataapi_api environment: - - PYTHON_ENV=development - - DATABASE_URI='postgresql://myuser:mypassword@metadataapi_database:5432/mydatabase' + PYTHON_ENV: development + DATABASE_URI: postgresql://myuser:mypassword@metadataapi_database:5432/mydatabase command: sh -c "pip install -r /app/requirements.txt && python /app/src/app.py" volumes: - .:/app diff --git a/prod-docker-compose.yml b/prod-docker-compose.yml index bb8f5b6..58760f0 100644 --- a/prod-docker-compose.yml +++ b/prod-docker-compose.yml @@ -5,8 +5,8 @@ services: image: python:3.9 container_name: metadataapi_api environment: - - PYTHON_ENV=production - - DATABASE_URI='postgresql://myuser:mypassword@metadataapi_database:5432/mydatabase' + PYTHON_ENV: production + DATABASE_URI: postgresql://myuser:mypassword@metadataapi_database:5432/mydatabase command: sh -c "pip install -r /app/requirements.txt && python -u /app/src/app.py" volumes: - .:/app diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..10e2bc4 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,15 @@ +[metadata] +name=MetadataApi + +[options] +package_dir= + =src +packages = find: +zip_safe = False +python_requires = >= 3 + +[options.packages.find] +where = src +exlude = + test* + .gitignore \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..a405585 --- /dev/null +++ b/setup.py @@ -0,0 +1,4 @@ +# pylint: skip-file + +from setuptools import setup +setup() \ No newline at end of file diff --git a/src/__pycache__/app.cpython-310.pyc b/src/__pycache__/app.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c2e31f10ee0bc446fe6d5d38866b5b971ca62f26 GIT binary patch literal 4218 zcmb7H-ESMm5#QbW z^shS8d&|Ee@{osl7`7u{B)JTehVVC{Solw2TV%CLmDTA){6f`G*0ngywv{8r{f@|T zc?260L3n$Bixv8ZP_{_+`&PEzT|y zZs?YIk>qxt?9s2;$K)%vLAk~4M=rPbS<~4wz9vJh!(Gt2LoLiQa1Y2|%arW1LFs@{ za+mOuNldZ_M^4=LNcP(uNKFuqel+Qe7U*Xz}&+<1O zxzNjoy>sJU3jGE@!B6Ub+`GrWGaik-jL-8^y4UQJHBw#Z`TkuQw%bDb8=a()M`_}3 zq|yhK-vHNUzA9f`t}S0)URw$7+`g_(p;te<^2y4Ld%@9;YwGNgp4#o@E58eF+`M}I z+Vv~Twd*%m*CyTpcpcnOT-gP<3j!b`b;fDk_=YsiZ^!`N0Qkb-=3`d33tiJe&%?9J z9oW6wJJXON%tZj(J%2Gy8)2M%bbf@N-uxI!ejcs^ep)FPvH$cPSg`hls;Rb&TA}O) z+oF375aTADI7Y+OYDu|4kc2G}1j-8n7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4eQcd4rn#5T^liu!Lkmrzsa^Y_4S7P}HHFII0zm0CS)?I@ zd18W4FC`5~6yfWp35@tlKE!AU`0tK^kF>+9cvY{%uwn!zILuj4Q$sd^CWsxVHKHUF z66p@@VHN5_6*^wG0Oy!>5^H4nJ_@YmAm(e7WB)ke%pM`jPtXz>BY%nFLlnP4v4lb= zE1W>tSo$YizKiOgq0mJPaz<7`R2@y6BfI%EXw@7#E6~v<*pO)p*rYtnOU0ozpJ0#2 zQOU!kQkeY_rpnHNU|x}x7Jy79(5Xz>mlXpu)EuiA!whw78G1Mw#0mqZ(xs+iDHLWR z`67~OBGDI^Uz3e!Q`-1o-N5evH3f$cK%a{Tx$;H{FpiZaQ;0E;dkwIVxI_616u&{S zj6&zxi`Xja($U~{8wsor<+3@$qpmS;%v+xA(KF9o)1wu0mR1(#Xywc-HP6XU!5Y6b zT49s~LC^X5dHomdLsh4|TlZ?8+*}P-R)4REn&RRM5vT1Id=kTluep`N=dRgKWv(nP z);pWk*`lz%jN8($SQi`C27VzI&cTYLC^2TWHpuSBVeyHqJ)`$ixX_TDL|#FA?LR9{ kcZ58)x^*uWUq>HdX2`ItH;GHj@KsW#E^{BgL(S*^10nzr#Q*>R literal 0 HcmV?d00001 diff --git a/src/app.py b/src/app.py index dff33ad..fcdd954 100644 --- a/src/app.py +++ b/src/app.py @@ -1,7 +1,11 @@ """ Metadataapi entrance file """ import os +import sys +import json +from uuid import uuid4 from flask import Flask, request, jsonify from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.orm.attributes import flag_modified app = Flask(__name__) @@ -15,12 +19,12 @@ # Define a simple model class Metadata(db.Model): """ Metadata table model """ - uuid = db.Column(db.String(40), primary_key=True) + uuid = db.Column(db.String(36), primary_key=True) mdata = db.Column(db.JSON, nullable=False) # mdata because metadata is reserved in declarative flask apis class TripleUUID(db.Model): """ Triple UUID model """ - uuid = db.Column(db.String(40)) + uuids = db.Column(db.ARRAY(db.String(36))) triple = db.Column(db.String(2000), primary_key=True) # Create tables @@ -31,15 +35,21 @@ class TripleUUID(db.Model): @app.route('/') def index(): """ Acts as a health check """ - return jsonify({ "success": True, "message": os.environ['PYTHON_ENV']}) - -@app.route('/binduuid', methods=['POST']) -def binduuid(): - """ Method to take in a UUID and metadata and bind it together in a database """ + return jsonify({ "success": True, "message": "Metadata api is healthy" }) + +@app.route('/metadata', methods=['POST']) +def add_metadata(): + """ + @description: Method to take in metadata and bind it together with a UUID in the database + @body: { + metadata: object + } + @returns: uuid matching the metadata + """ try: data = request.get_json() - uuid = data.get('uuid') + uuid = str(uuid4()) metadata = data.get('metadata') new_metadata = Metadata(uuid=uuid, mdata=metadata) @@ -47,81 +57,87 @@ def binduuid(): db.session.add(new_metadata) db.session.commit() - return jsonify({'success': True, 'message': f'Saved metadata to database under UUID {uuid}'}) + return jsonify({ 'success': True, 'message': uuid }) except Exception as e: - return jsonify({'success': False, 'message': str(e)}) + return jsonify({ 'success': False, 'message': str(e) }) -@app.route('/bindtriple', methods=['POST']) -def bindtriple(): - """ Method to take in a UUID and a triple and bind it together in a database """ +@app.route('/metadata', methods=['GET']) +def get_metadata(): + """ + @description Method to take in a triple and return the metadata connected to this triple + @body: { + triple: array + } + @returns: metadata connected to specified triple + """ try: data = request.get_json() - uuid = data.get('uuid') - triple = data.get('triple') + triple_as_pk = data['triple'][0] + data['triple'][1] + data['triple'][2] - triple_as_pk = triple[0] + triple[1] + triple[2] + uuid = db.session.execute(db.select(TripleUUID).filter_by(triple=triple_as_pk)).scalar() - new_triple = TripleUUID(uuid=uuid, triple=triple_as_pk) + if uuid.uuids: + metadata = Metadata.query.filter(Metadata.uuid.in_(uuid.uuids)).all() - db.session.add(new_triple) - db.session.commit() + if metadata: + res = [] - return jsonify({'success': True, 'message': f'Saved data to database under triple {triple_as_pk}'}) + for data in metadata: + res.append(data.mdata[0]) + return jsonify({'success': True, 'message': res }) - except Exception as e: - return jsonify({'success': False, 'message': str(e)}) + return jsonify({'success': False, 'message': f'No metadata found connected to UUID: {uuid.uuids}'}) -@app.route('/getMetadata') -def get_metadata(): - """ Method to take in a triple and return the metadata connected to this triple""" + return jsonify({'success': False, 'message': f'No UUID found connected to Triple: {triple_as_pk}'}) + + except Exception as e: + return jsonify({'success': False, 'message': str(e) }) + +@app.route('/triple', methods=['POST']) +def add_triple(): + """ + @description Method to take in a UUID and a triple and bind it together in a database + @body: { + uuid: string, + triple: array + } + @returns: triple in the format that was inserted as primary key + """ try: data = request.get_json() - triple_as_pk = data['triple'][0] + data['triple'][1] + data['triple'][2] - - uuid = db.session.execute(db.select(TripleUUID).filter_by(triple=triple_as_pk)).scalar() + uuid = data.get('uuid') + triple = data.get('triple') - if uuid.uuid: - metadata = db.session.execute(db.select(Metadata).filter_by(uuid=uuid.uuid)).scalar() + triple_as_pk = triple[0] + triple[1] + triple[2] - if metadata.mdata: - return jsonify({'success': True, 'message': metadata.mdata}) + uuid_array_from_pk = db.session.execute(db.select(TripleUUID).filter_by(triple=triple_as_pk)).scalar() - return jsonify({'success': False, 'message': f'No metadata found connected to UUID: {uuid.uuid}'}) + if uuid_array_from_pk: + # Add UUID to array of UUIDS + if uuid_array_from_pk.uuids: + if uuid in uuid_array_from_pk.uuids: + # If UUID is already in array of UUIDS + return jsonify({ 'success': False, 'message': f"UUID: {uuid} already exists!" }) - return jsonify({'success': False, 'message': f'No UUID found connected to Triple: {triple_as_pk}'}) + uuid_array_from_pk.uuids.append(uuid) + flag_modified(uuid_array_from_pk, 'uuids') - except Exception as e: - return jsonify({'success': False, 'message': e}) + else: + # Create new triple instance + new_triple = TripleUUID(uuids=[uuid], triple=triple_as_pk) + db.session.add(new_triple) -# TESTING ROUTES - REMOVE WHEN STABLE # -@app.route('/getuuids') -def getuuids(): - """ Testing function to get all uuids in the database - should be removed """ - try: - mdata = Metadata.query.all() - uuid_list = [{'uuid': d.uuid, 'metadata': d.mdata} for d in mdata] + db.session.commit() - return {'success': True, 'message': uuid_list} + return jsonify({ 'success': True, 'message': triple_as_pk }) except Exception as e: - return jsonify({'success': False, 'message': str(e)}) - -@app.route('/gettriples') -def gettriples(): - """ Testing function to get all triples in the database - should be removed """ - try: + return jsonify({ 'success': False, 'message': str(e) }) - triples = TripleUUID.query.all() - triples_list = [{'uuid': d.uuid, 'triple': d.triple} for d in triples] - - return {'success': True, 'message': triples_list} - - except Exception as e: - return jsonify({'success': False, 'message': str(e)}) if __name__ == '__main__': - app.run(host='0.0.0.0', port=5000, debug=os.environ.get('PYTHON_ENV', '').lower() == 'true') + app.run(host='0.0.0.0', port=5000, debug=os.environ.get('PYTHON_ENV', '').lower() == 'development') From 5fbfe72021219e22cc51bf930186c4b81c135c9b Mon Sep 17 00:00:00 2001 From: Kristian-Knudsen Date: Wed, 29 Nov 2023 17:06:22 +0100 Subject: [PATCH 2/4] minor tweaks --- setup.cfg | 15 --------------- setup.py | 4 ---- src/__pycache__/app.cpython-310.pyc | Bin 4218 -> 0 bytes src/app.py | 2 -- 4 files changed, 21 deletions(-) delete mode 100644 setup.cfg delete mode 100644 setup.py delete mode 100644 src/__pycache__/app.cpython-310.pyc diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 10e2bc4..0000000 --- a/setup.cfg +++ /dev/null @@ -1,15 +0,0 @@ -[metadata] -name=MetadataApi - -[options] -package_dir= - =src -packages = find: -zip_safe = False -python_requires = >= 3 - -[options.packages.find] -where = src -exlude = - test* - .gitignore \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index a405585..0000000 --- a/setup.py +++ /dev/null @@ -1,4 +0,0 @@ -# pylint: skip-file - -from setuptools import setup -setup() \ No newline at end of file diff --git a/src/__pycache__/app.cpython-310.pyc b/src/__pycache__/app.cpython-310.pyc deleted file mode 100644 index c2e31f10ee0bc446fe6d5d38866b5b971ca62f26..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4218 zcmb7H-ESMm5#QbW z^shS8d&|Ee@{osl7`7u{B)JTehVVC{Solw2TV%CLmDTA){6f`G*0ngywv{8r{f@|T zc?260L3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KsW#E^{BgL(S*^10nzr#Q*>R diff --git a/src/app.py b/src/app.py index fcdd954..ced5ca8 100644 --- a/src/app.py +++ b/src/app.py @@ -1,7 +1,5 @@ """ Metadataapi entrance file """ import os -import sys -import json from uuid import uuid4 from flask import Flask, request, jsonify from flask_sqlalchemy import SQLAlchemy From e801e3eb4837344d386ee18a816eadb1b25ad6ec Mon Sep 17 00:00:00 2001 From: Kristian-Knudsen Date: Wed, 29 Nov 2023 17:07:27 +0100 Subject: [PATCH 3/4] removed unittesting pipeline --- .github/workflows/pipeline.yml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 197e747..d136499 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -15,15 +15,4 @@ jobs: with: fetch-depth: 0 - run: pip install -r requirements.txt - - run: pylint ./**/*.py - - testing: - name: Unit test - runs-on: ubuntu-latest - steps: - - name: checkout and testing - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - run: pip install -r requirements.txt - - run: "python3 -m unittest discover -s src -p 'test_*.py'" + - run: pylint ./**/*.py \ No newline at end of file From b8e666fe179e71925afeb994d3dd1fc77ef45cb0 Mon Sep 17 00:00:00 2001 From: Kristian-Knudsen Date: Wed, 29 Nov 2023 17:34:01 +0100 Subject: [PATCH 4/4] tweaks and more fixes --- P5-Metadata-api.postman_collection.json | 56 ++++--------------------- src/app.py | 2 +- 2 files changed, 10 insertions(+), 48 deletions(-) diff --git a/P5-Metadata-api.postman_collection.json b/P5-Metadata-api.postman_collection.json index 510c6bd..ed20a80 100644 --- a/P5-Metadata-api.postman_collection.json +++ b/P5-Metadata-api.postman_collection.json @@ -1,7 +1,7 @@ { "info": { "_postman_id": "7085b715-1a0f-41de-ba42-0d41bc8c2377", - "name": "P5-Metadata api", + "name": "P5-Metadata-api", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, "item": [ @@ -31,7 +31,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"uuid\": \"{{$guid}}\",\r\n \"metadata\": [\r\n { \"author\": \"John Snut\", \"pages\": 420 }\r\n ]\r\n}", + "raw": "{\r\n \"metadata\":\r\n { \r\n \"author\": \"Other Test Author\", \r\n \"pages\": 69\r\n }\r\n}", "options": { "raw": { "language": "json" @@ -39,52 +39,14 @@ } }, "url": { - "raw": "http://localhost:5000/binduuid", + "raw": "http://localhost:5000/metadata", "protocol": "http", "host": [ "localhost" ], "port": "5000", "path": [ - "binduuid" - ] - } - }, - "response": [] - }, - { - "name": "TESTING_Get uuids", - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "http://localhost:5000/getuuids", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "5000", - "path": [ - "getuuids" - ] - } - }, - "response": [] - }, - { - "name": "TESTING_Get triples", - "request": { - "method": "GET", - "header": [], - "url": { - "raw": "http://localhost:5000/gettriples", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "5000", - "path": [ - "gettriples" + "metadata" ] } }, @@ -97,7 +59,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"uuid\": \"b3d47bdd-5190-4c43-892c-dab379a72ebc\",\r\n \"triple\": [\r\n \"knox-kb01.srv.aau.dk/Barack_Obama\", \r\n \"http://dbpedia.org/ontology/spouse\", \r\n \"knox-kb01.srv.aau.dk/Michelle_Obama\"\r\n ]\r\n}", + "raw": "{\r\n \"uuid\": \"b7d29cec-89e0-44b3-988f-960496374ba5\",\r\n \"triple\": [\r\n \"knox-kb01.srv.aau.dk/Barack_Obama\", \r\n \"http://dbpedia.org/ontology/spouse\", \r\n \"knox-kb01.srv.aau.dk/Michelle_Obama\"\r\n ]\r\n}", "options": { "raw": { "language": "json" @@ -105,14 +67,14 @@ } }, "url": { - "raw": "http://localhost:5000/bindtriple", + "raw": "http://localhost:5000/triple", "protocol": "http", "host": [ "localhost" ], "port": "5000", "path": [ - "bindtriple" + "triple" ] } }, @@ -136,14 +98,14 @@ } }, "url": { - "raw": "http://localhost:5000/getMetadata", + "raw": "http://localhost:5000/metadata", "protocol": "http", "host": [ "localhost" ], "port": "5000", "path": [ - "getMetadata" + "metadata" ] } }, diff --git a/src/app.py b/src/app.py index ced5ca8..863a3f4 100644 --- a/src/app.py +++ b/src/app.py @@ -83,7 +83,7 @@ def get_metadata(): res = [] for data in metadata: - res.append(data.mdata[0]) + res.append(data.mdata) return jsonify({'success': True, 'message': res })