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

allow for explicit login credentials #161

Merged
merged 8 commits into from
Jun 27, 2017
Merged

Conversation

jaredcnance
Copy link
Contributor

@jaredcnance jaredcnance commented Jun 14, 2017

Closes #160

If you guys are cool with this, let me know and I'll get some tests written.

@dnfclas
Copy link

dnfclas commented Jun 14, 2017

@jaredcnance,
Thanks for your contribution.
To ensure that the project team has proper rights to use your work, please complete the Contribution License Agreement at https://cla2.dotnetfoundation.org.

It will cover your contributions to all .NET Foundation-managed open source projects.
Thanks,
.NET Foundation Pull Request Bot

{
try
{
await _armManager.Initialize();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Under the hood, this calls ArmManager.SelectTenantAsync, which calls _authHelper.GetToken and _authHelper.AcquireTokens() which I don't think makes much sense if there is a login command. this should also resolve #112

Copy link
Contributor

Choose a reason for hiding this comment

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

the reason for having this is to prompt to login if the user never actually called func azure login, or if the cached token has expired. otherwise everytime you run any other command it'll fail until you run login again.

Copy link
Contributor Author

@jaredcnance jaredcnance Jun 23, 2017

Choose a reason for hiding this comment

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

added an optional requiresLogin param to the constructor.

if (string.IsNullOrWhiteSpace(_username))
await _armManager.LoginAsync();
else
await _armManager.LoginAsync(_username, _password);
Copy link
Contributor Author

@jaredcnance jaredcnance Jun 14, 2017

Choose a reason for hiding this comment

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

may want to prompt if the username is provided but the password is empty?
also, it may be convenient to check the environment as well, where the priority order is something like:

  • use parameters
  • no parameters, use environment (AZURE_USER and AZURE_PASSWORD)
  • no env vars, prompt with interactive dialog, logging a message to the console to indicate action is required

@dnfclas
Copy link

dnfclas commented Jun 14, 2017

@jaredcnance, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request.

Thanks, .NET Foundation Pull Request Bot

this removes the requirement that a CLI only login makes the password visible on the display. the password can still be supplied using the (-w) option
@ahmelsayed
Copy link
Contributor

I'm very sorry, some how I missed the notification for this PR, and just saw it now. I'll take a look at it today.

password.Append(key.KeyChar);
}
Console.Write(Environment.NewLine);
return password.ToString();
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 SecurityHelpers.ReadPassword() which is similar to this method.


Parser.Setup<string>('w')
.WithDescription("password")
.Callback(password => _password = password);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a long option for these as well for consistency with other flags?

Maybe the description can be Username to use for non-interactive login. Note that accounts with 2 factor-auth require interactive login. Default: interactive and Password to use for non-interactive login only in conjunction with -u. Default: prompt

@jaredcnance
Copy link
Contributor Author

@ahmelsayed any thoughts on the updates?

@ahmelsayed
Copy link
Contributor

@jaredcnance sorry about the delay. I fixed my notifications for this repo which weren't making it to my email for some reason.

Sorry I don't mean to keep pushing back, but why not just make LoginAction not drive from BaseAzureAccountAction but drive from BaseAction directly? The only thing BaseAzureAccountAction is buying you is also being an IInitializableAction so that we can call login, and that's what LoginAction is avoiding with the requireLogin flag, right?

@jaredcnance
Copy link
Contributor Author

pushback is good 😄

the only reason is so it can call BaseAzureAccountAction.PrintAccountsAsync()

@ahmelsayed
Copy link
Contributor

ah, you're right. I forgot about that. Your change actually makes more sense now as login is just one form of initialization.

@ahmelsayed ahmelsayed merged commit 3ee0716 into Azure:master Jun 27, 2017
@ahmelsayed
Copy link
Contributor

Merged - Thank you very much for your contributions, @jaredcnance :)

@ahmelsayed
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants