# ows-product-review

API for digital audio content review.

## Getting Started

### Installation

> Before starting make sure you have python3.13 installed. An easy way to manage
> python versions is with [pyenv](https://github.com/pyenv/pyenv). Set the local
> python version with the command `pyenv local 3.11.6`

To create a local development environment, you can run `make pip_dev`.
If you skip that and just run `make lint` or `make test`, the `make pip_dev`
steps will automatically run for you in the background, so there is no need to
run `make pip_dev` before other `make` commands.

### Running

You can run the development flask server locally by running `make dev`

By using the development server, you will have access to specific features that
are not necessarily available in production, such as the exception tracer.

### Development Guidelines

#### Route Handlers

All new route handlers must include the `@require_auth_rules_access_standalone` decorator to enforce proper authorization checks. This decorator verifies that the user has the necessary access permissions for the endpoint and returns a 401 Unauthorized response if authorization fails.

Example:
```python
@app.route("/your-new-endpoint", methods=["GET"])
@require_auth_rules_access_standalone
def your_new_handler():
    # Your handler code here
    return flaskify(response.Response(data))
```

If additional header validation is needed, combine it with other decorators:
```python
@app.route("/your-new-endpoint", methods=["POST"])
@require_auth_rules_access_standalone
@require_header_orchard_identity_id
def your_new_handler():
    # Your handler code here
    return flaskify(response.Response(data))
```

### Testing

To run the tests, use the command `make test`

To run linting, use the command `make lint`

To run integration tests, use the command `make test_integration`

### Updating Dependencies

The main dependencies for the service are located in
[./requirements-to-freeze.txt](./requirements-to-freeze.txt). These dependencies
are generally locked using the `~=` operator to loosely constrain dependency
versions. Dependencies that are installed in your local install and deployed
containers are stored in [./requirements.txt](./requirements.txt). This file is
generated using the `requirements-to-freeze.txt` dependencies and locks all
dependencies and sub-dependencies to specific minor versions. **DO NOT MANUALLY
EDIT** `requirements.txt`. Instead, make you updates to
`requirements-to-freeze.txt` and then run `make pip_lock_versions` to generate
a new version of `requirement.txt`.

### Using Docker

You may want to debug or verify the docker image build process is working,
here's how.

1. Ensure you're using `awsume` and its ecr credentials helper.
1. Use awsume to log into our AWS account.
1. Run `docker compose up -d local_server mysqldb` to start up a local ows
   server and mysqldb. The mysqldb won't have any tables defined at first, so
   you'll need to create them based on what's currently in the QA content_review
   database. The database uses a docker volume so the data will not disappear
   if you stop and restart the service.
1. Test application by running
   `curl --request GET --url http://localhost:5000/hello/`
1. Shut down the docker stack by running `docker compose down`

This repo is set up to run PR, Unit-Lint, and Integration Test Jenkins jobs as
docker containers. See the `make` command `docker_unit_lint` and
`docker_test_integration`. Scripts related to those jobs are in the
[./scripts](./scripts) directory.
