Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: exit code not passed to sys.exit #209

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ docker pull ghcr.io/okigan/awscurl
## Options

```sh
usage: __main__.py [-h] [-v] [-i] [-X REQUEST] [-d DATA] [-H HEADER] [-k] [--data-binary] [--region REGION] [--profile PROFILE] [--service SERVICE]
usage: __main__.py [-h] [-v] [-i] [-X REQUEST] [-d DATA] [-H HEADER] [-k] [--fail-with-body] [--data-binary] [--region REGION] [--profile PROFILE] [--service SERVICE]
[--access_key ACCESS_KEY] [--secret_key SECRET_KEY] [--security_token SECURITY_TOKEN] [--session_token SESSION_TOKEN] [-L] [-o <file>]
uri

Expand All @@ -145,6 +145,7 @@ options:
-H HEADER, --header HEADER
HTTP header (default: None)
-k, --insecure Allow insecure server connections when using SSL (default: False)
--fail-with-body Fail on HTTP errors but save the body (default: False)
--data-binary Process HTTP POST data exactly as specified with no extra processing whatsoever. (default: False)
--region REGION AWS region [env var: AWS_DEFAULT_REGION] (default: us-east-1)
--profile PROFILE AWS profile [env var: AWS_PROFILE] (default: default)
Expand Down
5 changes: 3 additions & 2 deletions awscurl/awscurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ def inner_main(argv):
parser.add_argument('-H', '--header', help='HTTP header', action='append')
parser.add_argument('-k', '--insecure', action='store_true', default=False,
help='Allow insecure server connections when using SSL')
parser.add_argument('--fail-with-body', action='store_true', help='Fail on HTTP errors but save the body', default=False)

parser.add_argument('--data-binary', action='store_true',
help='Process HTTP POST data exactly as specified with '
Expand Down Expand Up @@ -564,13 +565,13 @@ def inner_main(argv):
with open(filename, file_mode) as f:
f.write(response.content)

exit_code = 0 if response.ok else 1
exit_code = 0 if response.ok or not args.fail_with_body else 22

return exit_code


def main():
inner_main(sys.argv[1:])
return inner_main(sys.argv[1:])


if __name__ == '__main__':
Expand Down
21 changes: 17 additions & 4 deletions tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,31 @@ def test_make_request(self, *args, **kvargs):
class TestInnerMainMethod(TestCase):
maxDiff = None

def test_exit_code(self, *args, **kwargs):
def test_exit_code_without_fail_option(self, *args, **kwargs):
self.assertEqual(
inner_main(['--verbose', '--service', 's3', 'https://awscurl-sample-bucket.s3.amazonaws.com']),
1
0
)

def test_exit_code_with_fail_option(self, *args, **kwargs):
self.assertEqual(
inner_main(['--verbose', '--fail-with-body', '--service', 's3', 'https://awscurl-sample-bucket.s3.amazonaws.com']),
22
)

class TestInnerMainMethodEmptyCredentials(TestCase):
maxDiff = None

def test_exit_code(self, *args, **kwargs):
def test_exit_code_without_fail_option(self, *args, **kwargs):
self.assertEqual(
inner_main(['--verbose', '--access_key', '', '--secret_key', '', '--session_token', '', '--service', 's3',
'https://awscurl-sample-bucket.s3.amazonaws.com']),
1
0
)

def test_exit_code_with_fail_option(self, *args, **kwargs):
self.assertEqual(
inner_main(['--verbose', '--fail-with-body', '--access_key', '', '--secret_key', '', '--session_token', '', '--service', 's3',
'https://awscurl-sample-bucket.s3.amazonaws.com']),
22
)
Loading