Merge "Make options arguments truely optional"
This commit is contained in:
commit
2737fae96e
@ -25,7 +25,7 @@ import socket
|
|||||||
from os import environ, walk, _exit as os_exit
|
from os import environ, walk, _exit as os_exit
|
||||||
from os.path import isfile, isdir, join
|
from os.path import isfile, isdir, join
|
||||||
from six import text_type, PY2
|
from six import text_type, PY2
|
||||||
from six.moves.urllib.parse import unquote
|
from six.moves.urllib.parse import unquote, urlparse
|
||||||
from sys import argv as sys_argv, exit, stderr
|
from sys import argv as sys_argv, exit, stderr
|
||||||
from time import gmtime, strftime
|
from time import gmtime, strftime
|
||||||
|
|
||||||
@ -1208,8 +1208,9 @@ Positional arguments:
|
|||||||
<seconds> The amount of time in seconds the temporary URL will be
|
<seconds> The amount of time in seconds the temporary URL will be
|
||||||
valid for; or, if --absolute is passed, the Unix
|
valid for; or, if --absolute is passed, the Unix
|
||||||
timestamp when the temporary URL will expire.
|
timestamp when the temporary URL will expire.
|
||||||
<path> The full path to the Swift object. Example:
|
<path> The full path or storage URL to the Swift object.
|
||||||
/v1/AUTH_account/c/o.
|
Example: /v1/AUTH_account/c/o
|
||||||
|
or: http://saio:8080/v1/AUTH_account/c/o
|
||||||
<key> The secret temporary URL key set on the Swift cluster.
|
<key> The secret temporary URL key set on the Swift cluster.
|
||||||
To set a key, run \'swift post -m
|
To set a key, run \'swift post -m
|
||||||
"Temp-URL-Key:b3968d0207b54ece87cccc06515a89d4"\'
|
"Temp-URL-Key:b3968d0207b54ece87cccc06515a89d4"\'
|
||||||
@ -1236,6 +1237,9 @@ def st_tempurl(parser, args, thread_manager):
|
|||||||
st_tempurl_options, st_tempurl_help)
|
st_tempurl_options, st_tempurl_help)
|
||||||
return
|
return
|
||||||
method, seconds, path, key = args[:4]
|
method, seconds, path, key = args[:4]
|
||||||
|
|
||||||
|
parsed = urlparse(path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
seconds = int(seconds)
|
seconds = int(seconds)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -1245,8 +1249,12 @@ def st_tempurl(parser, args, thread_manager):
|
|||||||
thread_manager.print_msg('WARNING: Non default HTTP method %s for '
|
thread_manager.print_msg('WARNING: Non default HTTP method %s for '
|
||||||
'tempurl specified, possibly an error' %
|
'tempurl specified, possibly an error' %
|
||||||
method.upper())
|
method.upper())
|
||||||
url = generate_temp_url(path, seconds, key, method,
|
path = generate_temp_url(parsed.path, seconds, key, method,
|
||||||
absolute=options['absolute_expiry'])
|
absolute=options['absolute_expiry'])
|
||||||
|
if parsed.scheme and parsed.netloc:
|
||||||
|
url = "%s://%s%s" % (parsed.scheme, parsed.netloc, path)
|
||||||
|
else:
|
||||||
|
url = path
|
||||||
thread_manager.print_msg(url)
|
thread_manager.print_msg(url)
|
||||||
|
|
||||||
|
|
||||||
@ -1286,16 +1294,16 @@ class HelpFormatter(argparse.HelpFormatter):
|
|||||||
def parse_args(parser, args, enforce_requires=True):
|
def parse_args(parser, args, enforce_requires=True):
|
||||||
options, args = parser.parse_known_args(args or ['-h'])
|
options, args = parser.parse_known_args(args or ['-h'])
|
||||||
options = vars(options)
|
options = vars(options)
|
||||||
if enforce_requires and (options['debug'] or options['info']):
|
if enforce_requires and (options.get('debug') or options.get('info')):
|
||||||
logging.getLogger("swiftclient")
|
logging.getLogger("swiftclient")
|
||||||
if options['debug']:
|
if options.get('debug'):
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
logging.getLogger('iso8601').setLevel(logging.WARNING)
|
logging.getLogger('iso8601').setLevel(logging.WARNING)
|
||||||
client_logger_settings['redact_sensitive_headers'] = False
|
client_logger_settings['redact_sensitive_headers'] = False
|
||||||
elif options['info']:
|
elif options.get('info'):
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
if args and options['help']:
|
if args and options.get('help'):
|
||||||
_help = globals().get('st_%s_help' % args[0],
|
_help = globals().get('st_%s_help' % args[0],
|
||||||
"no help for %s" % args[0])
|
"no help for %s" % args[0])
|
||||||
print(_help)
|
print(_help)
|
||||||
|
@ -1412,6 +1412,22 @@ class TestShell(unittest.TestCase):
|
|||||||
temp_url.assert_called_with(
|
temp_url.assert_called_with(
|
||||||
'/v1/AUTH_account/c/o', 60, 'secret_key', 'GET', absolute=True)
|
'/v1/AUTH_account/c/o', 60, 'secret_key', 'GET', absolute=True)
|
||||||
|
|
||||||
|
def test_temp_url_output(self):
|
||||||
|
argv = ["", "tempurl", "GET", "60", "/v1/a/c/o",
|
||||||
|
"secret_key", "--absolute"]
|
||||||
|
with CaptureOutput(suppress_systemexit=True) as output:
|
||||||
|
swiftclient.shell.main(argv)
|
||||||
|
sig = "63bc77a473a1c2ce956548cacf916f292eb9eac3"
|
||||||
|
expected = "/v1/a/c/o?temp_url_sig=%s&temp_url_expires=60\n" % sig
|
||||||
|
self.assertEqual(expected, output.out)
|
||||||
|
|
||||||
|
argv = ["", "tempurl", "GET", "60", "http://saio:8080/v1/a/c/o",
|
||||||
|
"secret_key", "--absolute"]
|
||||||
|
with CaptureOutput(suppress_systemexit=True) as output:
|
||||||
|
swiftclient.shell.main(argv)
|
||||||
|
expected = "http://saio:8080%s" % expected
|
||||||
|
self.assertEqual(expected, output.out)
|
||||||
|
|
||||||
@mock.patch('swiftclient.service.Connection')
|
@mock.patch('swiftclient.service.Connection')
|
||||||
def test_capabilities(self, connection):
|
def test_capabilities(self, connection):
|
||||||
argv = ["", "capabilities"]
|
argv = ["", "capabilities"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user