MCPcopy Create free account
hub / github.com/s3tools/s3cmd / CloudFront

Class CloudFront

S3/CloudFront.py:329–645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

327 return ET.tostring(self.get_printable_tree())
328
329class CloudFront(object):
330 operations = {
331 "CreateDist" : { 'method' : "POST", 'resource' : "" },
332 "DeleteDist" : { 'method' : "DELETE", 'resource' : "/%(dist_id)s" },
333 "GetList" : { 'method' : "GET", 'resource' : "" },
334 "GetDistInfo" : { 'method' : "GET", 'resource' : "/%(dist_id)s" },
335 "GetDistConfig" : { 'method' : "GET", 'resource' : "/%(dist_id)s/config" },
336 "SetDistConfig" : { 'method' : "PUT", 'resource' : "/%(dist_id)s/config" },
337 "Invalidate" : { 'method' : "POST", 'resource' : "/%(dist_id)s/invalidation" },
338 "GetInvalList" : { 'method' : "GET", 'resource' : "/%(dist_id)s/invalidation" },
339 "GetInvalInfo" : { 'method' : "GET", 'resource' : "/%(dist_id)s/invalidation/%(request_id)s" },
340 }
341
342 dist_list = None
343
344 def __init__(self, config):
345 self.config = config
346
347 ## --------------------------------------------------
348 ## Methods implementing CloudFront API
349 ## --------------------------------------------------
350
351 def GetList(self):
352 response = self.send_request("GetList")
353 response['dist_list'] = DistributionList(response['data'])
354 if response['dist_list'].info['IsTruncated']:
355 raise NotImplementedError("List is truncated. Ask s3cmd author to add support.")
356 ## TODO: handle Truncated
357 return response
358
359 def CreateDistribution(self, uri, cnames_add = [], comment = None, logging = None, default_root_object = None):
360 dist_config = DistributionConfig()
361 dist_config.info['Enabled'] = True
362 dist_config.info['S3Origin']['DNSName'] = uri.host_name()
363 dist_config.info['CallerReference'] = str(uri)
364 dist_config.info['DefaultRootObject'] = default_root_object
365 if comment == None:
366 dist_config.info['Comment'] = uri.public_url()
367 else:
368 dist_config.info['Comment'] = comment
369 for cname in cnames_add:
370 if dist_config.info['CNAME'].count(cname) == 0:
371 dist_config.info['CNAME'].append(cname)
372 if logging:
373 dist_config.info['Logging'] = S3UriS3(logging)
374 request_body = str(dist_config)
375 debug("CreateDistribution(): request_body: %s" % request_body)
376 response = self.send_request("CreateDist", body = request_body)
377 response['distribution'] = Distribution(response['data'])
378 return response
379
380 def ModifyDistribution(self, cfuri, cnames_add = [], cnames_remove = [],
381 comment = None, enabled = None, logging = None,
382 default_root_object = None):
383 if cfuri.type != "cf":
384 raise ValueError("Expected CFUri instead of: %s" % cfuri)
385 # Get current dist status (enabled/disabled) and Etag
386 info("Checking current status of %s" % cfuri)

Callers 7

_parse_argsMethod · 0.85
infoMethod · 0.85
createMethod · 0.85
deleteMethod · 0.85
modifyMethod · 0.85
invalinfoMethod · 0.85
invalidateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…