From bbc10c5a682cb24b9b482f866da870979d42c9f8 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Tue, 22 Jan 2019 21:39:04 -0500 Subject: [PATCH] Remove unused TokenProvider code (#2844) The TokenProvider abstraction was refactored away during #1205 and is now obsolete. Other users of token pooling should use TokenPool and TokenPersistence directly. --- core/token-pooling/token-provider.js | 66 ----------------------- core/token-pooling/token-provider.spec.js | 21 -------- 2 files changed, 87 deletions(-) delete mode 100644 core/token-pooling/token-provider.js delete mode 100644 core/token-pooling/token-provider.spec.js diff --git a/core/token-pooling/token-provider.js b/core/token-pooling/token-provider.js deleted file mode 100644 index 95d40269e3..0000000000 --- a/core/token-pooling/token-provider.js +++ /dev/null @@ -1,66 +0,0 @@ -'use strict' - -const { Token, TokenPool } = require('./token-pool') - -class StaticTokenProvider { - constructor({ tokenValidator, tokenString }) { - if (typeof tokenValidator !== 'function') { - throw Error('tokenValidator is not a function') - } - if (!tokenValidator(tokenString)) { - throw Error(`Not a valid token: ${tokenString}`) - } - - this.staticToken = new Token(tokenString, null) - } - - addToken() { - throw Error( - 'When using token persistence, do not provide a static gh_token' - ) - } - - nextToken() { - return this.staticToken - } -} - -class PoolingTokenProvider { - /* - tokenValidator: A function which returns true if the argument is a valid token. - */ - constructor({ tokenValidator, batchSize = 25 }) { - if (typeof tokenValidator !== 'function') { - throw Error('tokenValidator is not a function') - } - - this.tokenValidator = tokenValidator - this.tokenPool = new TokenPool({ batchSize }) - } - - addToken(tokenString) { - if (!this.tokenValidator(tokenString)) { - throw Error(`Not a valid token: ${tokenString}`) - } - - this.tokenPool.add(tokenString) - } - - nextToken() { - return this.tokenPool.next() - } - - // Return an array of token strings. - toNative() { - return this.tokenPool.allValidTokenIds() - } - - serializeDebugInfo(options) { - return this.tokenPool.serializeDebugInfo(options) - } -} - -module.exports = { - StaticTokenProvider, - PoolingTokenProvider, -} diff --git a/core/token-pooling/token-provider.spec.js b/core/token-pooling/token-provider.spec.js deleted file mode 100644 index 2647a785f3..0000000000 --- a/core/token-pooling/token-provider.spec.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict' - -const assert = require('assert') -const { PoolingTokenProvider } = require('./token-provider') -const isValidGithubToken = require('../../services/github/auth/is-valid-token') - -describe('The token provider', function() { - describe('toNative', function() { - it('should return the expected value', function() { - const tokens = ['1', '2', '3', '4', '5'].map(c => c.repeat(40)) - const provider = new PoolingTokenProvider({ - tokenValidator: isValidGithubToken, - }) - tokens.forEach(t => provider.addToken(t)) - assert.deepStrictEqual( - provider.toNative().sort(), - Array.from(tokens).sort() - ) - }) - }) -})