forked from mozilla/firefox-health-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue mozilla#39 - Add Nimbledroid endpoint
* Add documentation to enable Nimbledroid fetching * Heroku review app configuration changes to copy Nimbledroid env variables * Add /api/android/nimbledroid endpoint * Add central configuration file * Add Nimbledroid tests
- Loading branch information
Showing
7 changed files
with
1,094 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import fetchJson from '../../fetch/json'; | ||
import config from '../../configuration'; | ||
|
||
const apiUrl = product => `${config.nimbledroidApiUrl}.${product}/apks`; | ||
|
||
const generateAuthKey = (email, apiKey) => ( | ||
Buffer.from(`${email}:${apiKey}`).toString('base64') | ||
); | ||
|
||
// It makes the data smaller (from 1.66mb to 1.23mb) | ||
const removeConsoleMessage = nimbledroidData => ( | ||
nimbledroidData.map((run) => { | ||
delete run.console_message; | ||
return run; | ||
}) | ||
); | ||
|
||
class NimbledroidHandler { | ||
constructor(apiKey, email) { | ||
if (!apiKey || !email) { | ||
throw Error('You need to instantiate with an apiKey and email address.'); | ||
} | ||
this.apiKey = apiKey; | ||
this.email = email; | ||
} | ||
|
||
async getNimbledroidData(product) { | ||
return removeConsoleMessage(await this.fetchData(product)); | ||
} | ||
|
||
async fetchData(product, buildId) { | ||
return fetchJson( | ||
apiUrl(product, buildId), | ||
{ method: 'GET', headers: this.generateAuthHeaders() }, | ||
); | ||
} | ||
|
||
generateAuthHeaders() { | ||
return ({ | ||
Authorization: `Basic ${generateAuthKey(this.email, this.apiKey)}`, | ||
}); | ||
} | ||
} | ||
|
||
export default NimbledroidHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* global afterEach describe, it */ | ||
import fetchMock from 'fetch-mock'; | ||
import superagent from 'supertest'; | ||
import app from '../../src/app'; | ||
import config from '../../src/configuration'; | ||
|
||
const KLAR_DATA = require('../mocks/nimbledroidKlar'); | ||
|
||
const request = () => superagent(app.listen()); | ||
|
||
describe('/android', () => { | ||
const product = 'klar'; | ||
fetchMock.get(`${config.nimbledroidApiUrl}.${product}/apks`, KLAR_DATA); | ||
|
||
describe('GET /api/android/nimbledroid/', () => { | ||
it('should return 400', (done) => { | ||
delete process.env.NIMBLEDROID_EMAIL; | ||
request() | ||
.get('/api/android/nimbledroid/') | ||
.expect(400, done); | ||
}); | ||
|
||
it('should return 400', (done) => { | ||
request() | ||
.get('/api/android/nimbledroid/') | ||
.expect(400, done); | ||
}); | ||
|
||
it('should return 200', (done) => { | ||
request() | ||
.get(`/api/android/nimbledroid/?product=${product}`) | ||
.expect(200, done); | ||
}); | ||
|
||
afterEach(() => { | ||
process.env.NIMBLEDROID_EMAIL = 'nobody@moz.com'; | ||
process.env.NIMBLEDROID_API_KEY = 'foo_bar'; | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.