britive / python-cli

Britive CLI Python Implementation
MIT License
4 stars 6 forks source link

[Feature Request] Open console URLs in browsers with a flag #74

Closed pbnj closed 1 year ago

pbnj commented 1 year ago

Currently, I open britive console URLs from the terminal by piping to open (macOS) or xdg-open (linux/ubuntu), like:

$ pybritive checkout --silent --console <APP>/<ENV>/<PROFILE> | xargs open

It is likely that this is also works on Windows, but this is untested:

C:\> pybritive checkout --silent --console <APP>/<ENV>/<PROFILE> | start

It would be nice to support this natively in the CLI with a flag, like:

$ pybritive checkout --console --web <APP>/<ENV>/<PROFILE>

Or, more simply, --web flag could implicitly checkout console access under the hood, like:

$ pybritive checkout --web <APP>/<ENV>/<PROFILE>

A python module like webbrowser could help here.

twratl commented 1 year ago

This feature is supported with the checkout --mode browser option or shorthand of checkout -m browser. --silent would not be required as behind the scenes we are grabbing the URL from the API response and using the webbrowser module to pop open the browser.

The --web flag is an interesting approach as well which we will consider for a future release.

pbnj commented 1 year ago

I did not know the feature already exists.

Thank you for clarifying.

No need for --web if --mode|-m browser works.

Having said that, I tried -m browser and --mode=browser for AWS and GCP profiles and they did not work for me (I can re-purpose this ticket as bug if you'd like).

I get the dot . progress indicator and then it stops and nothing happens.

pbnj commented 1 year ago

I got it working by doing pybritive checkout --console --mode=browser ....

--mode=browser by itself seems to do nothing.

twratl commented 1 year ago

Ah yes. You still have to provide the --console/-c flag to ensure the console version of the profile is checked out. It doees make sense that if --mode browser is selected that implicitly says that you want to the console version of the profile. That is something we should support.

pbnj commented 1 year ago

To be honest, programmatic & console checkouts should be unified behind the --mode flag.

And, is there a case where you may need a URL printed in the terminal without opening in the browser?

Not to scope creep beyond what I have already done, but since webbrowser python module is used, it would nice to surface/expose some of the browser options (similar to --mode=env|env-nix|env-wincmd|env-winps), like --mode=browser|browser-safari|browser-firefox|browser-chrome

twratl commented 1 year ago

Great idea. I actually do the browser option thing with in internal tool we have (which I am considering adding into pybritive) so this is another easy addition. It will be in the next release.

Also, will be adding the logic for --mode browser|console to indicate a console checkout without requiring --console flag.

In regards to the internal tool, it is signing an AWS console federation URL from AWS programmatic keys. So the command could be something like pybritive aws console --profile <aws-profile-name> which would then pop the browser up and drop you into the console. Therefore if you already have programmatic keys for AWS you don't need to checkout the console version.

Coupled with the credential_process we offer for the AW credentials file, the whole process is pretty seamless.

twratl commented 1 year ago

These changes have been released under v1.3.0. To upgrade run pip install pybritive --upgrade.

pbnj commented 1 year ago

Tested with pybritive checkout "<APP>/<ENV>/<PROFILE>" --mode=browser and it worked nicely.

Thank you.