report token used for potential auth issues

This commit is contained in:
Jeff McAffer 2016-12-11 13:40:15 -08:00
Родитель e066dcb699
Коммит 2d8b44feba
1 изменённых файлов: 10 добавлений и 1 удалений

Просмотреть файл

@ -10,6 +10,7 @@ class GitHubFetcher {
this.tokenFactory = tokenFactory; this.tokenFactory = tokenFactory;
this.options = options; this.options = options;
this.logger = options.logger; this.logger = options.logger;
this.options.reconfigure = this.reconfigure.bind(this);
this.getQueue = async.queue(this._callGitHubTask.bind(this), options.concurrency || 5); this.getQueue = async.queue(this._callGitHubTask.bind(this), options.concurrency || 5);
} }
@ -36,7 +37,7 @@ class GitHubFetcher {
const self = this; const self = this;
const etagPromise = checkEtag ? this.store.etag(request.type, request.url) : Q(null); const etagPromise = checkEtag ? this.store.etag(request.type, request.url) : Q(null);
return etagPromise.then(etag => { return etagPromise.then(etag => {
this._getFromGitHub(request, etag).then(githubResponse => { return this._getFromGitHub(request, etag).then(githubResponse => {
const status = githubResponse.statusCode; const status = githubResponse.statusCode;
if (status !== 200 && status !== 304) { if (status !== 200 && status !== 304) {
if (status === 409 || status === 204) { if (status === 409 || status === 204) {
@ -85,6 +86,11 @@ class GitHubFetcher {
if (error) { if (error) {
return deferred.reject(error); return deferred.reject(error);
} }
// If response indicates something that may be related to Auth, note the token used
if ([401, 403, 404].includes(response.statusCode)) {
const token = options.headers.authorization.slice(6);
request.addMeta({ token: `${token.slice(0, 2)}..${token.slice(-2)}` });
}
request.addMeta({ status: response.statusCode, fetch: Date.now() - start }); request.addMeta({ status: response.statusCode, fetch: Date.now() - start });
deferred.resolve(response); deferred.resolve(response);
}); });
@ -187,7 +193,10 @@ class GitHubFetcher {
const result = { const result = {
orgs: { tokenTraits: ['admin'] }, orgs: { tokenTraits: ['admin'] },
org: { tokenTraits: ['admin'] }, org: { tokenTraits: ['admin'] },
repos: { tokenTraits: ['admin'] },
repo: { tokenTraits: ['admin'] },
teams: { tokenTraits: ['admin'] }, teams: { tokenTraits: ['admin'] },
team: { tokenTraits: ['admin'] },
members: { tokenTraits: ['admin'] }, members: { tokenTraits: ['admin'] },
collaborators: { tokenTraits: ['push'] }, collaborators: { tokenTraits: ['push'] },
reactions: { headers: { Accept: 'application/vnd.github.squirrel-girl-preview' } }, reactions: { headers: { Accept: 'application/vnd.github.squirrel-girl-preview' } },