Skip to content

Commit

Permalink
* S3/CloudFront.py: Allow s3:// URI as well as cf:// URI
Browse files Browse the repository at this point in the history
  for most CloudFront-related commands.



git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@416 830e0280-6d2a-0410-9c65-932aecc39d9d
  • Loading branch information
mludvig committed Jun 12, 2010
1 parent b020ea0 commit 08f8991
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2010-06-13 Michal Ludvig <mludvig@logix.net.nz>

* S3/CloudFront.py: Allow s3:// URI as well as cf:// URI
for most CloudFront-related commands.

2010-06-12 Michal Ludvig <mludvig@logix.net.nz>

* s3cmd, S3/CloudFront.py, S3/Config.py: Support access
Expand Down
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ s3cmd 0.9.9.92 - ???
* Added access logging for CloudFront distributions
using [cfmodify --log]
* Added --acl-grant and --acl-revoke (by Timothee Linden).
* Allow s3:// URI as well as cf:// URI as a distribution
name for most CloudFront related commands.

s3cmd 0.9.9.91 - 2009-10-08
==============
Expand Down
52 changes: 37 additions & 15 deletions S3/CloudFront.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,36 @@ def update_option(self, option, value):
setattr(Cmd.options, option, value)

options = Options()
dist_list = None

@staticmethod
def _get_dist_name_for_bucket(uri):
cf = CloudFront(Config())
debug("_get_dist_name_for_bucket(%r)" % uri)
assert(uri.type == "s3")
if Cmd.dist_list is None:
response = cf.GetList()
Cmd.dist_list = {}
for d in response['dist_list'].dist_summs:
Cmd.dist_list[getBucketFromHostname(d.info['Origin'])[0]] = d.uri()
debug("dist_list: %s" % Cmd.dist_list)
return Cmd.dist_list[uri.bucket()]

@staticmethod
def _parse_args(args):
cfuris = []
for arg in args:
uri = S3Uri(arg)
if uri.type == 's3':
try:
uri = Cmd._get_dist_name_for_bucket(uri)
except Exception, e:
debug(e)
raise ParameterError("Unable to translate S3 URI to CloudFront distribution name: %s" % uri)
if uri.type != 'cf':
raise ParameterError("CloudFront URI required instead of: %s" % arg)
cfuris.append(uri)
return cfuris

@staticmethod
def info(args):
Expand All @@ -409,11 +439,7 @@ def info(args):
pretty_output("Enabled", d.info['Enabled'])
output("")
else:
cfuris = []
for arg in args:
cfuris.append(S3Uri(arg))
if cfuris[-1].type != 'cf':
raise ParameterError("CloudFront URI required instead of: %s" % arg)
cfuris = Cmd._parse_args(args)
for cfuri in cfuris:
response = cf.GetDistInfo(cfuri)
d = response['distribution']
Expand Down Expand Up @@ -463,11 +489,7 @@ def create(args):
@staticmethod
def delete(args):
cf = CloudFront(Config())
cfuris = []
for arg in args:
cfuris.append(S3Uri(arg))
if cfuris[-1].type != 'cf':
raise ParameterError("CloudFront URI required instead of: %s" % arg)
cfuris = Cmd._parse_args(args)
for cfuri in cfuris:
response = cf.DeleteDistribution(cfuri)
if response['status'] >= 400:
Expand All @@ -477,12 +499,12 @@ def delete(args):
@staticmethod
def modify(args):
cf = CloudFront(Config())
cfuri = S3Uri(args.pop(0))
if cfuri.type != 'cf':
raise ParameterError("CloudFront URI required instead of: %s" % arg)
if len(args):
if len(args) > 1:
raise ParameterError("Too many parameters. Modify one Distribution at a time.")

try:
cfuri = Cmd._parse_args(args)[0]
except IndexError, e:
raise ParameterError("No valid Distribution URI found.")
response = cf.ModifyDistribution(cfuri,
cnames_add = Cmd.options.cf_cnames_add,
cnames_remove = Cmd.options.cf_cnames_remove,
Expand Down

0 comments on commit 08f8991

Please sign in to comment.