MP6
Web service around MP2
Due dates may be found on the schedule.

MP 2 had you implement part of the PNG specification and hide arbitrary payloads inside a special uiuc chunk of them. This MP has you wrap that MP in a web microservice so that it can be run by visiting a website rather than by having the source code on hand.

1 Initial Files

In your CS 340 directory, merge the initial starting files with the following commands:

git fetch release
git merge release/mp6 --allow-unrelated-histories -m "Merging initial files"

2 Part 1: Flask Implementation

2.1 Machine Problem

Complete the app.py program using the Python flask library to create a web-based service that has two different routes.

2.1.1 Extract Hidden GIF, POST /extract

Complete the POST /extract route to extract and return a hidden GIF.

  • If the PNG file has a hidden GIF image (as defined by mp2), the hidden GIF file is returned.
  • If the PNG file does not have a hidden GIF image (as reported by MP2’s return code), the response use be an HTTP 415 Unsupported Media Type status along with some useful text for the end-user.
  • If the PNG file is not a valid PNG file (as reported by MP2’s return code), the response must use an HTTP 422 Unprocessable Content status along with some useful text for the end-user.

2.1.2 Retrieve Previously Extracted GIF, GET /extract/<image_num>

Return a previously extracted hidden GIF, based on the image_num index.

  • If the <image_num>th GIF exists in your local cache, the <image_num>th hidden GIF file is returned.
  • If the flask program has not received <image_num> GIFs, a HTTP 404: Not Found response must be returned.
  • The <image_num> cache must save the first extracted image as index 0.

This assumes that you have a local cache, a list of successful returns from POST /extract. For consistency during testing, this should be an in-memory (not on-disk) cache.

2.2 Using Your MP2

As part of the POST /extract route, you will need to use your mp2 png-extractGIF program. You may want to verify that your png-extractGIF program is complete and functional and that you can run the following commands:

Additionally, you should verify your MP2 solution returns unique values for main for the different features you need to identify in Python:

You may need to modify your MP2 program slightly to fix any bugs to ensure your program can work with your new microservice.

If you didn’t do MP2 or its not readily fixable, we include just enough of a solution for this use case in the png-extractGIF-minimal.c including in the MP 6 starter files. If you overwrite MP 2’s png-extractGIF.c with this file it won’t pass all of MP2’s tests, but it does enough to pass this MP’s tests.

2.3 Useful Python Functions

There will be a few tasks you will need to complete in Python:

2.4 Manually Testing Your Microservice

Launch your service by starting your flask application:

python3 -m flask run

Then, you can test your program in two different ways:

  1. By using your web browser and visiting your flask server (ex: http://127.0.0.1:5000/).

  2. By the command line, using curl to make a request to your web server: curl -f -o output.gif http://localhost:5000/extract -F "png=@sample/luther.png"

    • You can replace @sample/luther.png with another file. Ensure that you keep the @ symbol to tell curl to send the contents of the file, not just the file name.
    • You should inspect output.gif to ensure the extraction was successful.
    • Make sure that you get an error when sending it an invalid PNG file.
    • Make sure you also get an error when sending it a PNG file without a hidden uiuc chunk.

2.5 Pytest Test Suite

A pytest suite is provided for you.

To run only the Part 1 test cases, run:

python3 -m pytest test_flask.py

3 Part 2: Deploying your MicroService

You have a Virtual Machine (VM) provided for you as part of being in CS 340. If you have not done so already, learn more about your VM on our VM page.

You might need to install additional libraries to get your VM fully set up. For systems packages you can use something like sudo apt-get install gcc. For python libraries, you can use something like python3 -mpip install requests. A list of python packages you might need for this MP is included in the requirements.txt file.

3.1 Identifying your VM

We identify your VM for testing by the NETID.txt file.

3.2 Deployment Requirements

At the time you run your GitHub Action for grading, you server must be running on your VM using port 5000 (the default flask port). Additionally, your service must be accessible to other machines than just localhost.

4 Submission

Once you have locally passed all the tests, you will need to submit and grade your code. First commit using the standard git commands:

git add -A
git commit -m "MP submission"
git push

4.1 Grading

The initial grading is done via a manual GitHub Action. You MUST complete this step before the deadline to earn any points for the MP:

4.2 Points

Points are allocated according to the GitHub Action score.