Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added description of remaining endpoints of the gcbm api and resolved typos in the readme #129

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/containerscan/allowedlist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ general:
- CVE-2022-0002
- CVE-2022-0847
- CVE-2022-1015
- CVE-2022-21499
- CVE-2022-29581
- CVE-2022-1966
- CVE-2022-29361

bestPracticeViolations:
- CIS-DI-0007
Expand Down
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ Currently the REST API has the following endpoints available for access:-

| Endpoint | Functionality |
| :--------------| :------------------------ |
| **\help\all** | Produces a help message with information on all options for moja.CLI. |
| **\help\arg** | Produces a help message with information on option **arg** for moja.CLI. |
| **\version** | Outputs the version number of moja.CLI. |
| **\point** | Runs point example and outputs point_example.csv as an attachment to be downloaded. Parameters (multipart-form data) `file` for point_example can be passed to override the default configurations. |
| **\rothc** | Runs rothc example and outputs point_rothc_example.csv as an attachment to be downloaded. Parameters (multipart-form data) `file` for rothc_example can be passed to override the default configurations.
| **/help/all** | Produces a help message with information on all options for moja.CLI. |
| **/help/arg** | Produces a help message with information on option **arg** for moja.CLI. |
| **/version** | Outputs the version number of moja.CLI. |
| **/point** | Runs point example and outputs point_example.csv as an attachment to be downloaded. Parameters (multipart-form data) `file` for point_example can be passed to override the default configurations. |
| **/rothc** | Runs rothc example and outputs point_rothc_example.csv as an attachment to be downloaded. Parameters (multipart-form data) `file` for rothc_example can be passed to override the default configurations.

This REST API is built using the `flask-restful` package and has been containerized using `Docker`.

Expand All @@ -87,9 +87,15 @@ Currently the REST API has the following endpoints available for access:-

| Endpoint | Functionality |
| :------------ | :-----------------|
| **\help\all** | Produces a help message with information on all options for moja.CLI. |
| **\help\arg** | Produces a help message with information on option **arg** for moja.CLI.|
| **\version** | Outputs the version number of moja.CLI.|
| **/help/all** | Produces a help message with information on all options for moja.CLI. |
| **/help/arg** | Produces a help message with information on option **arg** for moja.CLI.|
| **/version** | Outputs the version number of moja.CLI.|
| **/gcbm/new**| This endpoint is used to create new simulation with the suitable title.|
| **/gcbm/upload**| This endpoint is used to upload all the input files that needs to run the GCBM simulation.|
| **/gcbm/dynamic**| This endpoint is used to execute the simulation process.|
| **/gcbm/status**| This endpoint is used to check the status of the simulation process, whether the simulation is completed or not.|
| **/gcbm/download**| This endpoint is used to download a simulation output in the zip format.|
| **/gcbm/list**| This endpoint is used to check the available simulation currently present.|


This REST API is built using the `flask-restful` package and has been containerized using `Docker`.
Expand Down
8 changes: 5 additions & 3 deletions local/rest_api_flint.example/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
app.register_blueprint(SWAGGERUI_BLUEPRINT, url_prefix=SWAGGER_URL)
### end swagger specific ###

@app.route('/', methods=['GET'])

@app.route("/", methods=["GET"])
def home():
return 'FLINT.Example API'

return "FLINT.Example API"


@app.route("/spec")
def spec():
swag = swagger(app)
Expand Down
2 changes: 2 additions & 0 deletions local/rest_api_gcbm/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ def gcbm_download():
# Sanitize title
title = "".join(c for c in title if c.isalnum())
project_dir = f"{title}"
if not os.path.exists(f"{os.getcwd()}/input/{project_dir}"):
return {"error": "No such simulation exist for this {title}"}, 400
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the error status code, can be changed to 404 as 400 is used for a bad request and 404 is for a not found error. Let me know your thoughts on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 404 is valid here because the simulation of the given title is not present. @padmajabhol What are your views on this issue.

return send_file(
f"{os.getcwd()}/input/{project_dir}/output.zip",
attachment_filename="output.zip",
Expand Down
15 changes: 15 additions & 0 deletions local/tests/test_rest_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,18 @@ def test_version(self, base_endpoint):
version_endpoint = base_endpoint + "version"
version_response = requests.get(version_endpoint)
assert version_response.status_code == 200

def test_help_all(self, base_endpoint):
"""This test is to check the help endpoint with all argument"""
help_all_endpoint = base_endpoint + "help/all"
help_all_response = requests.get(help_all_endpoint)
assert help_all_response.status_code == 200
"This test is to check the help endpoint with random i.e arg argument"
random_arg = "arg"
help_random_endpoint = base_endpoint + "help/arg"
help_random_endpoint = requests.get(help_random_endpoint)
assert help_random_endpoint.status_code == 200
assert (
help_random_endpoint.json()["data"]["response"]
== f"Unknown section '{random_arg}' in the --help-section option\n"
)