#!/usr/bin/env python3 import sys import urllib.error import urllib.request bucket, key = sys.argv[1:3] base = 'http://s3:9000/' + bucket attempts = ( ('GET', '/', base + '/' + key, None), ('GET', '/', base + '/', None), ('PUT', '/anon.txt', base + '/anon.txt', b'x'), ) failed = False for method, label, url, data in attempts: try: code = urllib.request.urlopen(urllib.request.Request(url, data=data, method=method), timeout=5).status except urllib.error.HTTPError as error: code = error.code print(method, bucket + label, '->', code) failed = failed or code != 403 sys.exit(1 if failed else 0)