trek10inc / awsume

A utility for easily assuming AWS IAM roles from the command line.
https://awsu.me
MIT License
487 stars 90 forks source link

Add option to list profiles in JSON #123

Open okelet opened 3 years ago

okelet commented 3 years ago

In order to use the awsumepy library from scripts, when running this code:

awsumepy.awsume('profile', '-l')

It prints out the list of profile in a non-friendly parseable format in the stdout. It would be great that the function could return that information in JSON o dict, instead of printing the data in the stdout and returning None, or in order to capture the command output and parse the stdout.

mbarneyjr commented 3 years ago

Happy holidays!

Support for getting profile data as a dict has been released in the latest pre-release (currently awsume==4.5.1a2).

exceptions.EarlyExit has been updated to allow returning data to the non-interactive caller, and the list profiles handler has been updated to send the profile data back (and also not print the profile information when called non-interactively). This means that you should be able to do this:

from awsume.awsumepy import awsume
data = awsume('-l')
print(data['profiles'])

Let me know if there are any bugs, thank you!

mbarneyjr commented 3 years ago

4.5.1 has been released that returns the profile dictionary to non-interacitve calls of awsume (via python import)

We're working on being able to output the profile listing as json from the CLI (awsume -l | jq ...), so we'll leave this issue open until we get that released

Thanks!