New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add login command #3558
Add login command #3558
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice @DavidWells 👍 Really looking forward to merge this PR!
I added some comments. It's mostly that some of the functionality could be moved and some utils the Serverless core provides can be used. This way we can remove some utils code in here.
Let me know if you need any help here! 💯
lib/plugins/login/login.js
Outdated
const getFrameworkId = require('../../utils/getFrameworkId'); | ||
const updateConfig = require('../../utils/config/update'); | ||
|
||
const config = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will those values stay hard coded once merged?
Would be nice if they could be set via env
variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is okay for now. We can move to centralized spot once more default config stuff arises
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm I'm super curious about that. Would anyone be able to just copy that into their code and implement their own login? Do we want people logged in outside of the context of the framework?
lib/plugins/login/login.js
Outdated
} | ||
openBrowser(url) { | ||
let browser = process.env.BROWSER; | ||
if (browser === 'none') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this really return none
if not set or something like null
/ undefined
. In my Node REPL it returns undefined
.
lib/plugins/login/login.js
Outdated
opn(url, options).catch(() => {}); | ||
return true; | ||
} catch (err) { | ||
console.log('---------------------------'); // eslint-disable-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could use this.serverless.cli.log
or this.serverless.cli.consoleLog
to get rid of the eslint disables.
waiting on #3558 to merge implement
@brianneisler I don't see the signatures changing much. That would also break all the tests. IMO, We can refactor to mixin approach later if we need it. |
updated the utils class to use util functions
@DavidWells how does that break the tests? |
Changing Params will break tests
… On May 5, 2017, at 3:39 PM, Brian Neisler ***@***.***> wrote:
@DavidWells how does that break the tests?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@DavidWells could we update this to use the rc module. This will give us #3573 out of the box and a host of other goodies. |
Giving ultimate flexibility with where config can live might hurt us later (IE I'd propose a simpler solution for right now. |
Just a quick reminder that now that we should add docs for the login command to the Google docs now that they were merged (see todo-list in: #3365 (comment)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Just couple of comments 😊
lib/classes/Utils.js
Outdated
return false; | ||
} | ||
// console.log('this.serverless.utils.fileExistsSync being depricated in a future release') | ||
// console.log('Please explicitly declare your plugin dependancies') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm why are we deprecating this? and why is it commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be deprecated since we're moving towards a more functional codebase in the future where we can easily test all the different pieces independently w/o having to pass around this huge serverless
object.
I believe those are preparations so that this can be commented out once v2
will be around the corner.
lib/plugins/login/login.js
Outdated
const getFrameworkId = require('../../utils/getFrameworkId'); | ||
const updateConfig = require('../../utils/config/update'); | ||
|
||
const config = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm I'm super curious about that. Would anyone be able to just copy that into their code and implement their own login? Do we want people logged in outside of the context of the framework?
lib/plugins/login/login.js
Outdated
return true; | ||
} catch (err) { | ||
console.log('---------------------------'); // eslint-disable-line | ||
console.log(`🙈 ${chalk.red("Unable to open browser automatically")}`); // eslint-disable-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love that crazy monkey!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side Note: I don't have much experience with emojis on the CLI, but if we can really do that without side effects, we should probably use ⚡️ somewhere in there, maybe replace that ugly Serverless:
prompt on every line.
We'll change the logo soon though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just rendered poorly for people without unicode support (which I'd guesstimate is low)
Serverless: Packaging service…
yarn
uses emojis, I think we can use them too. Looks like they use a package to do so reliably https://github.com/yarnpkg/yarn/blob/cb453f56353016d5c98e4d6a0f4069896b1eef43/src/cli/commands/why.js#L17 . I will look into this
lib/plugins/login/login.js
Outdated
}) | ||
.then((response) => response.json()) | ||
.then((platformResponse) => { | ||
// console.log('data', platformResponse); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this is left out from debugging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea will be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good so far. 👍
Just added some comments while looking through the code.
@@ -0,0 +1,24 @@ | |||
<!-- | |||
title: Serverless Framework Commands - Login | |||
menuText: Login |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we lowercase this so that it follows the new naming schema?
@@ -0,0 +1,24 @@ | |||
<!-- | |||
title: Serverless Framework Commands - Login | |||
menuText: Login |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we lowercase this so that it follows the new naming schema?
@@ -0,0 +1,24 @@ | |||
<!-- | |||
title: Serverless Framework Commands - Login | |||
menuText: Login |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we lowercase this so that it follows the new naming schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes =). Will update
lib/plugins/login/login.js
Outdated
id, | ||
email: decoded.email, | ||
}).then(() => { | ||
// console.log('login complete'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be removed.
lib/plugins/login/login.js
Outdated
}); | ||
}) | ||
.catch(() => { | ||
console.log(chalk.red('Incorrect token value supplied. Please run `serverless login` again')); // eslint-disable-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can wrap serverless login
into "" since the console output won't render markdown (the tildes).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated it. Is that a windows thing?
lib/plugins/logout/logout.js
Outdated
configUtils.set(`users.${currentId}.auth`, null); | ||
// log stat | ||
userStats.track('user_loggedOut').then(() => { | ||
console.log('Successfully logged out.'); // eslint-disable-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best would be if this.serverless.cli.consoleLog
is used.
lib/utils/userStats.js
Outdated
if (DEBUG) { | ||
console.log('.track call', eventData); // eslint-disable-line | ||
} | ||
// return BbPromise.resolve(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed.
lib/utils/userStats.js
Outdated
|
||
const eventData = _.merge(defaultData, data); | ||
if (DEBUG) { | ||
console.log('.track call', eventData); // eslint-disable-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best would be if this.serverless.cli.consoleLog
is used.
const path = require('path'); | ||
const os = require('os'); | ||
const _ = require('lodash'); | ||
const writeFileAtomic = require('write-file-atomic'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to e.g. use some stuff from fs-extra
or any other method already available so that we don't introduce yet another dependency?
Ok. Travis is a liar. The tests are failing. Working on an update... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed a couple of changes and tested the login
/ logout
functionality.
Works like a charm. GTM from my side!
@eahefnawy could you take a second look and merge if everything is fine? @DavidWells changed some stuff in the meantime. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just gave one final review. Looking great! Hopefully we slowly move all our utils to follow this pattern.
Thanks @DavidWells 😊
waiting on #3558 to merge implement
What did you implement:
Adds
serverless login
to the CLI.Running this command optional & is prep work for the upcoming release of the serverless platform.
Additionally, this is part of an ongoing effort to improve the developer experience of the CLI. The
login
command will help us help new developers adopt & use the framework.How did you implement it:
Added
login
commandHow can we verify it:
Run
sls login
, login, grab your token, & insert back into the CLI.Todos:
Is this ready for review?: Yes
Is it a breaking change?: No