{"id":22957529,"url":"https://github.com/tca166/cdp","last_synced_at":"2025-04-02T01:45:19.755Z","repository":{"id":163578339,"uuid":"630436868","full_name":"TCA166/cdp","owner":"TCA166","description":"A demo game store API","archived":false,"fork":false,"pushed_at":"2023-05-10T16:59:27.000Z","size":12953,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-07T16:43:33.708Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TCA166.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-20T11:30:53.000Z","updated_at":"2023-04-25T09:14:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"22ce39b0-3650-406a-bcea-92750bcc15d5","html_url":"https://github.com/TCA166/cdp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TCA166%2Fcdp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TCA166%2Fcdp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TCA166%2Fcdp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TCA166%2Fcdp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TCA166","download_url":"https://codeload.github.com/TCA166/cdp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246741191,"owners_count":20826063,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-14T17:17:39.401Z","updated_at":"2025-04-02T01:45:19.747Z","avatar_url":"https://github.com/TCA166.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Game Store API\n\nA demo backend API for an online game store.\n\n## API Endpoints\n\n1. GET /games\n    Returns all games in the database in the JSON format.\n    Arguments:\n    - name:str\n        A string that each result's name must contain\n    - studio:str\n        A string that each result's studio must contain\n    - date:str(10)\n        A string that each result's release date must contain\n\n2. POST /games\n    Returns all owned games by the user associated with the provided key.\n    Arguments:\n    - key:str\n        Key used for authentication\n\n3. POST /games/delete\n    Deletes a game entry from the database with the provided uid.\n    Arguments:\n    - key:str (with admin privileges)\n    - uid:int\n        Id of game to be deleted\n\n4. POST /games/add\n    Adds a new game entry to the database with the attributes in arguments.\n    Arguments:\n    - key:str (with admin privileges)\n    - name:str\n    - date:str\n    - studio:str\n\n5. POST /games/update\n    Updates a single game entry attribute.\n    - key:str (with admin privileges)\n    - uid:int\n    - attr:str\n        Attribute key to be updated.\n    - val:str\n        Value to update the attribute with.\n\n6. POST /key/valid\n    Returns if the key in POST arguments is valid.\n    Arguments:\n    - key:str\n\n7. POST /key/valid/admin\n    Returns if the key in POST arguments is valid and admin capable.  \n\n8. POST /key/register\n    Registers the user and makes him eligible to receive keys.\n    Arguments:\n    - login:str\n        A user login that will be later used for verification during key issuing.\n    - pass:str\n        A user password used in tandem with login.\n\n9. POST /key/get\n    Issues a new key for the user, with a permission level fitting their user permission level.\n    Arguments:\n    - login:str\n    - pass:str\n    - expiry:str\n        Either \"auto\" meaning tomorrow, a date formatted in \"YYYY-MM-DD\" or not provided (null) meaning never.\n        Perpetual keys may only be issued by admins.\n\n## Authentication\n\nAuthentication is not necessary for all GET endpoints, and is provided in POST requests via the use of a key attribute in all requests.\nThe exception to that are the /key/register and /key/get endpoints that are used in key issue process.\nThis system ensures the backend can verify user identity without exposing any of their credentials, while also allowing access to automated clients and having two levels of authority over served content.\nWhat's more this system has a built in key expiry that may only be turned off for keys generated by admins.\nA frontend client can easily initialize secure data exchange by obtaining a one day valid key via the get endpoint and then use that key in all endpoints requiring authentication.\n\n### Example interaction flow\n\n1. Client registers to be eligible to receive authentication keys using POST /key/register\n2. Client requests a new key using POST /key/get\n3. Client verifies the capabilities of the key using POST /key/verify and POST /key/verify/admin\n4. Client uses the key to authenticate himself and perform actions like POST /games\n5. After a set amount of time the key expires, and needs to reissued.\n\nExtremely high quality diagram of the above:  \n![Interaction diagram](graphUser.png \"Interaction diagram\")\n\n### Permanent keys and admin users\n\nAdmin users are indicated in the database by a single field, and keys issued to them are marked accordingly.\nThese users cannot be registered using the API, and need to be manually created.\nKeys issued to admin users hold admin privileges, and grant access to admin endpoints.\nAlso admins may request keys that don't expire, for automated clients.\n\n## Database\n\nDue to it's relative simplicity and my experience with it I chose sqlite as the engine to power the database.\nIt removes a lot of the unnecessary data types from SQL while keeping all the necessary features.  \n![Database diagram](db.png \"Database diagram\")\n\n## Example commands for testing\n\n```Bash\ncurl -X GET localhost:8080/games\n#outputs json contents of table games\ncurl -d \"key=4shrg654ccI=\" -X POST localhost:8080/key/valid\n#true\ncurl -d \"key=4shrg654ccI=\" -X POST localhost:8080/key/valid/admin\n#false\ncurl -d \"key=test\" -X POST localhost:8080/key/valid/admin\n#true\ncurl -d \"key=4shrg654ccI=\" -X POST localhost:8080/games\n#[{\"date\":\"1993-12-10\",\"studio\":\"ID\",\"name\":\"Doom\"}]\ncurl -d \"login=test\u0026pass=1234\u0026expiry=auto\" -X POST localhost:8080/key/get\n#json with key and expiry\n```\n\n## Notes\n\n- I had trouble with Java setup, thus two jar files are bundled.\n- The games table has very little columns, but that's not important and can be easily changed.\n- This was ultimetely rejected. It was noted however that I could have improved this project using a REST approach(guess using the Quarkus rest client wasn't RESTful enough) and I shouldn't have developed my own authorisation system and used a premade one\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftca166%2Fcdp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftca166%2Fcdp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftca166%2Fcdp/lists"}