summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Merritt <sam@swiftstack.com>2014-07-23 14:12:03 -0700
committerSamuel Merritt <sam@swiftstack.com>2014-08-05 11:11:03 -0700
commit2b55709625e8687af9e867ec93b095864b701959 (patch)
tree33a0fa3a4540ae4de725167793df358eb52f196b
parent4f2bb9f271e705ee5e7a357c9e5ec9384b4a690e (diff)
downloadswift-2b55709625e8687af9e867ec93b095864b701959.tar.gz
Make swift-form-signature output a sample form
swift-form-signature would give you the required expiration-time and HMAC signature, but it wouldn't help you actually construct the HTML form. To do that, you had to go look at the formpost middleware's doc string and make up a form yourself. For convenience, this commit makes swift-form-signature output a sample form with the computed values filled in already; the user only needs to fill in the Swift cluster's hostname. Change-Id: I70d70a648b78b382dbfbe8ff918e6158a7f6a0ab
-rw-r--r--swift/cli/form_signature.py41
-rw-r--r--test/unit/cli/test_form_signature.py4
2 files changed, 45 insertions, 0 deletions
diff --git a/swift/cli/form_signature.py b/swift/cli/form_signature.py
index 20452f36c..0aefaca37 100644
--- a/swift/cli/form_signature.py
+++ b/swift/cli/form_signature.py
@@ -46,6 +46,19 @@ def main(argv):
print 'Example output:'
print ' Expires: 1323842228'
print ' Signature: 18de97e47345a82c4dbfb3b06a640dbb'
+ print
+ print 'Sample form:'
+ print
+ print('NOTE: the <form> tag\'s "action" attribute does not contain '
+ 'the Swift cluster\'s hostname.')
+ print 'You should manually add it before using the form.'
+ print
+ print('<form action="/v1/a/c/o" method="POST" '
+ 'enctype="multipart/form-data">')
+ print ' <input type="hidden" name="max_file_size" value="123" />'
+ print ' ... more HTML ...'
+ print ' <input type="submit" />'
+ print '</form>'
return 1
path, redirect, max_file_size, max_file_count, seconds, key = argv[1:]
try:
@@ -83,4 +96,32 @@ def main(argv):
sha1).hexdigest()
print ' Expires:', expires
print 'Signature:', sig
+ print ''
+
+ print('Sample form:\n')
+
+ print('NOTE: the <form> tag\'s "action" attribute does not '
+ 'contain the Swift cluster\'s hostname.')
+ print('You should manually add it before using the form.\n')
+
+ print('<form action="%s" method="POST" enctype="multipart/form-data">'
+ % path)
+ if redirect:
+ print(' <input type="hidden" name="redirect" value="%s" />'
+ % redirect)
+ print(' <input type="hidden" name="max_file_size" value="%d" />'
+ % max_file_size)
+ print(' <input type="hidden" name="max_file_count" value="%d" />'
+ % max_file_count)
+ print(' <input type="hidden" name="expires" value="%d" />' % expires)
+ print(' <input type="hidden" name="signature" value="%s" />' % sig)
+ print(' <!-- This signature allows for at most %d files, -->'
+ % max_file_count)
+ print(' <!-- but it may also have any smaller number. -->')
+ print(' <!-- Remove file inputs as needed. -->')
+ for i in range(max_file_count):
+ print(' <input type="file" name="file%d" />' % i)
+ print(' <br />')
+ print(' <input type="submit" />')
+ print('</form>')
return 0
diff --git a/test/unit/cli/test_form_signature.py b/test/unit/cli/test_form_signature.py
index fa2c9da90..3120f08cd 100644
--- a/test/unit/cli/test_form_signature.py
+++ b/test/unit/cli/test_form_signature.py
@@ -54,6 +54,10 @@ class TestFormSignature(unittest.TestCase):
self.assertTrue("Expires: %d" % (the_time + expires,)
in out.getvalue())
+ sig_input = ('<input type="hidden" name="signature" value="%s" />'
+ % expected_signature)
+ self.assertTrue(sig_input in out.getvalue())
+
def test_too_few_args(self):
out = StringIO()
with mock.patch('sys.stdout', out):