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.
This commit is contained in:
Paul Melnikow
2019-01-22 21:39:04 -05:00
committed by GitHub
parent cd89a4db9e
commit bbc10c5a68
2 changed files with 0 additions and 87 deletions

View File

@@ -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,
}

View File

@@ -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()
)
})
})
})