From 19b50a66a6630ce604df9e8c0ecc56db326c0724 Mon Sep 17 00:00:00 2001 From: chris48s Date: Sun, 19 Nov 2023 19:24:56 +0000 Subject: [PATCH] call [pepy] with auth (#9748) --- .github/actions/service-tests/action.yml | 5 +++++ .github/workflows/deploy-review-app.yml | 1 + .github/workflows/test-services-20.yml | 1 + .github/workflows/test-services.yml | 1 + config/custom-environment-variables.yml | 1 + core/server/server.js | 1 + doc/server-secrets.md | 8 ++++++++ services/pepy/pepy-downloads.service.js | 16 ++++++++++++---- 8 files changed, 30 insertions(+), 4 deletions(-) diff --git a/.github/actions/service-tests/action.yml b/.github/actions/service-tests/action.yml index d6aa6008f9..480ed7abb0 100644 --- a/.github/actions/service-tests/action.yml +++ b/.github/actions/service-tests/action.yml @@ -16,6 +16,10 @@ inputs: description: 'The SERVICETESTS_OBS_PASS secret' required: false default: '' + pepy-key: + description: 'The SERVICETESTS_PEPY_KEY secret' + required: false + default: '' sl-insight-user-uuid: description: 'The SERVICETESTS_SL_INSIGHT_USER_UUID secret' required: false @@ -66,6 +70,7 @@ runs: LIBRARIESIO_TOKENS: '${{ inputs.librariesio-tokens }}' OBS_USER: '${{ inputs.obs-user }}' OBS_PASS: '${{ inputs.obs-pass }}' + PEPY_KEY: '${{ inputs.pepy-key }}' SL_INSIGHT_USER_UUID: '${{ inputs.sl-insight-user-uuid }}' SL_INSIGHT_API_TOKEN: '${{ inputs.sl-insight-api-token }}' TWITCH_CLIENT_ID: '${{ inputs.twitch-client-id }}' diff --git a/.github/workflows/deploy-review-app.yml b/.github/workflows/deploy-review-app.yml index 5e775ce222..f4c69c9a40 100644 --- a/.github/workflows/deploy-review-app.yml +++ b/.github/workflows/deploy-review-app.yml @@ -35,6 +35,7 @@ jobs: LIBRARIESIO_TOKENS=${{ secrets.SERVICETESTS_LIBRARIESIO_TOKENS }} OBS_USER=${{ secrets.SERVICETESTS_OBS_USER }} OBS_PASS=${{ secrets.SERVICETESTS_OBS_PASS }} + PEPY_KEY=${{ secrets.SERVICETESTS_PEPY_KEY }} SL_INSIGHT_API_TOKEN=${{ secrets.SERVICETESTS_SL_INSIGHT_USER_UUID }} SL_INSIGHT_USER_UUID=${{ secrets.SERVICETESTS_SL_INSIGHT_API_TOKEN }} TWITCH_CLIENT_ID=${{ secrets.SERVICETESTS_TWITCH_CLIENT_ID }} diff --git a/.github/workflows/test-services-20.yml b/.github/workflows/test-services-20.yml index 6ddb7f5fa3..adc8f3d247 100644 --- a/.github/workflows/test-services-20.yml +++ b/.github/workflows/test-services-20.yml @@ -29,6 +29,7 @@ jobs: librariesio-tokens: '${{ secrets.SERVICETESTS_LIBRARIESIO_TOKENS }}' obs-user: '${{ secrets.SERVICETESTS_OBS_USER }}' obs-pass: '${{ secrets.SERVICETESTS_OBS_PASS }}' + pepy-key: '${{ secrets.SERVICETESTS_PEPY_KEY }}' sl-insight-user-uuid: '${{ secrets.SERVICETESTS_SL_INSIGHT_USER_UUID }}' sl-insight-api-token: '${{ secrets.SERVICETESTS_SL_INSIGHT_API_TOKEN }}' twitch-client-id: '${{ secrets.SERVICETESTS_TWITCH_CLIENT_ID }}' diff --git a/.github/workflows/test-services.yml b/.github/workflows/test-services.yml index e393b810da..c8022149a3 100644 --- a/.github/workflows/test-services.yml +++ b/.github/workflows/test-services.yml @@ -27,6 +27,7 @@ jobs: librariesio-tokens: '${{ secrets.SERVICETESTS_LIBRARIESIO_TOKENS }}' obs-user: '${{ secrets.SERVICETESTS_OBS_USER }}' obs-pass: '${{ secrets.SERVICETESTS_OBS_PASS }}' + pepy-key: '${{ secrets.SERVICETESTS_PEPY_KEY }}' sl-insight-user-uuid: '${{ secrets.SERVICETESTS_SL_INSIGHT_USER_UUID }}' sl-insight-api-token: '${{ secrets.SERVICETESTS_SL_INSIGHT_API_TOKEN }}' twitch-client-id: '${{ secrets.SERVICETESTS_TWITCH_CLIENT_ID }}' diff --git a/config/custom-environment-variables.yml b/config/custom-environment-variables.yml index 18011390b7..ec769d2eff 100644 --- a/config/custom-environment-variables.yml +++ b/config/custom-environment-variables.yml @@ -96,6 +96,7 @@ private: obs_pass: 'OBS_PASS' redis_url: 'REDIS_URL' opencollective_token: 'OPENCOLLECTIVE_TOKEN' + pepy_key: 'PEPY_KEY' postgres_url: 'POSTGRES_URL' sentry_dsn: 'SENTRY_DSN' sl_insight_userUuid: 'SL_INSIGHT_USER_UUID' diff --git a/core/server/server.js b/core/server/server.js index 1b2870f504..8f92e4fd28 100644 --- a/core/server/server.js +++ b/core/server/server.js @@ -185,6 +185,7 @@ const privateConfigSchema = Joi.object({ obs_pass: Joi.string(), redis_url: Joi.string().uri({ scheme: ['redis', 'rediss'] }), opencollective_token: Joi.string(), + pepy_key: Joi.string(), postgres_url: Joi.string().uri({ scheme: 'postgresql' }), sentry_dsn: Joi.string(), sl_insight_userUuid: Joi.string(), diff --git a/doc/server-secrets.md b/doc/server-secrets.md index 10c88cd12d..1bacce44d6 100644 --- a/doc/server-secrets.md +++ b/doc/server-secrets.md @@ -254,6 +254,14 @@ OpenCollective's GraphQL API only allows 10 reqs/minute for anonymous users. An [API token](https://graphql-docs-v2.opencollective.com/access) can be provided to access a higher rate limit of 100 reqs/minute. +### Pepy + +- `PEPY_KEY` (yml: `pepy_key`) + +The Pepy API requires authentication. To obtain a key, +Create an account, sign in and obtain generate a key on your +[account page](https://www.pepy.tech/user). + ### SymfonyInsight (formerly Sensiolabs) - `SL_INSIGHT_USER_UUID` (yml: `private.sl_insight_userUuid`) diff --git a/services/pepy/pepy-downloads.service.js b/services/pepy/pepy-downloads.service.js index 8fd242c643..bb54c3160f 100644 --- a/services/pepy/pepy-downloads.service.js +++ b/services/pepy/pepy-downloads.service.js @@ -20,6 +20,12 @@ export default class PepyDownloads extends BaseJsonService { pattern: 'dt/:packageName', } + static auth = { + passKey: 'pepy_key', + authorizedOrigins: ['https://api.pepy.tech'], + isRequired: true, + } + static openApi = { '/pepy/dt/{packageName}': { get: { @@ -38,10 +44,12 @@ export default class PepyDownloads extends BaseJsonService { static defaultBadgeData = { label: 'downloads' } async fetch({ packageName }) { - return this._requestJson({ - url: `https://api.pepy.tech/api/v2/projects/${packageName}`, - schema, - }) + return this._requestJson( + this.authHelper.withApiKeyHeader({ + url: `https://api.pepy.tech/api/v2/projects/${packageName}`, + schema, + }), + ) } async handle({ packageName }) {