This is designed to used the basic venv that flask recommends.
pip install virtualenv
or possibly
apt-get install python-virtualenv
Then go into the directory flask_package_mgr and activate the virtualenv
cd flask_package_mgr
virtualenv venv
. venv/bin/activate
Then you will need to install Flask, pytest, and the application
pip install flask
pip install pytest
pip install --editable .
Now we want to create the initial blank database
export FLASK_APP=flask_package_mgr
flask initdb
The app is not complicated yet. I have not had time to add an actual configuration file, so for now it runs on localhost. If you want to run it on the localhost then do the followin:
export FLASK_APP=flask_package_mgr flask run
Right now most of the functionality has been tested with pytest. If you wish to see the tests run then run pytest
pytest
if you wish to see the log outputs run without supressing text
pytest -s
The API has a few routes:
-
/api/v1/admin/user_list
- content_type - application/json
- methods - GET
- json inputs
- None
- response codes
200
- Success500
- Internal Server Error
- Notes - this is an insecure endpoint only for testing purposes, it would be removed in any actual deployment
-
/api/v1/user/add
- content_type - application/json
- methods - POST
- json inputs
username
- Required, string/text username of new userpassword
- Required, string/text password of new user
- response codes
200
- Success400
- Invalid Use did not include above inputs409
- Conflict - username is already in use500
- Internal Server Error
- Notes - this is the endpoint used to add a new user to the system
-
/api/v1/user/get_token
- content_type - application/json
- methods - POST (is a post because it should create an entry in a database, at this point could be a GET)
- json inputs
username
- Required, string/text username of existing userpassword
- Required, string/text password of existing user
- response codes
200
- Success400
- Invalid Use did not include above inputs401
- Unauthorized typically password is incorrect404
- Not Found, typcially username not found500
- Internal Server Error
- json response
token
- the authorization token to continue using the api
- Notes - this is the endpoint to get the token for authorization, right now is a basic check, no salting/hashing or anything
-
/api/v1/user/invalidate_token
- content_type - application/json
- methods - POST
- headers
token
- token from get_token
- json inputs
username
- Required, string/text username of token userpassword
- Required, string/text password of token user
- response codes
200
- Success400
- Invalid Use typically did not include above inputs401
- Unauthorized typically password is incorrect404
- Not Found, typically username not found500
- Internal Server Error
- json response
message
- message describing revokation
- Notes - this is mostly a test endpoint, but it could be used to manually invalidate a token rather than wait for a timeout
-
/api/v1/packages
- method - POST
- content_type - multipart/form-data
- file
json
- (ran into trouble with werkzeug on this, so it has a weird API)filename
should contain json parameterspackage_name
- Required, string/text package name (cannot contain '/')tag
- Required, string text tag (cannot contain '/')
- pass as type
application/json
- data is ignored
- file
file
- pass file wanting to upload, could be
application/octet-stream
ortext/plain
- pass file wanting to upload, could be
- headers
token
- token from get_token
- response codes
200
- Success400
- Invalid Use typically did not include above inputs or file401
- Unauthorized typically token is incorrect409
- Conflict, typically something that needs to be unique is not500
- Internal Server Error
- response json (I had the thought of using these id's as an alternate accessor of the API, didn't pursue)
package_id
- id of the packagetag_id
- id of the tag
- Notes - this is a very crazy API. I tried to figure out why werkzeug was not allowing me to do this in a sane way, but I ran out of time. I tried a ton of different options, but just settled for getting it working.
- method - GET
- content_type - application/json
- headers
token
- token from get_token
- json inputs
search
- optional, string/text, if not included will return all packages
- response codes
200
- Success401
- Unauthorized typically token is incorrect500
- Internal Server Error
- response json
- list of the following pairs
id
- id of the packagetitle
- title of the package
- list of the following pairs
- Notes - this is a search method, including the search parameter will include all packages that have the input string as a substring
- method - POST
-
/api/v1/<package_name>
- method - POST
- content_type - multipart/form-data
- file
json
- (ran into trouble with werkzeug on this, so it has a weird API)filename
should contain json parameterstag
- Required, string text tag (cannot contain '/')
- pass as type
application/json
- data is ignored
- file
file
- pass file wanting to upload, could be
application/octet-stream
ortext/plain
- pass file wanting to upload, could be
- headers
token
- token from get_token
- response codes
200
- Success400
- Invalid Use typically did not include above inputs or file401
- Unauthorized typically token is incorrect409
- Conflict, typically something that needs to be unique is not500
- Internal Server Error
- response json (I had the thought of using these id's as an alternate accessor of the API, didn't pursue)
package_id
- id of the packagetag_id
- id of the tag
- Notes - this is a very crazy API. I tried to figure out why werkzeug was not allowing me to do this in a sane way, but I ran out of time. I tried a ton of different options, but just settled for getting it working.
- method - GET
- content_type - application/json
- headers
token
- token from get_token
- json inputs
search
- optional, string/text, if not included will return all packages
- response codes
200
- Success401
- Unauthorized typically token is incorrect404
- Not Found, one of the url parameters is incorrect/references something not present500
- Internal Server Error
- response json
- list of the following pairs
id
- id of the packagetag
- tag for a specific instance of this package
- list of the following pairs
- Notes - this is a search method, including the search parameter will include all tags that have the input string as a substring
- method - POST
-
/api/v1/<package_name>/<tag>
- method - POST
- content_type - multipart/form-data
- file
json
- (ran into trouble with werkzeug on this, so it has a weird API)filename
should contain json parameters- pass as type
application/json
- data is ignored
- file
file
- pass file wanting to upload, could be
application/octet-stream
ortext/plain
- pass file wanting to upload, could be
- headers
token
- token from get_token
- response codes
200
- Success400
- Invalid Use typically did not include above inputs or file401
- Unauthorized typically token is incorrect409
- Conflict, typically something that needs to be unique is not500
- Internal Server Error
- response json (I had the thought of using these id's as an alternate accessor of the API, didn't pursue)
package_id
- id of the packagetag_id
- id of the tag
- Notes - this is a very crazy API. I tried to figure out why werkzeug was not allowing me to do this in a sane way, but I ran out of time. I tried a ton of different options, but just settled for getting it working.
- method - GET
- content_type - application/json
- headers
token
- token from get_token
- json inputs
search
- optional, string/text, if not included will return all packages
- responses
- Failure response is json
- response codes
401
- Unauthorized typically token is incorrect404
- Not Found, one of the url parameters is incorrect/references something not present500
- Internal Server Error
- response codes
- success is simply the data of the file in the response data section
- Failure response is json
- Notes - This is a bit of a weird method as well. the failure case will include the json response code, but the success case will use the basic python methods. These seem to not send the response code, and thus it is detected by the absense of a response code.
- method - POST