Skip to content

Commit

Permalink
returns appropriate status codes on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarneyjr committed May 11, 2021
1 parent 9187803 commit ebd1979
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion awsume/__data__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = '4.5.1a3'
version = '4.5.1a4'

name = 'awsume'
author = 'Trek10, Inc'
Expand Down
1 change: 1 addition & 0 deletions awsume/awsumepy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,6 @@ def run(self, system_arguments: list):
logger.debug('', exc_info=True)
if self.is_interactive:
safe_print('Awsume error: {}'.format(e), color=colorama.Fore.RED)
sys.exit(1)
else:
raise
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [#92](https://github.com/trek10inc/awsume/issues/92) Adds support for fish shell, including custom alias to target `awsume.fish`
- Adds support for `data` argument in `exceptions.EarlyExit` to return data to non-interactive awsume executions
- [#123](https://github.com/trek10inc/awsume/issues/123) `awsume -l` will not print profiles if awsume is executing non-interactively, instead it will return a dictionary with one key, `profiles`, that maps to another dictionary where each key is a profile name and each value is a dictionary containing that profile's configuration and credentials
- [#142](https://github.com/trek10inc/awsume/issues/142) Returns appropriate exit codes on errors

## [4.5.0] - 2020-11-20 - `credential_process` support

Expand Down
8 changes: 7 additions & 1 deletion shell_scripts/awsume
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

#AWSUME_FLAG - what awsumepy told the shell to do
#AWSUME_n - the data from awsumepy
read AWSUME_FLAG AWSUME_1 AWSUME_2 AWSUME_3 AWSUME_4 AWSUME_5 AWSUME_6 AWSUME_7 <<< $(awsumepy "$@")

AWSUME_OUTPUT=$(awsumepy "$@")
AWSUME_STATUS=$?
read AWSUME_FLAG AWSUME_1 AWSUME_2 AWSUME_3 AWSUME_4 AWSUME_5 AWSUME_6 AWSUME_7 <<< $(echo $AWSUME_OUTPUT)

# remove carraige return
AWSUME_FLAG=$(echo "$AWSUME_FLAG" | tr -d '\r')

Expand Down Expand Up @@ -173,3 +177,5 @@ elif [ "$AWSUME_FLAG" = "Awsume" ]; then
fi
done
fi

return $AWSUME_STATUS
12 changes: 8 additions & 4 deletions shell_scripts/awsume.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

set SHOW=

awsumepy %* > ./temp.txt
set /p AWSUME_TEXT=<./temp.txt
awsumepy %* > %TEMP%\temp.txt
set AWSUME_STATUS=%ERRORLEVEL%
set /p AWSUME_TEXT=<%TEMP%\temp.txt
del %TEMP%\temp.txt

FOR %%A IN (%*) DO (
IF "%%A"=="-s" (set "SHOW=y")
Expand Down Expand Up @@ -116,7 +118,7 @@ for /f "tokens=1,2,3,4,5,6,7,8 delims= " %%a in ("%AWSUME_TEXT%") do (
set AWS_SECRET_ACCESS_KEY=%%c)

if "%%d" NEQ "None" (
set AWS_SESSION_TOKEN=%%d
set AWS_SESSION_TOKEN=%%d)

if "%%e" NEQ "None" (
set AWS_REGION=%%e
Expand All @@ -140,7 +142,7 @@ for /f "tokens=1,2,3,4,5,6,7,8 delims= " %%a in ("%AWSUME_TEXT%") do (
echo set AWS_SECRET_ACCESS_KEY=%%c)

if "%%d" NEQ "None" (
echo set AWS_SESSION_TOKEN=%%d
echo set AWS_SESSION_TOKEN=%%d)

if "%%e" NEQ "None" (
echo set AWS_REGION=%%e
Expand All @@ -159,3 +161,5 @@ for /f "tokens=1,2,3,4,5,6,7,8 delims= " %%a in ("%AWSUME_TEXT%") do (
)
)
)

Exit /b %AWSUME_STATUS%
7 changes: 6 additions & 1 deletion shell_scripts/awsume.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

#AWSUME_FLAG - what awsumepy told the shell to do
#AWSUME_n - the data from awsumepy
awsumepy $argv | read AWSUME_FLAG AWSUME_1 AWSUME_2 AWSUME_3 AWSUME_4 AWSUME_5 AWSUME_6 AWSUME_7
set AWSUME_OUTPUT (awsumepy $argv)
set AWSUME_STATUS $status
echo $AWSUME_OUTPUT | read AWSUME_FLAG AWSUME_1 AWSUME_2 AWSUME_3 AWSUME_4 AWSUME_5 AWSUME_6 AWSUME_7

# remove carraige return
set -gx AWSUME_FLAG (echo $AWSUME_FLAG | tr -d '\r')

if test "$AWSUME_FLAG" = "usage:"
awsumepy $argv


else if test "$AWSUME_FLAG" = "Version"
awsumepy $argv

Expand Down Expand Up @@ -165,3 +168,5 @@ else if test "$AWSUME_FLAG" = "Awsume"
end
end
end

exit $AWSUME_STATUS
3 changes: 3 additions & 0 deletions shell_scripts/awsume.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#AWSUME_n - the data from awsumepy
$AWSUME_FLAG, $AWSUME_1, $AWSUME_2, $AWSUME_3, $AWSUME_4, $AWSUME_5, $AWSUME_6, $AWSUME_7 = `
$(awsumepy $args) -split '\s+'
$env:AWSUME_STATUS = $LASTEXITCODE

#if incorrect flag/help
if ( $AWSUME_FLAG -eq "usage:" ) {
Expand Down Expand Up @@ -184,3 +185,5 @@ elseif ( $AWSUME_FLAG -eq "Awsume") {
}
}
}

exit $env:AWSUME_STATUS

0 comments on commit ebd1979

Please sign in to comment.