Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Conversation

@deeptibaghel
Copy link
Contributor

@deeptibaghel deeptibaghel commented Jul 31, 2018

Fixes #333

@ghost ghost assigned deeptibaghel Jul 31, 2018
@ghost ghost added the waffle:active label Jul 31, 2018
Copy link
Contributor

@vladikoff vladikoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check 'static' in a bit

user: uid,
scope: scope
}}};
return P.fromCallback(cb => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a cb here, should that be removed and function below needs to 'return'?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should check if cache.drop still uses callbacks or not

handler: function avatar(req, reply) {
handler: async function avatar(req) {
var uid = req.auth.credentials.user;
db.getSelectedAvatar(uid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need a 'return'?

})
.then(() => {
notifyProfileUpdated(uid); // Don't wait on promise
return EMPTY;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to check 'EMPTY' vs the {} above

handler: function upload(req, reply) {
handler: async function upload(req, h) {
const uid = req.auth.credentials.user;
req.server.methods.profileCache.drop(uid, () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to return?, also no more callbacks?

url: '/v1/_core_profile',
headers: req.headers,
credentials: req.auth.credentials
}, res => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no callbacks in inject?

cors: true,
security: {
hsts: {
maxAge: 15552000,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we had a different fix for this to make sure these headers are set ?

handler: function heartbeat(req, reply) {
db.ping().done(reply, reply);
handler: async function heartbeat() {
db.ping().then(() => {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return?

server.route(routes);

server.ext('onPreAuth', function (request, reply) {
server.ext('onPreAuth', function (request, h) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these stilp callbacks? need to check..

config: {
handler: function upload(req, reply) {
reply({});
handler: async function upload(req) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function name 'upload' is wrong here, lets fix

const uid = req.auth.credentials.user;
req.server.methods.profileCache.drop(uid, () => {
const payload = req.payload;
db.setDisplayName(uid, payload.displayName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return here as well?

bin/worker.js Outdated
async function start(){
const server = await require('../lib/server/worker').create();

server.start(function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a callback anymore on .start, You need to do await server.start()
and surround it with the a try and catch to throw an error if it fails to .start

bin/worker.js Outdated
server.start(function() {
logger.info('listening', server.info.uri);
});
async function start(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: start() { (space before {

cache: {
expiresIn: options.expiresIn,
generateTimeout: options.generateTimeout
generateTimeout: options.generateTimeout || 100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we change that in the tests instead and should not do this here

Copy link
Contributor Author

@deeptibaghel deeptibaghel Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was throwing error here generateTimeout is required so i added it temporarily

method: 'POST',
path: v('/display_name'),
config: require('./routes/display_name/post')
options: require('./routes/display_name/post')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍

host: config.server.host,
port: config.server.port + 1,
debug: { request: ['error'] }
debug: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm not sure about this change, I wonder what { request: ['error'] } used to do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was originally false only

port: config.server.port,
cache: cache,
debug: false,
debug: { request: ['error'] },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh

// server method for caching profile
try {
await server.register({
name: 'fxa-profile-server',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can call this just profileCache

});

server.ext('onPreResponse', function(request, next) {
server.ext('onPreResponse', function(request, h) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the h here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have h.continue below

@deeptibaghel
Copy link
Contributor Author

@vladikoff still i am missing something :(

bin/_static.js Outdated

async function create() {
const server = await require('../lib/server/_static').create();
server.start().then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use await server.start(); here , move the log out of then. Just like below: https://github.com/mozilla/fxa-profile-server/pull/334/files#diff-8d44631bfd02d64ee75348ab92f466c0R27

return workers.delete(avatar.id);
}
})
req.server.methods.profileCache.drop(uid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this will fail because this doesn't return

// precaution to avoid the default id from being overwritten
assert(id !== DEFAULT_AVATAR_ID);
const url = avatarShared.fxaUrl(id);
workers.upload(id, req.payload, req.headers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also needs to return otherwise response will be lost

})
.done(reply, reply);
});
req.server.methods.profileCache.drop(uid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will fail, no return

req.server.methods.profileCache.drop(uid)
.then(() => {
const payload = req.payload;
db.setDisplayName(uid, payload.displayName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs return here too

switch (request.params.type) {
case '':
reply.file(DEFAULT_AVATAR);
h.file(DEFAULT_AVATAR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we make h.file a return h.file ?

return next(null, result, ttl);
})
.catch(next);
.then(result => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vladikoff , I have fixed the server stop function but it still didn't work. This method seems to be failing.

server.methods.profileCache.get.cache.drop(req, cb);
});
}).asCallback(next);
await server.methods.profileCache.get.cache.drop(req);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vladikoff , this method is not right yet, how do we change it correctly ?

user: uid,
scope: scope
}}};
return await server.methods.profileCache.get.cache.drop(req);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vladikoff this line is throwing a 500 error, am I missing something ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deeptibaghel do you get this when running the tests?

.eslintrc Outdated
semi: [2, "always"]

parserOptions:
ecmaVersion: 2017
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make this 2018 here

lib/config.js Outdated
},
serverCache: {
redis: {
// name: 'redisCache',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens here? is this not named anymore? do we delete it?

const url = avatarShared.fxaUrl(id);
await workers.upload(id, req.payload, req.headers);
await db.addAvatar(id, uid, url, FXA_PROVIDER);
await notifyProfileUpdated(uid); // Don't wait on promise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per // Don't wait on promise , we don't want an await here

})
.done(reply, reply);
});
return req.server.methods.profileCache.drop(uid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are changing the upload.js above to use async await, then we should do it here as well. or we can use the .then structure above. Pick the one you like.

// we should always get an email field back.
if (! res.result.email) {
logger.error('request.auth_server.fail', res.result);
return new AppError({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we throw here?

handler: function index(req, reply) {
function sendReply() {
reply({
// response: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happened here?

user: uid,
scope: scope
}}};
return await server.methods.profileCache.get.cache.drop(req);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deeptibaghel do you get this when running the tests?

scope: scope
}}};
return await server.methods.profileCache.get.cache.drop(req);
return server.methods.profileCache.get.cache.drop(req);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vladikoff the test to upload avatar fails at this point

@shane-tomlinson
Copy link

I'm leaving this PR open because we still want this work! We will need to migrate this to the new mono-repo: github.com/mozilla/fxa

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants