Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
🔄 Synced file(s) with WordPress/openverse (#1039)
Openverse (Bot)6b7576695fc7
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.mdindex debacdb69..cffdd1d81 100644--- a/.github/ISSUE_TEMPLATE/bug_report.md+++ b/.github/ISSUE_TEMPLATE/bug_report.md@@ -6,30 +6,35 @@ title: "<Replace this with actual title>"---## Description+<!-- Concisely describe the bug. Compare your experience with what you expected to happen. --><!-- For example: "I clicked the 'submit' button and instead of seeing a thank you message, I saw a blank page." -->## Reproduction+<!-- Provide detailed steps to reproduce the bug. -->+1. <!-- Step 1 ... -->2. <!-- Step 2 ... -->3. <!-- Step 3 ... -->4. See error.## Screenshots+<!-- Add screenshots to show the problem; or delete the section entirely. -->## Environment+<!-- Please complete this, unless you are certain the problem is not environment specific. -->- - Device: <!-- (_eg._ iPhone Xs; laptop) -->- - OS: <!-- (_eg._ iOS 13.5; Fedora 32) -->- - Browser: <!-- (_eg._ Safari; Firefox) -->- - Version: <!-- (_eg._ 13; 73) -->- - Other info: <!-- (_eg._ display resolution, ease-of-access settings) -->++- Device: <!-- (_eg._ iPhone Xs; laptop) -->+- OS: <!-- (_eg._ iOS 13.5; Fedora 32) -->+- Browser: <!-- (_eg._ Safari; Firefox) -->+- Version: <!-- (_eg._ 13; 73) -->+- Other info: <!-- (_eg._ display resolution, ease-of-access settings) -->## Additional context+<!-- Add any other context about the problem here; or delete the section entirely. -->-## Resolution-<!-- Replace the [ ] with [x] to check the box. -->-- [ ] 🙋 I would be interested in resolving this bug.+<!-- If you would like to work on this, please comment below separately. -->diff --git a/.github/ISSUE_TEMPLATE/discussion.md b/.github/ISSUE_TEMPLATE/discussion.mdindex 79344d2c4..ca91bba13 100644--- a/.github/ISSUE_TEMPLATE/discussion.md+++ b/.github/ISSUE_TEMPLATE/discussion.md@@ -6,13 +6,16 @@ title: "<Replace this with actual title>"---<!-- Consider how soon we need the discussion resolved vs. giving everyone an opportunity to participate. -->+## Due date: yyyy-mm-dd<!-- Suggest two members of @WordPress/openverse to review the discussion. -->+## Assigned reviewers- [ ] TBD- [ ] TBD<!-- Start the conversation. Please @ anyone relevant and try to ask questions to help facilate discussion. -->+## Descriptiondiff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.mdindex 75c3ee41d..ab7047947 100644--- a/.github/ISSUE_TEMPLATE/feature_request.md+++ b/.github/ISSUE_TEMPLATE/feature_request.md@@ -6,17 +6,19 @@ title: "<Replace this with actual title>"---## Problem+<!-- Describe a problem solved by this feature; or delete the section entirely. -->## Description+<!-- Describe the feature and how it solves the problem. -->## Alternatives+<!-- Describe any alternative solutions or features you have considered. How is this feature better? -->## Additional context+<!-- Add any other context about the feature here; or delete the section entirely. -->-## Implementation-<!-- Replace the [ ] with [x] to check the box. -->-- [ ] 🙋 I would be interested in implementing this feature.+<!-- If you would like to work on this, please comment below separately. -->diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.mdindex accf40a74..dc5a5773b 100644--- a/.github/PULL_REQUEST_TEMPLATE.md+++ b/.github/PULL_REQUEST_TEMPLATE.md@@ -1,28 +1,39 @@## Fixes+<!-- If PR doesn't fully resolve the issue, replace 'Fixes' below with 'Related to'. --><!-- If there is no issue being resolved, please consider opening one before creating this pull request. -->+Fixes #[issue number] by @[issue author]## Description+<!-- Concisely describe what the pull request does. --><!-- Add screenshots, videos, or other media to show the problem and the solution when appropriate. -->## Testing Instructions+<!-- Give steps for the reviewer to verify that this PR fixes the problem; or delete this section entirely. -->## Checklist+<!-- Replace the [ ] with [x] to check the boxes. -->-- [ ] My pull request has a descriptive title (not a vague title like `Update index.md`).-- [ ] My pull request targets the *default* branch of the repository (`main`) or a parent feature branch.++- [ ] My pull request has a descriptive title (not a vague title like+ `Update index.md`).+- [ ] My pull request targets the _default_ branch of the repository (`main`) or+ a parent feature branch.- [ ] My commit messages follow [best practices][best_practices].- [ ] My code follows the established code style of the repository.- [ ] I added or updated tests for the changes I made (if applicable).- [ ] I added or updated documentation (if applicable).-- [ ] I tried running the project locally and verified that there are no visible errors.+- [ ] I tried running the project locally and verified that there are no visible+ errors.-[best_practices]:https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#_commit_guidelines+[best_practices]:+ https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#_commit_guidelines## Developer Certificate of Origin+<!-- You must read and understand the following attestation. --><details>diff --git a/.github/workflows/pr_label_check.yml b/.github/workflows/pr_label_check.ymlindex 726c02934..d8dd7c16d 100644--- a/.github/workflows/pr_label_check.yml+++ b/.github/workflows/pr_label_check.yml@@ -13,24 +13,27 @@ jobs:runs-on: ubuntu-lateststeps:- name: Check aspect label- uses: sugarshin/[email protected]+ uses: docker://agilepathway/pull-request-label-checker:v1.2.9with:- required_oneof: "💻 aspect: code,📄 aspect: text,🤖 aspect: dx,🕹 aspect: interface,♿️ aspect: a11y"+ one_of: "💻 aspect: code,📄 aspect: text,🤖 aspect: dx,🕹 aspect: interface,♿️ aspect: a11y"+ repo_token: ${{ secrets.GITHUB_TOKEN }}check_goal_label:name: Check goal labelruns-on: ubuntu-lateststeps:- name: Check goal label- uses: sugarshin/[email protected]+ uses: docker://agilepathway/pull-request-label-checker:v1.2.9with:- required_oneof: "🌟 goal: addition,🛠 goal: fix,✨ goal: improvement,🧰 goal: internal improvement"+ one_of: "🌟 goal: addition,🛠 goal: fix,✨ goal: improvement,🧰 goal: internal improvement"+ repo_token: ${{ secrets.GITHUB_TOKEN }}check_priority_label:name: Check priority labelruns-on: ubuntu-lateststeps:- name: Check priority label- uses: sugarshin/[email protected]+ uses: docker://agilepathway/pull-request-label-checker:v1.2.9with:- required_oneof: "🟩 priority: low,🟨 priority: medium,🟧 priority: high,🟥 priority: critical"+ one_of: "🟩 priority: low,🟨 priority: medium,🟧 priority: high,🟥 priority: critical"+ repo_token: ${{ secrets.GITHUB_TOKEN }}diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex 4ba3de21b..89540ab63 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -67,7 +67,6 @@ repos:rev: v2.6.0hooks:- id: prettier- exclude: \.md$ # TODO: https://github.com/WordPress/openverse/issues/333additional_dependencies:diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.mdindex 5a77323cc..d68c1b7de 100644--- a/CODE_OF_CONDUCT.md+++ b/CODE_OF_CONDUCT.md@@ -1,11 +1,25 @@-This project comes under the WordPress [Etiquette](https://wordpress.org/about/etiquette/):+This project comes under the WordPress+[Etiquette](https://wordpress.org/about/etiquette/):-In the WordPress open source project, we realize that our biggest asset is the community that we foster. The project, as a whole, follows these basic philosophical principles from The Cathedral and The Bazaar.+In the WordPress open source project, we realize that our biggest asset is the+community that we foster. The project, as a whole, follows these basic+philosophical principles from The Cathedral and The Bazaar.-- Contributions to the WordPress open source project are for the benefit of the WordPress community as a whole, not specific businesses or individuals. All actions taken as a contributor should be made with the best interests of the community in mind.-- Participation in the WordPress open source project is open to all who wish to join, regardless of ability, skill, financial status, or any other criteria.-- The WordPress open source project is a volunteer-run community. Even in cases where contributors are sponsored by companies, that time is donated for the benefit of the entire open source community.-- Any member of the community can donate their time and contribute to the project in any form including design, code, documentation, community building, etc. For more information, go to make.wordpress.org.-- The WordPress open source community cares about diversity. We strive to maintain a welcoming environment where everyone can feel included, by keeping communication free of discrimination, incitement to violence, promotion of hate, and unwelcoming behavior.+- Contributions to the WordPress open source project are for the benefit of the+ WordPress community as a whole, not specific businesses or individuals. All+ actions taken as a contributor should be made with the best interests of the+ community in mind.+- Participation in the WordPress open source project is open to all who wish to+ join, regardless of ability, skill, financial status, or any other criteria.+- The WordPress open source project is a volunteer-run community. Even in cases+ where contributors are sponsored by companies, that time is donated for the+ benefit of the entire open source community.+- Any member of the community can donate their time and contribute to the+ project in any form including design, code, documentation, community building,+ etc. For more information, go to make.wordpress.org.+- The WordPress open source community cares about diversity. We strive to+ maintain a welcoming environment where everyone can feel included, by keeping+ communication free of discrimination, incitement to violence, promotion of+ hate, and unwelcoming behavior.The team involved will block any user who causes any breach in this.diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 161f097db..bb1aa260d 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -1,39 +1,60 @@# Contributing to Openverse-Thank you for your interest in contributing to Openverse! This document is a set of guidelines to help you contribute to this project.+Thank you for your interest in contributing to Openverse! This document is a set+of guidelines to help you contribute to this project.## Code of Conduct-By participating in this project, you are expected to uphold our [Code of Conduct](./CODE_OF_CONDUCT.md).+By participating in this project, you are expected to uphold our+[Code of Conduct](./CODE_OF_CONDUCT.md).## Project DocumentationPlease consult the [README](./README.md) file at the root of this repository.-Also see the [project documentation guidelines](./DOCUMENTATION_GUIDELINES.md) if you are interested in improving our documentation.+Also see the [project documentation guidelines](./DOCUMENTATION_GUIDELINES.md)+if you are interested in improving our documentation.### Bugs-If you find a bug, please open an issue in this repository describing the bug. You can file a bug [here](https://github.com/WordPress/openverse-api/issues/new?template=bug_report.md). You will see a bug report template with the required information you should provide.+If you find a bug, please open an issue in this repository describing the bug.+You can file a bug+[here](https://github.com/WordPress/openverse-api/issues/new?template=bug_report.md).+You will see a bug report template with the required information you should+provide.After that, don't forget to tag the issue with the "Bug" label.### Proposing changes or new features-Feel free to [open an issue](https://github.com/WordPress/openverse-api/issues/new/choose) to discuss any new features or to propose any changes.+Feel free to+[open an issue](https://github.com/WordPress/openverse-api/issues/new/choose) to+discuss any new features or to propose any changes.### Pull requests-Before you start writing code, make sure there is an issue open. Pull requests without a link to an existing issue won't be merged.+Before you start writing code, make sure there is an issue open. Pull requests+without a link to an existing issue won't be merged.-If you want to get started contributing code to this project but don't know exactly what to work on, we compiled a good list of issues labeled as [`good first issue`](https://github.com/wordpress/openverse-api/labels/good%20first%20issue) which are small in scope and not so complex to solve. There are also issues labeled as [`help wanted`](https://github.com/wordpress/openverse-api/labels/help%20wanted) which can be a bit more complex but are good examples of things we are currently accepting help from the community.+If you want to get started contributing code to this project but don't know+exactly what to work on, we compiled a good list of issues labeled as+[`good first issue`](https://github.com/wordpress/openverse-api/labels/good%20first%20issue)+which are small in scope and not so complex to solve. There are also issues+labeled as+[`help wanted`](https://github.com/wordpress/openverse-api/labels/help%20wanted)+which can be a bit more complex but are good examples of things we are currently+accepting help from the community.-Any code modifications will have to be accompanied by the appropriate unit tests. This will be checked and verified during code review. Once the Pull Request is opened, our CI server will run the unit test suite and run a code linter to verify that the code follows the coding guidelines.+Any code modifications will have to be accompanied by the appropriate unit+tests. This will be checked and verified during code review. Once the Pull+Request is opened, our CI server will run the unit test suite and run a code+linter to verify that the code follows the coding guidelines.## Running the tests### How to Run API live integration tests-You can check the health of a live deployment of the API by running the live integration tests.+You can check the health of a live deployment of the API by running the live+integration tests.1. Change directory to `openverse_api`@@ -47,11 +68,13 @@ cd openverse_apipipenv install```-Note: The following non-Python libraries or binaries are transient dependencies which will also need to be present on your computer for the project to run and install as expected:+Note: The following non-Python libraries or binaries are transient dependencies+which will also need to be present on your computer for the project to run and+install as expected:-* `librdkafka`-* `exempi`-* `audiowaveform`+- `librdkafka`+- `exempi`+- `audiowaveform`3. Launch a new shell session@@ -95,4 +118,5 @@ python3 test/integration_tests.py## Questions or Thoughts?-Feel free to [join us on Slack](https://make.wordpress.org/chat/) and discuss the project with the engineers and community members on #openverse.+Feel free to [join us on Slack](https://make.wordpress.org/chat/) and discuss+the project with the engineers and community members on #openverse.diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.mdindex aa39374c8..4818ecbb7 100644--- a/CONTRIBUTORS.md+++ b/CONTRIBUTORS.md@@ -1,11 +1,13 @@# openverse-api contributors (sorted alphabetically by last name)- **[Liza Daley](https://github.com/lizadaly)**- - Built CC Search prototype, bits of which live on in this repository to this day+ - Built CC Search prototype, bits of which live on in this repository to this+ day- **[Alden Page](https://github.com/aldenstpage)**- Author and maintainer of current implementation- **[Paulo Rosário](https://github.com/paulofilip3)**- - Contributed to solution for consistent link rot filtering without impacting result count, improved test suite+ - Contributed to solution for consistent link rot filtering without impacting+ result count, improved test suite- **[Krystle Salazar](https://github.com/krysal)**- Implemented image takedown endpoint- **[Habeeb Shopeju](https://github.com/HAKSOAT)**diff --git a/DOCUMENTATION_GUIDELINES.md b/DOCUMENTATION_GUIDELINES.mdindex d93f68b9e..504f38eb7 100644--- a/DOCUMENTATION_GUIDELINES.md+++ b/DOCUMENTATION_GUIDELINES.md@@ -1,22 +1,28 @@# Documentation Guidelines-Interested in improving our documentation? Here’s what you need to know before making any changes to the documentation.+Interested in improving our documentation? Here’s what you need to know before+making any changes to the documentation.<br/>## Introduction-Openverse API uses [drf-yasg](https://github.com/axnsan12/drf-yasg), which is a tool that generates real Swagger/OpenAPI 2.0 specifications from a Django Rest Framework API.+Openverse API uses [drf-yasg](https://github.com/axnsan12/drf-yasg), which is a+tool that generates real Swagger/OpenAPI 2.0 specifications from a Django Rest+Framework API.<br/>## How to Start Contributing-- Run the server locally by following this [link](https://github.com/WordPress/openverse-api#running-the-server-locally)+- Run the server locally by following this+ [link](https://github.com/WordPress/openverse-api#running-the-server-locally)- Update documentation-- Make sure the updates passed the automated tests in this [file](https://github.com/WordPress/openverse-api/blob/main/.github/workflows/ci_cd.yml)+- Make sure the updates passed the automated tests in this+ [file](https://github.com/WordPress/openverse-api/blob/main/.github/workflows/ci_cd.yml)- Commit and push-- Create pull request by following [GitHub Repo Guidelines](https://opensource.creativecommons.org/contributing-code/github-repo-guidelines/)+- Create pull request by following+ [GitHub Repo Guidelines](https://opensource.creativecommons.org/contributing-code/github-repo-guidelines/)<br/>@@ -30,7 +36,8 @@ Openverse API uses [drf-yasg](https://github.com/axnsan12/drf-yasg), which is a## Cheat Sheet for drf-yasg-This is a quick syntax guide with examples on how to add or update the documentation for API endpoints.+This is a quick syntax guide with examples on how to add or update the+documentation for API endpoints.<br/>@@ -73,7 +80,9 @@ image_stats_description = \### Responses-The response received after submitting an API request. The current API documentation includes response schemas and response samples based on their response codes.+The response received after submitting an API request. The current API+documentation includes response schemas and response samples based on their+response codes.**Example**@@ -159,7 +168,8 @@ register_api_oauth2_request = openapi.Schema(### Code Examples-Code examples on how to use the API endpoints. The current API documentation provides code examples in Bash.+Code examples on how to use the API endpoints. The current API documentation+provides code examples in Bash.**Example**diff --git a/README.md b/README.mdindex 2bc7ca87c..5bf86b752 100644--- a/README.md+++ b/README.md@@ -8,12 +8,21 @@## Purpose-This repository is primarily concerned with back end infrastructure like datastores, servers, and APIs. The pipeline that feeds data into this system can be found in the [Openverse Catalog repository](https://github.com/WordPress/openverse-catalog). A front end web application that interfaces with the API can be found at the [Openverse frontend repository](https://github.com/WordPress/openverse-frontend).+This repository is primarily concerned with back end infrastructure like+datastores, servers, and APIs. The pipeline that feeds data into this system can+be found in the+[Openverse Catalog repository](https://github.com/WordPress/openverse-catalog).+A front end web application that interfaces with the API can be found at the+[Openverse frontend repository](https://github.com/WordPress/openverse-frontend).## Getting started-Our quickstart guide and other documentation can be found in our [developer docs](https://wordpress.github.io/openverse-api/guides/quickstart.html) (or within the repo at [`./api/docs/guides/quickstart.md`](./api/docs/guides/quickstart.md)).-Our API documentation can also be found at [https://api.openverse.engineering](https://api.openverse.engineering).+Our quickstart guide and other documentation can be found in our+[developer docs](https://wordpress.github.io/openverse-api/guides/quickstart.html)+(or within the repo at+[`./api/docs/guides/quickstart.md`](./api/docs/guides/quickstart.md)). Our API+documentation can also be found at+[https://api.openverse.engineering](https://api.openverse.engineering).## System architecture@@ -21,24 +30,48 @@ Our API documentation can also be found at [https://api.openverse.engineering](h### Basic flow of data-Search data is ingested from upstream sources provided by the [data pipeline](https://github.com/WordPress/openverse-catalog). As of the time of writing, this includes data from Common Crawl and multiple 3rd party APIs. Once the data has been scraped and cleaned, it is transferred to the upstream database, indicating that it is ready for production use.+Search data is ingested from upstream sources provided by the+[data pipeline](https://github.com/WordPress/openverse-catalog). As of the time+of writing, this includes data from Common Crawl and multiple 3rd party APIs.+Once the data has been scraped and cleaned, it is transferred to the upstream+database, indicating that it is ready for production use.-Every week, the latest version of the data is automatically bulk copied ("ingested") from the upstream database to the production database by the Ingestion Server. Once the data has been downloaded and indexed inside of the database, the data is indexed in Elasticsearch, at which point the new data can be served up from the Openverse API servers.+Every week, the latest version of the data is automatically bulk copied+("ingested") from the upstream database to the production database by the+Ingestion Server. Once the data has been downloaded and indexed inside of the+database, the data is indexed in Elasticsearch, at which point the new data can+be served up from the Openverse API servers.### Description of subprojects-- **api/**: a Django Rest Framework API server- For a full description of its capabilities, please see the [browsable documentation](https://api.openverse.engineering).-- **ingestion_server/**: a service for downloading and indexing search data once it has been prepared by the Openverse Catalog+- **api/**: a Django Rest Framework API server For a full description of its+ capabilities, please see the+ [browsable documentation](https://api.openverse.engineering).+- **ingestion_server/**: a service for downloading and indexing search data once+ it has been prepared by the Openverse Catalog## Contributing-Pull requests are welcome! Feel free to [join us on Slack](https://make.wordpress.org/chat/) and discuss the project with the engineers and community members on #openverse.+Pull requests are welcome! Feel free to+[join us on Slack](https://make.wordpress.org/chat/) and discuss the project+with the engineers and community members on #openverse.-You are welcome to take any open issue in the tracker labeled [`help wanted`](https://github.com/WordPress/openverse-api/labels/help%20wanted) or [`good first issue`](https://github.com/WordPress/openverse-api/labels/good%20first%20issue); **there's no need to ask for permission in advance**. Other issues are open for contribution as well, but may be less accessible or well-defined in comparison to those that are explicitly labeled.+You are welcome to take any open issue in the tracker labeled+[`help wanted`](https://github.com/WordPress/openverse-api/labels/help%20wanted)+or+[`good first issue`](https://github.com/WordPress/openverse-api/labels/good%20first%20issue);+**there's no need to ask for permission in advance**. Other issues are open for+contribution as well, but may be less accessible or well-defined in comparison+to those that are explicitly labeled.See the [CONTRIBUTING](CONTRIBUTING.md) file for details.## Acknowledgments-Openverse, previously known as CC Search, was conceived and built at [Creative Commons](https://creativecommons.org). We thank them for their commitment to open source and openly licensed content, with particular thanks to previous team members @ryanmerkley, @janetpkr, @lizadaly, @sebworks, @pa-w, @kgodey, @annatuma, @mathemancer, @aldenstpage, @brenoferreira, and @sclachar, along with their [community of volunteers](https://opensource.creativecommons.org/community/community-team/).+Openverse, previously known as CC Search, was conceived and built at+[Creative Commons](https://creativecommons.org). We thank them for their+commitment to open source and openly licensed content, with particular thanks to+previous team members @ryanmerkley, @janetpkr, @lizadaly, @sebworks, @pa-w,+@kgodey, @annatuma, @mathemancer, @aldenstpage, @brenoferreira, and @sclachar,+along with their+[community of volunteers](https://opensource.creativecommons.org/community/community-team/).diff --git a/api/README.md b/api/README.mdindex a55fb3089..06bc03143 100644--- a/api/README.md+++ b/api/README.md@@ -3,6 +3,7 @@The API has two sets of documentation.- [Developer docs](https://wordpress.github.io/openverse-api/)+- are focused towards developers who are building the Openverse API- can be seen locally by- running the following recipe:diff --git a/api/catalog/api/docs/README.md b/api/catalog/api/docs/README.mdindex 1bb996012..cf59ea2bd 100644--- a/api/catalog/api/docs/README.md+++ b/api/catalog/api/docs/README.md@@ -1,12 +1,11 @@This documentation is focused towards consumers who are using the Openverse API.The developer documentation for the Openverse API can be found [here]().-# Introduction-The Openverse API is a system that allows programmatic access-to public domain digital media. It is our ambition to index and catalog billions-of openly-licensed works, including articles, songs, videos, photographs,+The Openverse API is a system that allows programmatic access to public domain+digital media. It is our ambition to index and catalog billions of+openly-licensed works, including articles, songs, videos, photographs,paintings, and more. Using this API, developers will be able to access thedigital commons in their own applications.@@ -22,10 +21,12 @@ instructions on obtaining an API key.# Register and Authenticate## Register for a key+Before using the Openverse API, you need to register access via OAuth2. This canbe done using the `/v1/auth_tokens/register/` endpoint.Example on how to register for a key:+```bash$ curl \-X POST \@@ -33,49 +34,57 @@ $ curl \-d '{"name": "My amazing project", "description": "To access Openverse API", "email": "[email protected]"}' \"https://api.openverse.engineering/v1/auth_tokens/register/"```+If your request is successful, you will get a `client_id` and `client_secret`.Example of successful request:+```json{- "client_secret" : "YhVjvIBc7TuRJSvO2wIi344ez5SEreXLksV7GjalLiKDpxfbiM8qfUb5sNvcwFOhBUVzGNdzmmHvfyt6yU3aGrN6TAbMW8EOkRMOwhyXkN1iDetmzMMcxLVELf00BR2e",- "client_id" : "pm8GMaIXIhkjQ4iDfXLOvVUUcIKGYRnMlZYApbda",- "name" : "My amazing project"+ "client_secret": "YhVjvIBc7TuRJSvO2wIi344ez5SEreXLksV7GjalLiKDpxfbiM8qfUb5sNvcwFOhBUVzGNdzmmHvfyt6yU3aGrN6TAbMW8EOkRMOwhyXkN1iDetmzMMcxLVELf00BR2e",+ "client_id": "pm8GMaIXIhkjQ4iDfXLOvVUUcIKGYRnMlZYApbda",+ "name": "My amazing project"}```## Authenticate+In order to use the Openverse API endpoints, you need to include access token inthe header. This can be done by exchanging your client credentials for a tokenusing the `/v1/auth_tokens/token/` endpoint.Example on how to authenticate using OAuth2:+```bash$ curl \-X POST \-d "client_id=pm8GMaIXIhkjQ4iDfXLOvVUUcIKGYRnMlZYApbda&client_secret=YhVjvIBc7TuRJSvO2wIi344ez5SEreXLksV7GjalLiKDpxfbiM8qfUb5sNvcwFOhBUVzGNdzmmHvfyt6yU3aGrN6TAbMW8EOkRMOwhyXkN1iDetmzMMcxLVELf00BR2e&grant_type=client_credentials" \"https://api.openverse.engineering/v1/auth_tokens/token/"```+If your request is successful, you will get an access token.Example of successful request:+```json- {- "access_token" : "DLBYIcfnKfolaXKcmMC8RIDCavc2hW",- "scope" : "read write groups",- "expires_in" : 36000,- "token_type" : "Bearer"- }+{+ "access_token": "DLBYIcfnKfolaXKcmMC8RIDCavc2hW",+ "scope": "read write groups",+ "expires_in": 36000,+ "token_type": "Bearer"+}```Check your email for a verification link. After you have followed the link, yourAPI key will be activated.## Using Access Token+Include the `access_token` in the authorization header to use your key in yourfuture API requests.Example on how to make an authenticated request:+```bash$ curl \-H "Authorization: Bearer DLBYIcfnKfolaXKcmMC8RIDCavc2hW" \@@ -87,23 +96,23 @@ $ curl \# Glossary-| Term | Definition |-|-------------------|---|-| API | an abbreviation for Application Programming Interface |-| OAuth2 | an authorization framework that enables a third party application to get access to an HTTP service |-| access token | a private string that authorizes an application to make API requests |-| client ID | a publicly exposed string used by Openverse API to identify the application |-| client secret | a private string that authenticates the identity of the application to the Openverse API |-| CC | an abbreviation for Creative Commons |-| copyright | a type of intellectual property that gives the owner an exclusive right to reproduce, publish, sell or distribute content |-| mature content | any content that requires the audience to be 18 and older |+| Term | Definition |+| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| API | an abbreviation for Application Programming Interface |+| OAuth2 | an authorization framework that enables a third party application to get access to an HTTP service |+| access token | a private string that authorizes an application to make API requests |+| client ID | a publicly exposed string used by Openverse API to identify the application |+| client secret | a private string that authenticates the identity of the application to the Openverse API |+| CC | an abbreviation for Creative Commons |+| copyright | a type of intellectual property that gives the owner an exclusive right to reproduce, publish, sell or distribute content |+| mature content | any content that requires the audience to be 18 and older || sensitive content | any content that depicts graphic violence, adult content, and hostility or malice against others based on their race, religion, disability, sexual orientation, ethnicity and national origin |# ContributeWe love pull requests! If you’re interested in-[contributing on Github](https://github.com/WordPress/openverse-api/blob/main/CONTRIBUTING.md), here’s a-todo list to get started.+[contributing on Github](https://github.com/WordPress/openverse-api/blob/main/CONTRIBUTING.md),+here’s a todo list to get started.- Read up about [Django REST Framework](https://www.django-rest-framework.org/),which is the framework used to build Openverse APIdiff --git a/api/docs/_static/_css/brand.css b/api/docs/_static/_css/brand.cssindex eaf865706..c5c7b8dfe 100644--- a/api/docs/_static/_css/brand.css+++ b/api/docs/_static/_css/brand.css@@ -2,12 +2,12 @@color: black;}-body[data-theme='dark'] .sidebar-logo-container {+body[data-theme="dark"] .sidebar-logo-container {color: white;}@media (prefers-color-scheme: dark) {- body:not([data-theme='light']) .sidebar-logo-container {+ body:not([data-theme="light"]) .sidebar-logo-container {color: white;}}diff --git a/api/docs/guides/https.md b/api/docs/guides/https.mdindex c78e06802..bd0592a19 100644--- a/api/docs/guides/https.md+++ b/api/docs/guides/https.md@@ -1,13 +1,18 @@# Testing HTTPS-To emulate the proxying behavior of production, we have set up an NGINX proxy that serves the API over `https` by proxying to the Gunicorn server which serves over `http`.+To emulate the proxying behavior of production, we have set up an NGINX proxy+that serves the API over `https` by proxying to the Gunicorn server which serves+over `http`.-This proxy uses certificates from the `nginx/certs/` directory. These certificates can be generated using `mkcert` with the `just cert` command.+This proxy uses certificates from the `nginx/certs/` directory. These+certificates can be generated using `mkcert` with the `just cert` command.-Additionally, to test with the dev hostname `dev.openverse.test`, add the following line to your hosts file.+Additionally, to test with the dev hostname `dev.openverse.test`, add the+following line to your hosts file.```text127.0.0.1 dev.openverse.test```-Visiting `http://dev.openverse.test:9080` in your browser should permanently redirect you to `https://dev.openverse.test:9443`.+Visiting `http://dev.openverse.test:9080` in your browser should permanently+redirect you to `https://dev.openverse.test:9443`.diff --git a/api/docs/guides/logging.md b/api/docs/guides/logging.mdindex 01ea4e382..f65f56e05 100644--- a/api/docs/guides/logging.md+++ b/api/docs/guides/logging.md@@ -1,19 +1,46 @@# Logging-Openverse is in the process of establishing and implementing its logging strategy. Until the [introduction of more extensive logging in the Elasticsearch controller modules](https://github.com/WordPress/openverse-api/pull/790) we did not have an established approach to logging. That PR still does not establish a comprehensive approach, but it does introduce and follow some rules:+Openverse is in the process of establishing and implementing its logging+strategy. Until the+[introduction of more extensive logging in the Elasticsearch controller modules](https://github.com/WordPress/openverse-api/pull/790)+we did not have an established approach to logging. That PR still does not+establish a comprehensive approach, but it does introduce and follow some rules:++1. Always use a child logger based on the module name and method name. For+ example, at the top level of a module, there should be a `parent_logger`+ variable that is the result of calling `logging.getLogger(__name__)`.+ Individual methods that log should+ [get a child logger for themselves based on this parent logger and their method name](https://docs.python.org/3/library/logging.html#logging.Logger.getChild):-1. Always use a child logger based on the module name and method name. For example, at the top level of a module, there should be a `parent_logger` variable that is the result of calling `logging.getLogger(__name__)`. Individual methods that log should [get a child logger for themselves based on this parent logger and their method name](https://docs.python.org/3/library/logging.html#logging.Logger.getChild):```pydef apply_filters(self, ...):logging = parent_logger.getChild("apply_filters")...```-2. When logging variable values, log them in the following format: `name=value`. Prefer that `name` equals the expression that produces the `value`. For example, if logging the length of a list named `providers`, `name` should be `len(providers)`, with the full expression looking like this: `len(providers)={len(providers)}`. If logging a property of an object, prefer `object.property_name={object.property_name}`. Exclude serialization from the name like `json.dumps` as this is assumed: `verified={json.dumps(verified)}`.-3. Avoid using the `pprint` module for serializing log data as it significantly increases the amount of space and time it takes to write a log. Instead, prefer a simpler `json.dumps`.-These practices provide context in the logs and makes them uniformly searchable and filterable based on the values assigned to the names. Using a child logger means we can easily see all the logs for a method. Using the `name=value` format means we always know how to filter any given logged variable either by name or by name and value.+2. When logging variable values, log them in the following format: `name=value`.+ Prefer that `name` equals the expression that produces the `value`. For+ example, if logging the length of a list named `providers`, `name` should be+ `len(providers)`, with the full expression looking like this:+ `len(providers)={len(providers)}`. If logging a property of an object, prefer+ `object.property_name={object.property_name}`. Exclude serialization from the+ name like `json.dumps` as this is assumed: `verified={json.dumps(verified)}`.+3. Avoid using the `pprint` module for serializing log data as it significantly+ increases the amount of space and time it takes to write a log. Instead,+ prefer a simpler `json.dumps`.++These practices provide context in the logs and makes them uniformly searchable+and filterable based on the values assigned to the names. Using a child logger+means we can easily see all the logs for a method. Using the `name=value` format+means we always know how to filter any given logged variable either by name or+by name and value.-Openverse also makes use of request IDs. Because multiple workers are writing to the same log at once, any given request's logs may be interspersed with the logs of another. Filtering on the request ID allows us to see the full logging story of a single request. This allows us to trace problematic requests through the codebase and understand what specific parts of the code are causing problems with these particular requests.+Openverse also makes use of request IDs. Because multiple workers are writing to+the same log at once, any given request's logs may be interspersed with the logs+of another. Filtering on the request ID allows us to see the full logging story+of a single request. This allows us to trace problematic requests through the+codebase and understand what specific parts of the code are causing problems+with these particular requests.## Future improvementsdiff --git a/api/docs/guides/publish.md b/api/docs/guides/publish.mdindex 5709bdf88..f218fd273 100644--- a/api/docs/guides/publish.md+++ b/api/docs/guides/publish.md@@ -1,49 +1,68 @@# Publish-The production API and ingestion server Docker images are published to [Github Container Registry](https://ghcr.io).-They can be found here:-* API: [ghcr.io/wordpress/openverse-api](https://ghcr.io/wordpress/openverse-api)-* Ingestion server: [ghcr.io/wordpress/openverse-ingestion_server](https://ghcr.io/wordpress/openverse-ingestion_server)+The production API and ingestion server Docker images are published to+[Github Container Registry](https://ghcr.io). They can be found here:++- API:+ [ghcr.io/wordpress/openverse-api](https://ghcr.io/wordpress/openverse-api)+- Ingestion server:+ [ghcr.io/wordpress/openverse-ingestion_server](https://ghcr.io/wordpress/openverse-ingestion_server)These images are published under two conditions: on release, or manually.## On release-When a new release is cut, the [CI/CD action will run](https://github.com/WordPress/openverse-api/actions/workflows/ci_cd.yml?query=event%3Arelease).-The final step of this action uploads the Docker images to their respective registries with the following tags:-* Release reference name, typically the git tag (e.g. `v2.4.2`)-* `latest`-* The commit SHA of the tagged commit (e.g. `b25879b84ec9d7b650be689c03384937a93eb06d`)+When a new release is cut, the+[CI/CD action will run](https://github.com/WordPress/openverse-api/actions/workflows/ci_cd.yml?query=event%3Arelease).+The final step of this action uploads the Docker images to their respective+registries with the following tags:++- Release reference name, typically the git tag (e.g. `v2.4.2`)+- `latest`+- The commit SHA of the tagged commit (e.g.+ `b25879b84ec9d7b650be689c03384937a93eb06d`)-In some cases, releases may not alter the Docker image.-For instance, in a release where only the API was changed, the ingestion server image would have the same Docker image hash.-In these instances, the new tags are added to the existing image.+In some cases, releases may not alter the Docker image. For instance, in a+release where only the API was changed, the ingestion server image would have+the same Docker image hash. In these instances, the new tags are added to the+existing image.## Manually-The Docker image for a particular service can also be published manually.-This process is initiated by the [Publish Docker images on-demand](https://github.com/WordPress/openverse-api/actions/workflows/push_docker_image.yml) action.-The workflow file for this action can be found here: [`push_docker_image.yml`](https://github.com/WordPress/openverse-api/blob/main/.github/workflows/push_docker_image.yml).+The Docker image for a particular service can also be published manually. This+process is initiated by the+[Publish Docker images on-demand](https://github.com/WordPress/openverse-api/actions/workflows/push_docker_image.yml)+action. The workflow file for this action can be found here:+[`push_docker_image.yml`](https://github.com/WordPress/openverse-api/blob/main/.github/workflows/push_docker_image.yml).-This action **will only publish & tag a service's image with the commit SHA** (i.e. it will not tag with `latest` or the git reference name).-This is useful for cases where one or more Docker images need to be tested on a staging environment before being merged and cut with a release.-This action also **requires that the CI/CD workflow has previously run on the specified commit**.+This action **will only publish & tag a service's image with the commit SHA**+(i.e. it will not tag with `latest` or the git reference name). This is useful+for cases where one or more Docker images need to be tested on a staging+environment before being merged and cut with a release. This action also+**requires that the CI/CD workflow has previously run on the specified commit**.This typically requires a PR in order to initiate.-Note that this action can only run on commits that had successful CI/CD runs in the last 90 days [due to GitHub's default artifact retention policy](https://docs.github.com/en/organizations/managing-organization-settings/configuring-the-retention-period-for-github-actions-artifacts-and-logs-in-your-organization).+Note that this action can only run on commits that had successful CI/CD runs in+the last 90 days+[due to GitHub's default artifact retention policy](https://docs.github.com/en/organizations/managing-organization-settings/configuring-the-retention-period-for-github-actions-artifacts-and-logs-in-your-organization).### Steps-_Note: [GitHub's documentation provides screenshots for the various steps](https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch)_+_Note:+[GitHub's documentation provides screenshots for the various steps](https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch)_-1. Navigate to the `openverse-api` "Actions" tab in GitHub: [github.com/WordPress/openverse-api/actions](https://github.com/WordPress/openverse-api/actions).+1. Navigate to the `openverse-api` "Actions" tab in GitHub:+ [github.com/WordPress/openverse-api/actions](https://github.com/WordPress/openverse-api/actions).2. Select the "Publish Docker images on-demand" workflow.3. Click the "Run workflow" button.- 1. (Optional) change the branch _that the workflow is running from_ (this does not change anything about the target commit)+ 1. (Optional) change the branch _that the workflow is running from_ (this+ does not change anything about the target commit)2. For the `image` parameter, specify either `api` or `ingestion_server`.- 3. For the `commit` parameter, specify the commit that the built Docker image artifact should be pulled from.-5. Click the green "Run workflow" button.+ 3. For the `commit` parameter, specify the commit that the built Docker image+ artifact should be pulled from.+4. Click the green "Run workflow" button.-The newest run should appear in the Action list, and its status can be tracked from there.+The newest run should appear in the Action list, and its status can be tracked+from there.diff --git a/api/docs/guides/quickstart.md b/api/docs/guides/quickstart.mdindex 7b20ddedf..152d5f025 100644--- a/api/docs/guides/quickstart.md+++ b/api/docs/guides/quickstart.md@@ -8,51 +8,67 @@- [Just](https://github.com/casey/just)- [mkcert](https://github.com/FiloSottile/mkcert)-Ensure that you have installed `mkcert` (and the corresponding NSS tools). You can run `mkcert -install` to verify your installation.+Ensure that you have installed `mkcert` (and the corresponding NSS tools). You+can run `mkcert -install` to verify your installation.-> _**Note:**_ Our Docker compose configuration requires specific environment configuration that is automatically handled by `just`. While you can run compose directly, it's advised to use the `just dc` alias for `docker-compose` as this ensures the environment will be properly configured.+> _**Note:**_ Our Docker compose configuration requires specific environment+> configuration that is automatically handled by `just`. While you can run+> compose directly, it's advised to use the `just dc` alias for `docker-compose`+> as this ensures the environment will be properly configured.## Steps-1. Ensure that the [Docker daemon](https://docs.docker.com/config/daemon/) is running.+1. Ensure that the [Docker daemon](https://docs.docker.com/config/daemon/) is+ running.2. Clone the repository and `cd` into it. This is the monorepo root.+```bashgit clone https://github.com/WordPress/openverse-api.gitcd openverse-api/```-3. Generate locally-trusted certificates. These will be used by the NGINX proxy to serve the API over `https`.- ```bash- just cert- ```+3. Generate locally-trusted certificates. These will be used by the NGINX proxy+ to serve the API over `https`.++ ```bash+ just cert+ ```++4. From the monorepo root, bring up the Docker Compose system. Docker Compose+ will automatically read the necessary environment variables from `env.docker`+ files from project directories.-4. From the monorepo root, bring up the Docker Compose system. Docker Compose will automatically read the necessary environment variables from `env.docker` files from project directories.```bashjust up```-5. Point your browser to `http://localhost:50280`. You should be able to see the API documentation.- +5. Point your browser to `http://localhost:50280`. You should be able to see the+ API documentation. 6. Load the sample data. This could take a couple of minutes.+```bashjust init```7. Make an API request using cURL. You should receive a JSON response.+```bashjust stats```- Piping the response through a pretty-printer like [`jq`](https://stedolan.github.io/jq/) should yield an output like the following.+ Piping the response through a pretty-printer like+ [`jq`](https://stedolan.github.io/jq/) should yield an output like the+ following.+```bashjust stats | jq '.[0]'``````json{- "source_name": "flickr",+ "source_name": "flickr","display_name": "Flickr","source_url": "https://www.flickr.com","logo_url": null,@@ -60,13 +76,16 @@ Ensure that you have installed `mkcert` (and the corresponding NSS tools). You c}```-8. When done, bring the system down. To remove all volumes as well, pass the `-v` flag.+8. When done, bring the system down. To remove all volumes as well, pass the+ `-v` flag.+```bashjust downjust down -v # removes volumes```-9. Use the `logs` command access the logs from all services. To isolate a service, pass the service name as an argument.+9. Use the `logs` command access the logs from all services. To isolate a+ service, pass the service name as an argument.```bashjust logsjust logs web # only shows logs web service@@ -90,14 +109,20 @@ The last two are subprojects of this monorepo.## Troubleshooting-If the Elasticsearch container fails to start on your machine, there's a good chance the container ran out of memory. Ensure that you have allocated enough memory to Docker applications and re-run the `just up` command.+If the Elasticsearch container fails to start on your machine, there's a good+chance the container ran out of memory. Ensure that you have allocated enough+memory to Docker applications and re-run the `just up` command.++If the logs mention "insufficient max map count", you may also need to increase+the number of open files allowed on your system. For most Linux machines, you+can fix this by adding the following line to `/etc/sysctl.conf`:-If the logs mention "insufficient max map count", you may also need to increase the number of open files allowed on your system. For most Linux machines, you can fix this by adding the following line to `/etc/sysctl.conf`:```inivm.max_map_count=262144```To make this setting take effect, update kernel state:+```bashsudo sysctl -p```diff --git a/api/docs/guides/run.md b/api/docs/guides/run.mdindex 29f455da8..2a6953d73 100644--- a/api/docs/guides/run.md+++ b/api/docs/guides/run.md@@ -4,7 +4,8 @@### Docker-To run the API inside Docker, follow the instructions in the {doc}`"Quickstart" <./quickstart>` document.+To run the API inside Docker, follow the instructions in the+{doc}`"Quickstart" <./quickstart>` document.### On the host@@ -15,11 +16,13 @@ To run the API inside Docker, follow the instructions in the {doc}`"Quickstart"#### Steps1. Create environment variables from the stencil file.+```bashjust env```2. Install Python dependencies.+```bashjust install```@@ -31,11 +34,16 @@ To run the API inside Docker, follow the instructions in the {doc}`"Quickstart"## Django admin-You can view the custom administration views at the `/admin/` endpoint. You can use the username 'deploy' and password 'deploy' to log in.+You can view the custom administration views at the `/admin/` endpoint. You can+use the username 'deploy' and password 'deploy' to log in.## Configuration-All configuration is performed through environment variables. See the `env.template` file for a comprehensive list of all environment variables. The ones with sane defaults have been commented out.+All configuration is performed through environment variables. See the+`env.template` file for a comprehensive list of all environment variables. The+ones with sane defaults have been commented out.-- Pipenv will automatically load `.env` files when running commands with `pipenv run`.-- Docker Compose will automatically load `.env.docker` files inside the container.+- Pipenv will automatically load `.env` files when running commands with+ `pipenv run`.+- Docker Compose will automatically load `.env.docker` files inside the+ container.diff --git a/api/docs/guides/test.md b/api/docs/guides/test.mdindex 06477d4be..c3412befb 100644--- a/api/docs/guides/test.md+++ b/api/docs/guides/test.md@@ -3,9 +3,11 @@## Docker1. Before running the tests, make sure to initialise the system with data.+```bashjust init```+This step is a part of the {doc}`"Quickstart" <./quickstart>` process.2. Run the tests in an interactive TTY connected to a `web` container.diff --git a/api/docs/index.md b/api/docs/index.mdindex f95808497..5ed85f91e 100644--- a/api/docs/index.md+++ b/api/docs/index.md@@ -1,6 +1,8 @@# Openverse API developer docs-This documentation is focused towards developers who are building the Openverse API. The consumer documentation for the Openverse API can be found [here](https://api.openverse.engineering/).+This documentation is focused towards developers who are building the Openverse+API. The consumer documentation for the Openverse API can be found+[here](https://api.openverse.engineering/).```{toctree}:maxdepth: 2diff --git a/api/docs/reference/api/authentication_and_throttling.md b/api/docs/reference/api/authentication_and_throttling.mdindex 9260b4313..fa17efb91 100644--- a/api/docs/reference/api/authentication_and_throttling.md+++ b/api/docs/reference/api/authentication_and_throttling.md@@ -1,33 +1,79 @@# Authentication and Throttling-This document primarily serves to document our additions to DRF's built-in throttling support. In order to accomplish this, some basic facts about our OAuth flow and configuration must also be explained.+This document primarily serves to document our additions to DRF's built-in+throttling support. In order to accomplish this, some basic facts about our+OAuth flow and configuration must also be explained.-This document deals primarily with the server's perspective of the OAuth flow and assumes you are familiar with the user's perspective. If you are not familiar with the user's perspective, please study the [Register and Authenticate](https://api.openverse.engineering/v1/#section/Register-and-Authenticate) section of the API documentation.+This document deals primarily with the server's perspective of the OAuth flow+and assumes you are familiar with the user's perspective. If you are not+familiar with the user's perspective, please study the+[Register and Authenticate](https://api.openverse.engineering/v1/#section/Register-and-Authenticate)+section of the API documentation.-Furthermore, this section assumes at least a surface level understanding of the `django-oauth-toolkit` library and its concepts. In particular, it is necessary to understand the [`Application` concept, the docs for which can be found here](https://django-oauth-toolkit.readthedocs.io/en/latest/advanced_topics.html#extending-the-application-model).+Furthermore, this section assumes at least a surface level understanding of the+`django-oauth-toolkit` library and its concepts. In particular, it is necessary+to understand the+[`Application` concept, the docs for which can be found here](https://django-oauth-toolkit.readthedocs.io/en/latest/advanced_topics.html#extending-the-application-model).## Flow-When a user makes the initial request to create their OAuth application, we create a `ThrottledApplication` model to associate to the likewise generated OAuth client. Whenever the user generates a new token using their client ID and key pair, it is automatically associated with the `ThrottledApplication` for the client via a [foreign key referencing the application on the access token](https://django-oauth-toolkit.readthedocs.io/en/latest/models.html#oauth2_provider.models.AbstractAccessToken). This allows us to retrieve the application for the token using just the token itself.+When a user makes the initial request to create their OAuth application, we+create a `ThrottledApplication` model to associate to the likewise generated+OAuth client. Whenever the user generates a new token using their client ID and+key pair, it is automatically associated with the `ThrottledApplication` for the+client via a+[foreign key referencing the application on the access token](https://django-oauth-toolkit.readthedocs.io/en/latest/models.html#oauth2_provider.models.AbstractAccessToken).+This allows us to retrieve the application for the token using just the token+itself.## `ThrottledApplication`-The `ThrottledApplication` is an extension of the base `AbstractApplication` class from `django-oauth-toolkit` that adds an additional concept of a `rate_limit_model`. Each rate limit model can be thought of as a "tiers" of rate limiting that the Openverse API supports.+The `ThrottledApplication` is an extension of the base `AbstractApplication`+class from `django-oauth-toolkit` that adds an additional concept of a+`rate_limit_model`. Each rate limit model can be thought of as a "tiers" of rate+limiting that the Openverse API supports.## Rate limit models (tiers)The following tiers exist:-* `standard`: The default rate limit that anyone is able to unlock simply by authenticating. Slightly higher and much more useful limit for an application.-* `enhanced`: A selectively granted rate limit that allows for significantly higher burst and sustained requests.-* `exempt`: A rate limit model that exists purely to accommodate internal infrastructural needs. For example, the server that renders the frontend can use tokens of this tier to prevent itself from being rate limited by the API during server side rendering. Likewise, when we need to circumvent the throttling to do load testing, we use a key of this tier.+- `standard`: The default rate limit that anyone is able to unlock simply by+ authenticating. Slightly higher and much more useful limit for an application.+- `enhanced`: A selectively granted rate limit that allows for significantly+ higher burst and sustained requests.+- `exempt`: A rate limit model that exists purely to accommodate internal+ infrastructural needs. For example, the server that renders the frontend can+ use tokens of this tier to prevent itself from being rate limited by the API+ during server side rendering. Likewise, when we need to circumvent the+ throttling to do load testing, we use a key of this tier.## Throttles-Each of these tiers also have corresponding throttle classes that are configured in `settings.py`. Each throttle class declares a "scope" applied to it. The "scope" defines the rate. The throttle class merely indicates to the view whether it itself applies to the incoming request. If it does not, then it returns a `None` cache key from `get_cache_key` and the view ignores the throttle class. If the throttle does apply to the request, then it returns a formatted cache key that the base DRF view then uses to determine whether the requester is still within the limits of their scope.+Each of these tiers also have corresponding throttle classes that are configured+in `settings.py`. Each throttle class declares a "scope" applied to it. The+"scope" defines the rate. The throttle class merely indicates to the view+whether it itself applies to the incoming request. If it does not, then it+returns a `None` cache key from `get_cache_key` and the view ignores the+throttle class. If the throttle does apply to the request, then it returns a+formatted cache key that the base DRF view then uses to determine whether the+requester is still within the limits of their scope.-To further understand this concept, it may be helpful to read the code for [`SimpleRateThrottle`](https://github.com/encode/django-rest-framework/blob/129890ab1bbbba2deb96b8e30675dfb1060d7615/rest_framework/throttling.py#L50) and the [`check_throttles` method of the DRF base view class](https://github.com/encode/django-rest-framework/blob/101aff6c43f6fa96174683e050988428143d1040/rest_framework/views.py#L352-L371).+To further understand this concept, it may be helpful to read the code for+[`SimpleRateThrottle`](https://github.com/encode/django-rest-framework/blob/129890ab1bbbba2deb96b8e30675dfb1060d7615/rest_framework/throttling.py#L50)+and the+[`check_throttles` method of the DRF base view class](https://github.com/encode/django-rest-framework/blob/101aff6c43f6fa96174683e050988428143d1040/rest_framework/views.py#L352-L371).-Each of the tiers above have their own scope namespace. For example, enhanced applications will use the scopes namespaced with `enhanced_oauth2_client_credentials`. To determine which scope a given authenticated request should have applied to it, we need to determine which application rate limit tier it belongs to. To simplify this abstract process, we use the `OAuth2IdRateThrottle` base class. All it does is take an incoming authenticated request, retrieve the application for the given access token, and then create a cache key based on the client ID and scope if the class is configured to handle the application's rate limit tier.+Each of the tiers above have their own scope namespace. For example, enhanced+applications will use the scopes namespaced with+`enhanced_oauth2_client_credentials`. To determine which scope a given+authenticated request should have applied to it, we need to determine which+application rate limit tier it belongs to. To simplify this abstract process, we+use the `OAuth2IdRateThrottle` base class. All it does is take an incoming+authenticated request, retrieve the application for the given access token, and+then create a cache key based on the client ID and scope if the class is+configured to handle the application's rate limit tier.-Individual tiers have complementary subclasses of `OAuth2IdRateThrottle` that configure which scope to apply to a particular rate limit tier. Please refer to the `catalog.api.utils.throttle` module for example implementations of this pattern.+Individual tiers have complementary subclasses of `OAuth2IdRateThrottle` that+configure which scope to apply to a particular rate limit tier. Please refer to+the `catalog.api.utils.throttle` module for example implementations of this+pattern.diff --git a/api/docs/terms_of_service.md b/api/docs/terms_of_service.mdindex 3fc1357c8..f3046914a 100644--- a/api/docs/terms_of_service.md+++ b/api/docs/terms_of_service.md@@ -4,44 +4,71 @@ _Effective as of 5 May 2022_## 1. Your Agreement to the Terms-Thank you for using the Openverse Catalog application programming interface (“Openverse API”).-BY USING THE OPENVERSE API, YOU ACKNOWLEDGE THAT YOU HAVE READ, UNDERSTOOD, AND AGREED TO BE BOUND BY THESE API TERMS OF USE (hereafter, “API Terms”).-By using the Openverse API, you also represent that you have the legal authority to accept the API Terms on behalf of yourself and any party you represent in connection with your use of the Openverse API.-If you do not agree to the API Terms, you are not authorized to use the Openverse API.+Thank you for using the Openverse Catalog application programming interface+(“Openverse API”). BY USING THE OPENVERSE API, YOU ACKNOWLEDGE THAT YOU HAVE+READ, UNDERSTOOD, AND AGREED TO BE BOUND BY THESE API TERMS OF USE (hereafter,+“API Terms”). By using the Openverse API, you also represent that you have the+legal authority to accept the API Terms on behalf of yourself and any party you+represent in connection with your use of the Openverse API. If you do not agree+to the API Terms, you are not authorized to use the Openverse API.## 2. Licensed Uses and RestrictionsIn connection with your use of the Openverse API:- - You must adhere to all rate limits, registration requirements, and comply with all requirements in the Openverse API documentation;- - You must not scrape the content in the Openverse Catalog;- - You must not use multiple machines to circumvent rate limits or otherwise take measures to bypass our technical or security measures;- - You must not operate in a way that negatively affects other users of the API or impedes the WordPress Foundation's ability to provide its services;- - You must respect and comply with the terms and conditions applicable to the content and metadata accessible through the Openverse API, including by providing proper attribution to [CC-licensed](https://creativecommons.org/licenses/) works and respecting the terms and conditions of platforms hosting CC-licensed works.- - You must not, and the products you develop must not, encourage others to violate any laws, regulations, or rights of any other person or entity, including intellectual property rights.+- You must adhere to all rate limits, registration requirements, and comply with+ all requirements in the Openverse API documentation;+- You must not scrape the content in the Openverse Catalog;+- You must not use multiple machines to circumvent rate limits or otherwise take+ measures to bypass our technical or security measures;+- You must not operate in a way that negatively affects other users of the API+ or impedes the WordPress Foundation's ability to provide its services;+- You must respect and comply with the terms and conditions applicable to the+ content and metadata accessible through the Openverse API, including by+ providing proper attribution to+ [CC-licensed](https://creativecommons.org/licenses/) works and respecting the+ terms and conditions of platforms hosting CC-licensed works.+- You must not, and the products you develop must not, encourage others to+ violate any laws, regulations, or rights of any other person or entity,+ including intellectual property rights.## 3. Content and Data Available through the API-The Openverse API aggregates metadata about openly licensed content hosted on websites managed by third parties.-Openverse does not own or control the content or data made available through the API, and does not verify its licensing status or make any representations or warranties about the content or data whatsoever.-You are responsible for independently verifying whether you have the right to use the content and data and what terms and conditions apply to your use.+The Openverse API aggregates metadata about openly licensed content hosted on+websites managed by third parties. Openverse does not own or control the content+or data made available through the API, and does not verify its licensing status+or make any representations or warranties about the content or data whatsoever.+You are responsible for independently verifying whether you have the right to+use the content and data and what terms and conditions apply to your use.## 4. Openverse Trademark Use-If you develop an application or other product or service using the Openverse API, you must prominently indicate that it was made using the Openverse API but is not endorsed or certified by Openverse.-You must comply with the [WordPress Foundation Trademark Policy](https://wordpressfoundation.org/trademark-policy/) for all use of the Openverse/WordPress logos and other trademarks.+If you develop an application or other product or service using the Openverse+API, you must prominently indicate that it was made using the Openverse API but+is not endorsed or certified by Openverse. You must comply with the+[WordPress Foundation Trademark Policy](https://wordpressfoundation.org/trademark-policy/)+for all use of the Openverse/WordPress logos and other trademarks.## 5. Fees-To help ensure the sustainability of the Openverse project, Openverse reserves the right to charge fees for commercial uses of the Openverse API and/or for heavy usage that places more of a burden on the financial supporters of the WordPress Foundation and the maintainers of its systems.+To help ensure the sustainability of the Openverse project, Openverse reserves+the right to charge fees for commercial uses of the Openverse API and/or for+heavy usage that places more of a burden on the financial supporters of the+WordPress Foundation and the maintainers of its systems.## 6. Changes to the Terms-Openverse is actively developing its product vision and strategy and may limit access to, and/or change the terms that apply to, the Openverse API at any time as plans take shape.-If we make changes that we feel are material, we will make reasonable efforts to update developers who we know are actively using the Openverse API.-Your continued use of the Openverse API after new and/or revised API Terms are effective indications that you have read, understood, and agreed to those terms.+Openverse is actively developing its product vision and strategy and may limit+access to, and/or change the terms that apply to, the Openverse API at any time+as plans take shape. If we make changes that we feel are material, we will make+reasonable efforts to update developers who we know are actively using the+Openverse API. Your continued use of the Openverse API after new and/or revised+API Terms are effective indications that you have read, understood, and agreed+to those terms.## 7. Termination-Openverse may modify, suspend, or terminate the operation of, or access to, the Openverse API at any time for any reason.-Additionally, your individual access to, and use of, the Openverse API may be terminated by Openverse at any time and for any reason.+Openverse may modify, suspend, or terminate the operation of, or access to, the+Openverse API at any time for any reason. Additionally, your individual access+to, and use of, the Openverse API may be terminated by Openverse at any time and+for any reason.diff --git a/ingestion_server/README.md b/ingestion_server/README.mdindex d59d0bacc..9bde58b0f 100644--- a/ingestion_server/README.md+++ b/ingestion_server/README.md@@ -2,12 +2,16 @@## Introduction-Ingestion Server is a small private API for copying data from an upstream source and loading it into the Openverse API. This is a two-step process:+Ingestion Server is a small private API for copying data from an upstream source+and loading it into the Openverse API. This is a two-step process:-1. The data is copied from the upstream catalog database and into the downstream API database.+1. The data is copied from the upstream catalog database and into the downstream+ API database.2. Data from the downstream API database gets indexed in Elasticsearch.-Performance is dependent on the size of the target Elasticsearch cluster, database throughput, and bandwidth available to the ingestion server. The primary bottleneck is indexing to Elasticsearch.+Performance is dependent on the size of the target Elasticsearch cluster,+database throughput, and bandwidth available to the ingestion server. The+primary bottleneck is indexing to Elasticsearch.## How indexing works@@ -15,28 +19,36 @@ Performance is dependent on the size of the target Elasticsearch cluster, databa## Safety and security considerations-The server has been designed to fail gracefully in the event of network interruptions, full disks, etc. If a task fails to complete successfully, the whole process is rolled back with zero impact to production.+The server has been designed to fail gracefully in the event of network+interruptions, full disks, etc. If a task fails to complete successfully, the+whole process is rolled back with zero impact to production.-The server is designed to be run in a private network only. You must not expose the private Ingestion Server API to the public internet.+The server is designed to be run in a private network only. You must not expose+the private Ingestion Server API to the public internet.## Notifications-If a `SLACK_WEBHOOK` variable is provided, the ingestion server will provide periodic updates on the progress of a data refresh, or relay any errors that may occur during the process.+If a `SLACK_WEBHOOK` variable is provided, the ingestion server will provide+periodic updates on the progress of a data refresh, or relay any errors that may+occur during the process.## Data refresh limit-The `DATA_REFRESH_LIMIT` variable can be used to define a limit to the number of rows pulled from the upstream-catalog database. If the server is running in an `ENVIRONMENT` that is not `prod` or `production`, this is-automatically set to 100k records.+The `DATA_REFRESH_LIMIT` variable can be used to define a limit to the number of+rows pulled from the upstream catalog database. If the server is running in an+`ENVIRONMENT` that is not `prod` or `production`, this is automatically set to+100k records.## Running on the host1. Create environment variables from the template file.+```bashjust env```2. Install Python dependencies.+```bashjust install```@@ -50,12 +62,14 @@ automatically set to 100k records.### Integration Tests-The integration tests can be run using `just ing-testlocal`.-Note that if a `.env` file exists in the folder you're running `just` from, it may interfere with the integration test variables and cause unexpected failures.+The integration tests can be run using `just ing-testlocal`. Note that if a+`.env` file exists in the folder you're running `just` from, it may interfere+with the integration test variables and cause unexpected failures.### Making requestsTo make cURL requests to the server+```bashpipenv run \curl \@@ -70,17 +84,25 @@ will be `"INGEST_UPSTREAM"`.## Configuration-All configuration is performed through environment variables. See the `env.template` file for a comprehensive list of all environment variables. The ones with sane defaults have been commented out.+All configuration is performed through environment variables. See the+`env.template` file for a comprehensive list of all environment variables. The+ones with sane defaults have been commented out.-Pipenv will automatically load `.env` files when running commands with `pipenv run`.+Pipenv will automatically load `.env` files when running commands with+`pipenv run`.## Mapping database tables to Elasticsearch-In order to synchronize a given table to Elasticsearch, the following requirements must be met:+In order to synchronize a given table to Elasticsearch, the following+requirements must be met:-- The database table must have an autoincrementing integer primary key named `id`.-- A SyncableDoctype must be defined in `es_syncer/elasticsearch_models`. The SyncableDoctype must implement the function `database_row_to_elasticsearch_model`.-- The table name must be mapped to the corresponding Elasticsearch SyncableDoctype in `database_table_to_elasticsearch_model` map.+- The database table must have an autoincrementing integer primary key named+ `id`.+- A SyncableDoctype must be defined in `es_syncer/elasticsearch_models`. The+ SyncableDoctype must implement the function+ `database_row_to_elasticsearch_model`.+- The table name must be mapped to the corresponding Elasticsearch+ SyncableDoctype in `database_table_to_elasticsearch_model` map.Example from `es_syncer/elasticsearch_models.py`:@@ -133,9 +155,18 @@ database_table_to_elasticsearch_model = {## Deployment-This codebase is deployed as a Docker image to the GitHub Container Registry [ghcr.io](https://ghcr.io). The deployed image is then pulled in the production environment. See the [`ci_cd.yml`](../.github/workflows/ci_cd.yml) workflow for deploying to GHCR.--The published image can be deployed using the minimal [`docker-compose.yml`](docker-compose.yml) file defined in this folder (do not forget to update the `.env` file for production). The repository `justfile` can be used, but the environment variable `IS_PROD` must be set to `true` in order for it to reference the production `docker-compose.yml` file here. The version of the image to use can also be explicitly defined using the `IMAGE_TAG` environment variable (e.g. `IMAGE_TAG=v2.1.1`).+This codebase is deployed as a Docker image to the GitHub Container Registry+[ghcr.io](https://ghcr.io). The deployed image is then pulled in the production+environment. See the [`ci_cd.yml`](../.github/workflows/ci_cd.yml) workflow for+deploying to GHCR.++The published image can be deployed using the minimal+[`docker-compose.yml`](docker-compose.yml) file defined in this folder (do not+forget to update the `.env` file for production). The repository `justfile` can+be used, but the environment variable `IS_PROD` must be set to `true` in order+for it to reference the production `docker-compose.yml` file here. The version+of the image to use can also be explicitly defined using the `IMAGE_TAG`+environment variable (e.g. `IMAGE_TAG=v2.1.1`).### Old Docker Hub imagesdiff --git a/prettier.config.js b/prettier.config.jsindex b48775a1a..7b0c36b47 100644--- a/prettier.config.js+++ b/prettier.config.js@@ -3,15 +3,16 @@// - https://github.com/WordPress/openverse/blob/main/prettier.config.js.jinjamodule.exports = {- trailingComma: 'es5',+ trailingComma: "es5",tabWidth: 2,semi: false,- singleQuote: true,+ singleQuote: false,+ proseWrap: "always",overrides: [{- files: '*.yml',+ files: "*.yml",options: {- singleQuote: false,+ proseWrap: "preserve",},},],diff --git a/readme_assets/system_diagram/README.md b/readme_assets/system_diagram/README.mdindex f9e5b9a61..32b17f6af 100644--- a/readme_assets/system_diagram/README.md+++ b/readme_assets/system_diagram/README.md@@ -1,3 +1,4 @@The diagram was made using [draw.io](https://app.diagrams.net/).-The [system_architecure.xml](system_architecture.xml) file will allow you to restore, and edit it on the above-mentioned platform.+The [system_architecure.xml](system_architecture.xml) file will allow you to+restore, and edit it on the above-mentioned platform.