From b6e6a79b4f63a0b83ee7350579d2eb7a77f4a0ff Mon Sep 17 00:00:00 2001 From: PyvesB Date: Sat, 24 Apr 2021 11:26:47 +0100 Subject: [PATCH] Deprecate [Bintray] service --- config/custom-environment-variables.yml | 2 - core/server/server.js | 2 - doc/server-secrets.md | 8 -- services/bintray/bintray-downloads.service.js | 115 ------------------ services/bintray/bintray-downloads.spec.js | 47 ------- services/bintray/bintray-downloads.tester.js | 32 ----- services/bintray/bintray-version.service.js | 51 -------- services/bintray/bintray-version.spec.js | 46 ------- services/bintray/bintray-version.tester.js | 33 ----- services/bintray/bintray.service.js | 24 ++++ services/bintray/bintray.tester.js | 22 ++++ 11 files changed, 46 insertions(+), 336 deletions(-) delete mode 100644 services/bintray/bintray-downloads.service.js delete mode 100644 services/bintray/bintray-downloads.spec.js delete mode 100644 services/bintray/bintray-downloads.tester.js delete mode 100644 services/bintray/bintray-version.service.js delete mode 100644 services/bintray/bintray-version.spec.js delete mode 100644 services/bintray/bintray-version.tester.js create mode 100644 services/bintray/bintray.service.js create mode 100644 services/bintray/bintray.tester.js diff --git a/config/custom-environment-variables.yml b/config/custom-environment-variables.yml index b7c73c7864ffc..a5d3747e55047 100644 --- a/config/custom-environment-variables.yml +++ b/config/custom-environment-variables.yml @@ -68,8 +68,6 @@ public: private: azure_devops_token: 'AZURE_DEVOPS_TOKEN' - bintray_user: 'BINTRAY_USER' - bintray_apikey: 'BINTRAY_API_KEY' bitbucket_username: 'BITBUCKET_USER' bitbucket_password: 'BITBUCKET_PASS' bitbucket_server_username: 'BITBUCKET_SERVER_USER' diff --git a/core/server/server.js b/core/server/server.js index cde7fe3c5dfc2..f63c5bb852df8 100644 --- a/core/server/server.js +++ b/core/server/server.js @@ -152,8 +152,6 @@ const publicConfigSchema = Joi.object({ const privateConfigSchema = Joi.object({ azure_devops_token: Joi.string(), - bintray_user: Joi.string(), - bintray_apikey: Joi.string(), discord_bot_token: Joi.string(), drone_token: Joi.string(), gh_client_id: Joi.string(), diff --git a/doc/server-secrets.md b/doc/server-secrets.md index 28c4fbbef6fc4..722726ea71bf1 100644 --- a/doc/server-secrets.md +++ b/doc/server-secrets.md @@ -80,14 +80,6 @@ An Azure DevOps Token (PAT) is required for accessing [private Azure DevOps proj [ado personal access tokens]: https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=vsts#create-personal-access-tokens-to-authenticate-access [ado token scopes]: https://docs.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/oauth?view=vsts#scopes -### Bintray - -- `BINTRAY_USER` (yml: `private.bintray_user`) -- `BINTRAY_API_KEY` (yml: `private.bintray_apikey`) - -The bintray API [requires authentication](https://bintray.com/docs/api/#_authentication) -Create an account and obtain a token from the user profile page. - ### Bitbucket (Cloud) - `BITBUCKET_USER` (yml: `private.bitbucket_username`) diff --git a/services/bintray/bintray-downloads.service.js b/services/bintray/bintray-downloads.service.js deleted file mode 100644 index 8f3ed7520a7d5..0000000000000 --- a/services/bintray/bintray-downloads.service.js +++ /dev/null @@ -1,115 +0,0 @@ -'use strict' - -const Joi = require('joi') -const { metric } = require('../text-formatters') -const { downloadCount } = require('../color-formatters') -const { BaseJsonService } = require('..') - -const schema = Joi.object({ - totalDownloads: Joi.number().required(), -}).required() - -const versionSchema = Joi.object({ - name: Joi.string().required(), -}).required() - -const documentation = ` -

- These badges utilize unofficial Bintray APIs to retrieve download data.
- As such, they may be unstable or intermittently unavailable. -

` - -module.exports = class BintrayDownloads extends BaseJsonService { - static category = 'downloads' - - static route = { - base: 'bintray', - pattern: ':interval(dt)/:subject/:repo/:packageName/:version*', - } - - static auth = { - userKey: 'bintray_user', - passKey: 'bintray_apikey', - authorizedOrigins: ['https://bintray.com'], - } - - static examples = [ - { - title: 'Bintray', - staticPreview: this.render({ downloads: 69000 }), - namedParams: { - interval: 'dt', - subject: 'asciidoctor', - repo: 'maven', - packageName: 'asciidoctorj', - }, - documentation, - }, - { - title: 'Bintray (latest)', - staticPreview: this.render({ version: 'latest', downloads: 69000 }), - namedParams: { - interval: 'dt', - subject: 'asciidoctor', - repo: 'maven', - packageName: 'asciidoctorj', - version: 'latest', - }, - documentation, - }, - { - title: 'Bintray (version)', - staticPreview: this.render({ version: '1.6.0', downloads: 69000 }), - namedParams: { - interval: 'dt', - subject: 'asciidoctor', - repo: 'maven', - packageName: 'asciidoctorj', - version: '1.6.0', - }, - documentation, - }, - ] - - static defaultBadgeData = { label: 'downloads' } - - static render({ version, downloads }) { - return { - label: version ? `downloads@${version}` : 'downloads', - message: metric(downloads), - color: downloadCount(downloads), - } - } - - async fetch({ subject, repo, packageName, version }) { - let actualVersion = version - if (version === 'latest') { - actualVersion = ( - await this._requestJson( - this.authHelper.withBasicAuth({ - schema: versionSchema, - url: `https://bintray.com/api/v1/packages/${subject}/${repo}/${packageName}/versions/_latest`, - }) - ) - ).name - } - return this._requestJson( - this.authHelper.withBasicAuth({ - schema, - url: actualVersion - ? `https://bintray.com/api/ui/version/${subject}/${repo}/${packageName}/${actualVersion}/total_downloads` - : `https://bintray.com/api/ui/package/${subject}/${repo}/${packageName}/total_downloads`, - }) - ) - } - - async handle({ version, subject, repo, packageName }) { - const { totalDownloads } = await this.fetch({ - subject, - repo, - packageName, - version, - }) - return this.constructor.render({ version, downloads: totalDownloads }) - } -} diff --git a/services/bintray/bintray-downloads.spec.js b/services/bintray/bintray-downloads.spec.js deleted file mode 100644 index 28d27f7632242..0000000000000 --- a/services/bintray/bintray-downloads.spec.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict' - -const { expect } = require('chai') -const nock = require('nock') -const { cleanUpNockAfterEach, defaultContext } = require('../test-helpers') -const BintrayDownloads = require('./bintray-downloads.service') - -describe('BintrayDownloads', function () { - describe('auth', function () { - cleanUpNockAfterEach() - - const user = 'admin' - const pass = 'password' - const config = { - private: { - bintray_user: user, - bintray_apikey: pass, - }, - } - - it('sends the auth information as configured', async function () { - const scope = nock('https://bintray.com') - .get('/api/ui/package/asciidoctor/maven/asciidoctorj/total_downloads') - // This ensures that the expected credentials are actually being sent with the HTTP request. - // Without this the request wouldn't match and the test would fail. - .basicAuth({ user, pass }) - .reply(200, { - totalDownloads: 69, - }) - - expect( - await BintrayDownloads.invoke(defaultContext, config, { - interval: 'dt', - subject: 'asciidoctor', - repo: 'maven', - packageName: 'asciidoctorj', - }) - ).to.deep.equal({ - color: 'yellowgreen', - label: 'downloads', - message: '69', - }) - - scope.done() - }) - }) -}) diff --git a/services/bintray/bintray-downloads.tester.js b/services/bintray/bintray-downloads.tester.js deleted file mode 100644 index e4a3c194f7538..0000000000000 --- a/services/bintray/bintray-downloads.tester.js +++ /dev/null @@ -1,32 +0,0 @@ -'use strict' - -const { isMetric } = require('../test-validators') -const t = (module.exports = require('../tester').createServiceTester()) - -t.create('downloads') - .get('/dt/asciidoctor/maven/asciidoctorj.json') - .expectBadge({ - label: 'downloads', - message: isMetric, - }) - -t.create('downloads (not found)') - .get('/dt/asciidoctor/maven/not-a-real-package.json') - .expectBadge({ - label: 'downloads', - message: 'not found', - }) - -t.create('downloads (mocked)') - .get('/dt/asciidoctor/maven/asciidoctorj.json') - .intercept(nock => - nock('https://bintray.com') - .get('/api/ui/package/asciidoctor/maven/asciidoctorj/total_downloads') - .reply(200, { - totalDownloads: 420, - }) - ) - .expectBadge({ - label: 'downloads', - message: '420', - }) diff --git a/services/bintray/bintray-version.service.js b/services/bintray/bintray-version.service.js deleted file mode 100644 index 3e66c5d4b5883..0000000000000 --- a/services/bintray/bintray-version.service.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict' - -const Joi = require('joi') -const { renderVersionBadge } = require('../version') -const { BaseJsonService } = require('..') - -const schema = Joi.object() - .keys({ - name: Joi.string().required(), - }) - .required() - -module.exports = class BintrayVersion extends BaseJsonService { - static category = 'version' - static route = { base: 'bintray/v', pattern: ':subject/:repo/:packageName' } - - static auth = { - userKey: 'bintray_user', - passKey: 'bintray_apikey', - authorizedOrigins: ['https://bintray.com'], - } - - static examples = [ - { - title: 'Bintray', - staticPreview: renderVersionBadge({ version: '1.6.0' }), - namedParams: { - subject: 'asciidoctor', - repo: 'maven', - packageName: 'asciidoctorj', - }, - }, - ] - - static defaultBadgeData = { label: 'bintray' } - - async fetch({ subject, repo, packageName }) { - // https://bintray.com/docs/api/#_get_version - return this._requestJson( - this.authHelper.withBasicAuth({ - schema, - url: `https://bintray.com/api/v1/packages/${subject}/${repo}/${packageName}/versions/_latest`, - }) - ) - } - - async handle({ subject, repo, packageName }) { - const data = await this.fetch({ subject, repo, packageName }) - return renderVersionBadge({ version: data.name }) - } -} diff --git a/services/bintray/bintray-version.spec.js b/services/bintray/bintray-version.spec.js deleted file mode 100644 index 288bcdd4f05b3..0000000000000 --- a/services/bintray/bintray-version.spec.js +++ /dev/null @@ -1,46 +0,0 @@ -'use strict' - -const { expect } = require('chai') -const nock = require('nock') -const { cleanUpNockAfterEach, defaultContext } = require('../test-helpers') -const BintrayVersion = require('./bintray-version.service') - -describe('BintrayVersion', function () { - describe('auth', function () { - cleanUpNockAfterEach() - - const user = 'admin' - const pass = 'password' - const config = { - private: { - bintray_user: user, - bintray_apikey: pass, - }, - } - - it('sends the auth information as configured', async function () { - const scope = nock('https://bintray.com') - .get('/api/v1/packages/asciidoctor/maven/asciidoctorj/versions/_latest') - // This ensures that the expected credentials are actually being sent with the HTTP request. - // Without this the request wouldn't match and the test would fail. - .basicAuth({ user, pass }) - .reply(200, { - name: '1.5.7', - }) - - expect( - await BintrayVersion.invoke(defaultContext, config, { - subject: 'asciidoctor', - repo: 'maven', - packageName: 'asciidoctorj', - }) - ).to.deep.equal({ - label: undefined, - message: 'v1.5.7', - color: 'blue', - }) - - scope.done() - }) - }) -}) diff --git a/services/bintray/bintray-version.tester.js b/services/bintray/bintray-version.tester.js deleted file mode 100644 index a8efe740cc7c9..0000000000000 --- a/services/bintray/bintray-version.tester.js +++ /dev/null @@ -1,33 +0,0 @@ -'use strict' - -const { - isVPlusDottedVersionNClausesWithOptionalSuffix, -} = require('../test-validators') -const t = (module.exports = require('../tester').createServiceTester()) - -t.create('version').get('/asciidoctor/maven/asciidoctorj.json').expectBadge({ - label: 'bintray', - message: isVPlusDottedVersionNClausesWithOptionalSuffix, -}) - -t.create('version (not found)') - .get('/asciidoctor/maven/not-a-real-package.json') - .expectBadge({ - label: 'bintray', - message: 'not found', - }) - -t.create('version (mocked)') - .get('/asciidoctor/maven/asciidoctorj.json') - .intercept(nock => - nock('https://bintray.com') - .get('/api/v1/packages/asciidoctor/maven/asciidoctorj/versions/_latest') - .reply(200, { - name: '1.5.7', - }) - ) - .expectBadge({ - label: 'bintray', - message: 'v1.5.7', - color: 'blue', - }) diff --git a/services/bintray/bintray.service.js b/services/bintray/bintray.service.js new file mode 100644 index 0000000000000..fd19d8e82b39b --- /dev/null +++ b/services/bintray/bintray.service.js @@ -0,0 +1,24 @@ +'use strict' + +const { deprecatedService } = require('..') + +module.exports = [ + deprecatedService({ + category: 'downloads', + route: { + base: 'bintray/dt', + pattern: ':various+', + }, + label: 'bintray', + dateAdded: new Date('2021-04-24'), + }), + deprecatedService({ + category: 'version', + route: { + base: 'bintray/v', + pattern: ':various+', + }, + label: 'bintray', + dateAdded: new Date('2021-04-24'), + }), +] diff --git a/services/bintray/bintray.tester.js b/services/bintray/bintray.tester.js new file mode 100644 index 0000000000000..a16e2413c8ae4 --- /dev/null +++ b/services/bintray/bintray.tester.js @@ -0,0 +1,22 @@ +'use strict' + +const { ServiceTester } = require('../tester') + +const t = (module.exports = new ServiceTester({ + id: 'bintray', + title: 'Bintray', +})) + +t.create('no longer available (previously downloads)') + .get('/dt/asciidoctor/maven/asciidoctorj.json') + .expectBadge({ + label: 'bintray', + message: 'no longer available', + }) + +t.create('no longer available (previously version)') + .get('/v/asciidoctor/maven/asciidoctorj.json') + .expectBadge({ + label: 'bintray', + message: 'no longer available', + })