Skip to content
This repository has been archived by the owner. It is now read-only.

Split out fxa-basket-proxy into a standalone project. #2

Merged
merged 1 commit into from Sep 23, 2015

Conversation

@rfk
Copy link
Member

@rfk rfk commented Sep 10, 2015

This commit imports the fxa-basket-proxy code from [1] as a standalone
project, splitting it up into smaller chunks and adding some basic
repo infrastructure and tests. The logic of the code itself is unchanged
apart from some config-loading and logging tweaks.

[1] https://github.com/mozilla/fxa-content-server/blob/13a59b2457d373190f1853c513604a5b72bb5106/server/bin/basket-proxy-server.js

@rfk
Copy link
Member Author

@rfk rfk commented Sep 10, 2015

I'm opening this for anyone who'd like to give it an initial look-over to offer feedback, but will continue to work on it a little until I'm happy with the over all shape. @shane-tomlinson and/or @jrgm any thoughts on the proposed split-out from content-server repo?

@rfk rfk self-assigned this Sep 10, 2015
@rfk rfk added this to the FxA-44: journeybuilder events milestone Sep 10, 2015
@jrgm
Copy link
Contributor

@jrgm jrgm commented Sep 10, 2015

Looks good. I have one question: is the intent to run this on the same instances as fxa-content-server, or as a separate service? I'd prefer the former.

@rfk
Copy link
Member Author

@rfk rfk commented Sep 10, 2015

is the intent to run this on the same instances as fxa-content-server, or as a separate service?

Your call :-)

Running on the same instances sounds fine to me. In that case, would it make sense for it to continue sharing the same .json config file as the main content-server process? (I changed a few things in the config-file handling to be more consistent with the way other backend services to them, but can easily change back for compatibility).

I think we should also move the basket SQS consumer from [1] into this repo, to keep all the basket stuff together. But that just pulls things off a queue and posts them to an endpoint, so ISTM there should be no problem moving that to the content-server instances as well if necessary.

[1] https://github.com/mozilla/fxa-auth-server/blob/master/bin/basket.js

- Your patch should include new tests that cover your changes. It is your and your reviewer's responsibility to ensure your patch includes adequate tests.

When submitting a PR:
- You agree to license your code under the project's open source license ([MPL 2.0](/LICENSE)).

This comment has been minimized.

@pdehaan

pdehaan Sep 10, 2015

I think we need to add a /LICENSE file.

This comment has been minimized.

module.exports = function (grunt) {
grunt.config('bump', {
options: {
files: [ 'package.json', 'npm-shrinkwrap.json' ],

This comment has been minimized.

@pdehaan

pdehaan Sep 10, 2015

Not sure if we have a shrinkwrap file in this repo [yet].

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Sep 22, 2015
Member

It looks like @rfk has added it.

'<%= eslint.files %>'
],
options: {
config: '.jscsrc',

This comment has been minimized.

@pdehaan

pdehaan Sep 10, 2015

We may need to copy over the .jscsrc file as well. ¯_(ツ)_/¯

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Sep 22, 2015
Member

@rfk - @pdehaan is correct, there is no .jscsrc file in the repo.

This comment has been minimized.

@rfk

rfk Sep 23, 2015
Author Member

Ugh, it was being ignored by the .gitignore so didn't get checked in, I've added it now

return {
status: 'error',
desc: String(desc),
code: code || module.exports.UNKNOWN_ERROR

This comment has been minimized.

@pdehaan

pdehaan Sep 10, 2015

module.exports.errors.UNKNOWN_ERROR?

.tmp/**
app/bower_components/**
app/scripts/vendor/**
dist/**

This comment has been minimized.

@pdehaan

pdehaan Sep 10, 2015

I don't know if any of these paths apply to this repo. We may be able to nuke this file.


| TASK | DESCRIPTION |
|------|-------------|
| `grunt lint` | run ESLint, JSONLint, and JSCS (code style checker) on the code. |

This comment has been minimized.

@pdehaan

pdehaan Sep 10, 2015

Technically I don't think we're using JSONLint anywhere here.


Before submitting a PR:
- Your code must run and pass all the automated tests before you submit your PR for review. "Work in progress" pull requests are allowed to be submitted, but should be clearly labeled as such and should not be merged until all tests pass and the code has been reviewed.
- Run `grunt eslint` to make sure your code passes linting.

This comment has been minimized.

@pdehaan

pdehaan Sep 10, 2015

We should probably generic this down to grunt lint (which runs ESLint and JSCS; https://github.com/mozilla/fxa-basket-proxy/pull/2/files#diff-04c6e90faac2675aa89e2176d2eec7d8R25)

@@ -0,0 +1,33 @@
# Firefox Accounts Basket Proxy

[![Build Status: Travis](https://travis-ci.org/mozilla/fxa-basket-proxy.svg?branch=master)](https://travis-ci.org/mozilla/fxa-basket-proxy)

This comment has been minimized.

@pdehaan

pdehaan Sep 10, 2015

I think I enabled Travis-CI for this repo, but not sure how to set up coveralls below.

grunt.registerTask('lint', 'lint all the things', SUBTASKS);
grunt.registerTask('quicklint', 'lint the modified files', SUBTASKS.map(function (task) {
return 'newer:' + task;
}));

This comment has been minimized.

@pdehaan

pdehaan Sep 10, 2015

If we don't plan on using the Git pre-commit hooks in this repo, we can remove the quicklint task and probably remove a dependency or two.

"grunt-nodemon": "^0.4.0",
"grunt-nsp-shrinkwrap": "0.0.3",
"grunt-todo": "0.5.0",
"husky": "0.9.2",

This comment has been minimized.

@pdehaan

pdehaan Sep 10, 2015

If we don't plan on adding git pre-commit hooks to this repo (see #2 (comment)), we can remove the husky and grunt-newer dependencies above.

"mocha-text-cov": "^0.1.0",
"nock": "2.10",
"proxyquire": "1.6.0",
"sinon": "1.15.4",

This comment has been minimized.

@pdehaan

pdehaan Sep 10, 2015

I don't think we're using proxyquire or sinon anywhere in these files.

@rfk
Copy link
Member Author

@rfk rfk commented Sep 10, 2015

@pdehaan ❤️

@pdehaan
Copy link

@pdehaan pdehaan commented Sep 10, 2015

@rfk: To be clear, I add nothing to the conversation. I'm happy to merge this as-is and we can do future nit PRs to smooth the edges.

@rfk
Copy link
Member Author

@rfk rfk commented Sep 10, 2015

No no, I will definitely go through and apply these fixes. It's the sort of stuff that I can no longer notice because I've been shuffling all these files around for too long, and I deliberately pushed it thinking "I bet @pdehaan will notice a bunch of nits in the repo infrastructure" :-)

@rfk rfk force-pushed the initial-import-and-refactor branch Sep 11, 2015
@rfk
Copy link
Member Author

@rfk rfk commented Sep 11, 2015

(force-pushed with @pdehaan nits addressed, and travis does indeed appear to be running it)

@rfk rfk force-pushed the initial-import-and-refactor branch 2 times, most recently Sep 11, 2015
@rfk
Copy link
Member Author

@rfk rfk commented Sep 11, 2015

OK, test coverage up to 95%, I think this is ready for a preliminary r?. @zaach since Shane's PTO this weekend, would you mind giving this a look over?

Concurrently, I'll work on getting it running locally in fxa-local-dev to check that functional tests still pass.

@rfk rfk assigned zaach and unassigned rfk Sep 11, 2015

module.exports = function (grunt) {
// load all grunt tasks based on environment
if (process.env.NODE_ENV && process.env.NODE_ENV === 'production') {

This comment has been minimized.

@pdehaan

pdehaan Sep 11, 2015

Nit: this may need some tweaking as well.
According to lib/config.js, it looks like the NODE_ENV may be "prod", not "production":

var conf = module.exports = convict({
  env: {
    doc: 'The current node.js environment',
    default: 'prod',
    format: [ 'dev', 'test', 'stage', 'prod' ],
    env: 'NODE_ENV'
  },

Not sure if this is worth wrapping in a conf.get('env') === 'prod'; style thing, or maybe we need a better abstraction for determining if we're running in dev/stage/prod environment.

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Sep 22, 2015
Member

@rfk, @pdehaan - this is the same as what is used in the fxa-content-server. Should both be updated to use prod, or should prod be production? The inconsistency makes my head hurt.

This comment has been minimized.

@rfk

rfk Sep 23, 2015
Author Member

I changed lib/config.js to match what's in content-server, so they can share the same config file in deployment.

"env": "prod",
"basket": {
"apiUrl": "https://basket.mozilla.org/news"
}

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Sep 16, 2015
Member

Should log.format be changed to heka for production?

"publicUrl": "http://127.0.0.1:1114",
"env": "dev",
"log": {
"format": "pretty",

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Sep 16, 2015
Member

The default is pretty, so this shouldn't be needed.

@@ -0,0 +1,8 @@
{
"publicUrl": "http://127.0.0.1:1114",

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Sep 16, 2015
Member

This is the same as the default value, is it needed?

* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

module.exports = {
version: require('./version'),

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Sep 16, 2015
Member

Can you alphabetize these?

code: res.statusCode,
method: req.method,
path: req.path,
agent: req.headers['user-agent'],

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Sep 16, 2015
Member

Alphabetization would be nice here too.

* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/**

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Sep 16, 2015
Member

We use the core version fetch logic in a couple of repos, think we should extract it into its own library to share?

@rfk
Copy link
Member Author

@rfk rfk commented Sep 19, 2015

Thanks @shane-tomlinson! I've addressed all of your notes, except for the query about CORS * origin and #4 as a follow-up issue. Still to do:

  • make config file format compatible with fxa-content-server
  • integration test with fxa-local-dev
@rfk rfk force-pushed the initial-import-and-refactor branch 3 times, most recently Sep 19, 2015
@rfk rfk assigned shane-tomlinson and unassigned zaach Sep 19, 2015
@rfk rfk force-pushed the initial-import-and-refactor branch Sep 19, 2015
@rfk
Copy link
Member Author

@rfk rfk commented Sep 19, 2015

This seems to be working OK with mozilla/fxa-local-dev#32, I think it's ready for a final r?

!.git*
!.eslint*
!.npmignore
!.travis.yml

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Sep 22, 2015
Member

We would want .gitignore, .eslint, and .travis.yml updates to be noticed, wouldn't we?

This comment has been minimized.

@rfk

rfk Sep 23, 2015
Author Member

Yes, so IIUC this is saying "ignore all dot-files except the ones explicitly named here"

eslintrc: '.eslintrc'
},
files: [
'{,bin/,config/,grunttasks/,lib/**/,test/,test/lib/mocks}*.js'

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Sep 22, 2015
Member

Woah, I've never seen this form.

This comment has been minimized.

@pdehaan

pdehaan Sep 22, 2015

Although, I am mildly curious about that "test/" trickery there and wonder why the glob isn't just "test/**/" (instead of "test/,test/lib/mocks").

This comment has been minimized.

@rfk

rfk Sep 22, 2015
Author Member

test/lib/blanket.js is not our code so I excluded it from the checks, particularly to prevent being nagged about a missing MPL license header. I wonder if this fantastical glob syntax has a way to say "not this file" which would make it clearer...

This comment has been minimized.

@pdehaan

pdehaan Sep 22, 2015

You could try something like:
'{,bin/,config/,grunttasks/,lib/**/,test/**/,!test/lib/blanket}*.js'

Or maybe split it into two things:

'{,bin/,config/,grunttasks/,lib/**/,test/**/}*.js',
'!test/lib/blanket.js'

Or if you're saying it's because of the copyright task, exclude the blanket.js file in grunttasks/copyright.js:

      src: [
        '<%= eslint.files %>',
        '!test/lib/blanket.js'
      ]

This comment has been minimized.

@rfk

rfk Sep 23, 2015
Author Member

exclude the blanket.js file in grunttasks/copyright.js

👍 thank-you your globbiness, I shall follow this path.

api_timeout: {
doc: 'Timeout for talking to the Basket API server, in ms',
format: Number,
default: 5 * 1000 // 5 seconds

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Sep 22, 2015
Member

We talked about using the 5 seconds format in another repo, applicable here?

This comment has been minimized.

@rfk

rfk Sep 23, 2015
Author Member

nice catch, done

var startTime = Date.now();
onFinished(res, function logSummary(err, res) {
var line = {
agent: req.headers['user-agent'],

This comment has been minimized.

@shane-tomlinson

shane-tomlinson Sep 22, 2015
Member

I love that you alphabetized the keys.

@shane-tomlinson
Copy link
Member

@shane-tomlinson shane-tomlinson commented Sep 22, 2015

@rfk - there were a couple of outstanding items that @pdehaan initially brought up. I added a couple of notes, one about the config duration format, and .gitignore. All content server functional tests pass when using this repo from fxa-local-dev.

Once the few nits are either explicitly ignored or taken care of, merge away!

@rfk rfk force-pushed the initial-import-and-refactor branch 2 times, most recently Sep 23, 2015
This commit imports the fxa-basket-proxy code from [1] as a standalone
project, splitting it up into smaller chunks and adding some basic
repo infrastructure and tests.  The logic of the code itself is unchanged
apart from some config-loading and logging tweaks.

[1] https://github.com/mozilla/fxa-content-server/blob/13a59b2457d373190f1853c513604a5b72bb5106/server/bin/basket-proxy-server.js
@rfk rfk force-pushed the initial-import-and-refactor branch to 9cffaf4 Sep 23, 2015
@rfk
Copy link
Member Author

@rfk rfk commented Sep 23, 2015

Thanks @shane-tomlinson @pdehaan! Nits addressed, will merge when travis gives the final green light.

rfk added a commit that referenced this pull request Sep 23, 2015
Split out fxa-basket-proxy into a standalone project; r=shane-tomlinson
@rfk rfk merged commit b230ec4 into master Sep 23, 2015
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@rfk rfk removed the waffle:review label Sep 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants