Files
shields/services/github/github-auth-service.js
dependabot-preview[bot] 294aa1e1df Build(deps-dev): bump eslint-plugin-import from 2.17.3 to 2.18.0; autofixes (#3671)
* Build(deps-dev): bump eslint-plugin-import from 2.17.3 to 2.18.0

Bumps [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) from 2.17.3 to 2.18.0.
- [Release notes](https://github.com/benmosher/eslint-plugin-import/releases)
- [Changelog](https://github.com/benmosher/eslint-plugin-import/blob/master/CHANGELOG.md)
- [Commits](https://github.com/benmosher/eslint-plugin-import/compare/v2.17.3...v2.18.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Autofixes
2019-07-08 12:13:46 -04:00

46 lines
1.3 KiB
JavaScript

'use strict'
const { staticAuthConfigured } = require('./github-helpers')
const { BaseJsonService } = require('..')
function createRequestFetcher(context, config) {
const { sendAndCacheRequestWithCallbacks, githubApiProvider } = context
return async (url, { qs }) =>
githubApiProvider.requestAsPromise(
sendAndCacheRequestWithCallbacks,
url,
qs
)
}
class GithubAuthService extends BaseJsonService {
constructor(context, config) {
super(context, config)
this._requestFetcher = createRequestFetcher(context, config)
this.staticAuthConfigured = true
}
}
// Use Github auth, but only when static auth is configured. By using this
// class, in production it will behave like GithubAuthService, and in self-
// hosting (i.e. with a configured token) like BaseJsonService. This is
// useful when consuming GitHub endpoints which are not rate-limited: it
// avoids wasting API quota on them in production.
class ConditionalGithubAuthService extends BaseJsonService {
constructor(context, config) {
super(context, config)
if (staticAuthConfigured()) {
this._requestFetcher = createRequestFetcher(context, config)
this.staticAuthConfigured = true
} else {
this.staticAuthConfigured = false
}
}
}
module.exports = {
GithubAuthService,
ConditionalGithubAuthService,
}