Skip to content
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

Merged
merged 57 commits into from May 24, 2017
Merged

Add login command #3558

merged 57 commits into from May 24, 2017

Conversation

DavidWells
Copy link
Contributor

@DavidWells DavidWells commented May 4, 2017

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 command

How can we verify it:

Run sls login, login, grab your token, & insert back into the CLI.

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config / commands / resources

Is this ready for review?: Yes
Is it a breaking change?: No

pmuens
pmuens previously requested changes May 5, 2017
Copy link
Contributor

@pmuens pmuens left a 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! 💯

const getFrameworkId = require('../../utils/getFrameworkId');
const updateConfig = require('../../utils/config/update');

const config = {
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Member

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?

}
openBrowser(url) {
let browser = process.env.BROWSER;
if (browser === 'none') {
Copy link
Contributor

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.

opn(url, options).catch(() => {});
return true;
} catch (err) {
console.log('---------------------------'); // eslint-disable-line
Copy link
Contributor

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.

DavidWells added a commit that referenced this pull request May 5, 2017
waiting on #3558 to merge implement
@DavidWells
Copy link
Contributor Author

@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.

@DavidWells DavidWells dismissed pmuens’s stale review May 5, 2017 22:28

updated the utils class to use util functions

@brianneisler
Copy link
Contributor

@DavidWells how does that break the tests?

@DavidWells
Copy link
Contributor Author

DavidWells commented May 5, 2017 via email

@pmuens pmuens added this to the 1.14 milestone May 8, 2017
@brianneisler
Copy link
Contributor

@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.

@DavidWells
Copy link
Contributor Author

rc doesnt support our proposed path of ./serverless/.serverlessrc

Giving ultimate flexibility with where config can live might hurt us later (IE rc automagically parses args and people could have conflicting arg keys as one example)

I'd propose a simpler solution for right now. ./serverless/.serverlessrc and local .serverlessrc only. We could expand to other options if people really need other options

@pmuens
Copy link
Contributor

pmuens commented May 11, 2017

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)).

Copy link
Member

@eahefnawy eahefnawy left a 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 😊

return false;
}
// console.log('this.serverless.utils.fileExistsSync being depricated in a future release')
// console.log('Please explicitly declare your plugin dependancies')
Copy link
Member

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?

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 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.

const getFrameworkId = require('../../utils/getFrameworkId');
const updateConfig = require('../../utils/config/update');

const config = {
Copy link
Member

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?

return true;
} catch (err) {
console.log('---------------------------'); // eslint-disable-line
console.log(`🙈 ${chalk.red("Unable to open browser automatically")}`); // eslint-disable-line
Copy link
Member

Choose a reason for hiding this comment

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

love that crazy monkey! ☺️

Copy link
Member

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...

Copy link
Contributor

Choose a reason for hiding this comment

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

I can remember that @nikgraf changed the ... to the unicode representation which "broke" the CLI displaying for some people. So I'm not sure if this is a good idea --> See: #2714

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 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

})
.then((response) => response.json())
.then((platformResponse) => {
// console.log('data', platformResponse);
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea will be removed

Copy link
Contributor

@pmuens pmuens left a 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
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 lowercase this so that it follows the new naming schema?

@@ -0,0 +1,24 @@
<!--
title: Serverless Framework Commands - Login
menuText: Login
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 lowercase this so that it follows the new naming schema?

@@ -0,0 +1,24 @@
<!--
title: Serverless Framework Commands - Login
menuText: Login
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 lowercase this so that it follows the new naming schema?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes =). Will update

id,
email: decoded.email,
}).then(() => {
// console.log('login complete');
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be removed.

});
})
.catch(() => {
console.log(chalk.red('Incorrect token value supplied. Please run `serverless login` again')); // eslint-disable-line
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 wrap serverless login into "" since the console output won't render markdown (the tildes).

Copy link
Contributor Author

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?

configUtils.set(`users.${currentId}.auth`, null);
// log stat
userStats.track('user_loggedOut').then(() => {
console.log('Successfully logged out.'); // eslint-disable-line
Copy link
Contributor

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.

if (DEBUG) {
console.log('.track call', eventData); // eslint-disable-line
}
// return BbPromise.resolve();
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be removed.


const eventData = _.merge(defaultData, data);
if (DEBUG) {
console.log('.track call', eventData); // eslint-disable-line
Copy link
Contributor

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');
Copy link
Contributor

@pmuens pmuens May 24, 2017

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?

@pmuens
Copy link
Contributor

pmuens commented May 24, 2017

Ok. Travis is a liar. The tests are failing. Working on an update...

Copy link
Contributor

@pmuens pmuens left a 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!

Copy link
Member

@eahefnawy eahefnawy left a 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 😊

@eahefnawy eahefnawy merged commit bb7700d into master May 24, 2017
@eahefnawy eahefnawy deleted the addLogin branch May 24, 2017 13:02
DavidWells added a commit that referenced this pull request May 26, 2017
waiting on #3558 to merge implement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants