Skip to content
Open
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
29 changes: 18 additions & 11 deletions S3/CloudFront.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def parse(self, tree):
self.info['IsTruncated'] = (self.info['IsTruncated'].lower() == "true")

self.dist_summs = []
self.marker = self.info.get('Marker')
self.next_marker = self.info.get('NextMarker')
self.max_items = self.info.get('MaxItems')
for dist_summ in tree.findall(".//DistributionSummary"):
self.dist_summs.append(DistributionSummary(dist_summ))

Expand Down Expand Up @@ -297,7 +300,7 @@ class CloudFront(object):
operations = {
"CreateDist" : { 'method' : "POST", 'resource' : "" },
"DeleteDist" : { 'method' : "DELETE", 'resource' : "/%(dist_id)s" },
"GetList" : { 'method' : "GET", 'resource' : "" },
"GetList" : { 'method' : "GET", 'resource' : "?Marker=%(Marker)s" },
"GetDistInfo" : { 'method' : "GET", 'resource' : "/%(dist_id)s" },
"GetDistConfig" : { 'method' : "GET", 'resource' : "/%(dist_id)s/config" },
"SetDistConfig" : { 'method' : "PUT", 'resource' : "/%(dist_id)s/config" },
Expand All @@ -317,12 +320,9 @@ def __init__(self, config):
## Methods implementing CloudFront API
## --------------------------------------------------

def GetList(self):
response = self.send_request("GetList")
def GetList(self, marker = ''):
response = self.send_request("GetList", marker = marker)
response['dist_list'] = DistributionList(response['data'])
if response['dist_list'].info['IsTruncated']:
raise NotImplementedError("List is truncated. Ask s3cmd author to add support.")
## TODO: handle Truncated
return response

def CreateDistribution(self, uri, cnames_add = [], comment = None, logging = None, default_root_object = None):
Expand Down Expand Up @@ -490,11 +490,11 @@ def GetInvalInfo(self, cfuri):
## Low-level methods for handling CloudFront requests
## --------------------------------------------------

def send_request(self, op_name, dist_id = None, request_id = None, body = None, headers = {}, retries = _max_retries):
def send_request(self, op_name, dist_id = None, request_id = None, body = None, headers = {}, retries = _max_retries, marker = None):
operation = self.operations[op_name]
if body:
headers['content-type'] = 'text/plain'
request = self.create_request(operation, dist_id, request_id, headers)
request = self.create_request(operation, dist_id, request_id, headers, marker)
conn = self.get_connection()
debug("send_request(): %s %s" % (request['method'], request['resource']))
conn.c.request(request['method'], request['resource'], body, request['headers'])
Expand Down Expand Up @@ -524,9 +524,9 @@ def send_request(self, op_name, dist_id = None, request_id = None, body = None,

return response

def create_request(self, operation, dist_id = None, request_id = None, headers = None):
def create_request(self, operation, dist_id = None, request_id = None, headers = None, marker = ''):
resource = cloudfront_resource + (
operation['resource'] % { 'dist_id' : dist_id, 'request_id' : request_id })
operation['resource'] % { 'dist_id' : dist_id, 'request_id' : request_id, 'Marker': marker})

if not headers:
headers = {}
Expand Down Expand Up @@ -605,6 +605,7 @@ class Cmd(object):

class Options(object):
cf_cnames_add = []
cf_marker = ''
cf_cnames_remove = []
cf_comment = None
cf_enable = None
Expand Down Expand Up @@ -632,7 +633,13 @@ def _parse_args(args):
def info(args):
cf = CloudFront(Config())
if not args:
response = cf.GetList()
response = cf.GetList( marker=Cmd.options.cf_marker )
pretty_output("Current Marker", response['dist_list'].marker)
pretty_output("Next Marker", response['dist_list'].next_marker)
pretty_output("Max Items", response['dist_list'].max_items)
pretty_output("Items", len(response['dist_list'].dist_summs))
output("")

for d in response['dist_list'].dist_summs:
if d.info.has_key("S3Origin"):
origin = S3UriS3.httpurl_to_s3uri(d.info['S3Origin']['DNSName'])
Expand Down
1 change: 1 addition & 0 deletions s3cmd
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,7 @@ def main():
optparser.add_option( "--cf-remove-cname", dest="cf_cnames_remove", action="append", metavar="CNAME", help="Remove given CNAME from a CloudFront distribution (only for [cfmodify] command)")
optparser.add_option( "--cf-comment", dest="cf_comment", action="store", metavar="COMMENT", help="Set COMMENT for a given CloudFront distribution (only for [cfcreate] and [cfmodify] commands)")
optparser.add_option( "--cf-default-root-object", dest="cf_default_root_object", action="store", metavar="DEFAULT_ROOT_OBJECT", help="Set the default root object to return when no object is specified in the URL. Use a relative path, i.e. default/index.html instead of /default/index.html or s3://bucket/default/index.html (only for [cfcreate] and [cfmodify] commands)")
optparser.add_option( "--cf-marker", dest="cf_marker", action="store", metavar="MARKER", help="Get next page when list of cloudfront distributions is a multilist list (only for [cflist] command)")
optparser.add_option("-v", "--verbose", dest="verbosity", action="store_const", const=logging.INFO, help="Enable verbose output.")
optparser.add_option("-d", "--debug", dest="verbosity", action="store_const", const=logging.DEBUG, help="Enable debug output.")
optparser.add_option( "--version", dest="show_version", action="store_true", help="Show s3cmd version (%s) and exit." % (PkgInfo.version))
Expand Down