Skip to content

Commit

Permalink
Merge branch 'validate-endpoint-url' into develop
Browse files Browse the repository at this point in the history
* validate-endpoint-url:
  Add #899 to CHANGELOG
  Provide better error message for invalid endpoint urls
  • Loading branch information
jamesls committed Aug 27, 2014
2 parents e83c3d0 + d045c2c commit 4e093bd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ CHANGELOG
Next Release (TBD)
==================

* feature:Page Size: Add a ``--page-size`` option, that
* feature:Page Size: Add a ``--page-size`` option, that
controls page size when perfoming an operation that
uses pagination.
(`issue 889 <https://github.com/aws/aws-cli/pull/889>`__)
* bugfix:``aws s3``: Added support for ignoring and warning
about files that do not exist, user does not have read
permissions, or are special files (i.e. sockets, FIFOs,
character special devices, and block special devices)
character special devices, and block special devices)
(`issue 881 <https://github.com/aws/aws-cli/pull/881>`__)
* feature:Parameter Shorthand: Added support for
``structure(list-scalar, scalar)`` parameter shorthand.
(`issue 882 <https://github.com/aws/aws-cli/pull/882>`__)
* bugfix:``aws s3``: Fix bug when unknown options were
passed to ``aws s3`` commands
(`issue 886 <https://github.com/aws/aws-cli/pull/886>`__)
* bugfix:Endpoint URL: Provide a better error message when
an invalid ``--endpoint-url`` is provided
(`issue 899 <https://github.com/aws/aws-cli/issues/899>`__)


1.4.2
Expand Down
2 changes: 2 additions & 0 deletions awscli/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

if six.PY3:
import locale
import urllib.parse as urlparse

def get_stdout_text_writer():
return sys.stdout
Expand All @@ -38,6 +39,7 @@ def compat_open(filename, mode='r', encoding=None):
import codecs
import locale
import io
import urlparse

def get_stdout_text_writer():
# In python3, all the sys.stdout/sys.stderr streams are in text
Expand Down
14 changes: 14 additions & 0 deletions awscli/customizations/globalargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import jmespath

from awscli.compat import urlparse


def register_parse_global_args(cli):
cli.register('top-level-args-parsed', resolve_types)
Expand All @@ -26,6 +28,7 @@ def resolve_types(parsed_args, **kwargs):
# that plugins can also hook into this process.
_resolve_arg(parsed_args, 'query')
_resolve_arg(parsed_args, 'verify_ssl')
_resolve_arg(parsed_args, 'endpoint_url')


def _resolve_arg(parsed_args, name):
Expand All @@ -51,6 +54,17 @@ def _resolve_verify_ssl(value):
return verify


def _resolve_endpoint_url(value):
parsed = urlparse.urlparse(value)
# Our http library requires you specify an endpoint url
# that contains a scheme, so we'll verify that up front.
if not parsed.scheme:
raise ValueError('Bad value for --endpoint-url "%s": scheme is '
'missing. Must be of the form '
'http://<hostname>/ or https://<hostname>/' % value)
return value


def no_sign_request(parsed_args, session, **kwargs):
if not parsed_args.sign_request:
# In order to make signing disabled for all requests
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/customizations/test_globalargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,15 @@ def test_disable_signing(self):
service.signature_version = 'v4'
globalargs.disable_signing(service)
service.signature_version = None

def test_invalid_endpoint_url(self):
# Invalid jmespath expression.
parsed_args = FakeParsedArgs(endpoint_url='missing-scheme.com')
with self.assertRaises(ValueError):
globalargs.resolve_types(parsed_args)

def test_valid_endpoint_url(self):
parsed_args = FakeParsedArgs(endpoint_url='http://custom-endpoint.com')
globalargs.resolve_types(parsed_args)
self.assertEqual(parsed_args.endpoint_url,
'http://custom-endpoint.com')

0 comments on commit 4e093bd

Please sign in to comment.