Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* S3/CloudFront.py: Allow s3:// URI as well as cf:// URI

  for most CloudFront-related commands.



git-svn-id: http://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@416 830e0280-6d2a-0410-9c65-932aecc39d9d
  • Loading branch information...
commit f3ebd7840f867f85735761af8066751117af449e 1 parent 12702b8
ludvigm authored
Showing with 44 additions and 15 deletions.
  1. +5 −0 ChangeLog
  2. +2 −0  NEWS
  3. +37 −15 S3/CloudFront.py
View
5 ChangeLog
@@ -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
View
2  NEWS
@@ -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
==============
View
52 S3/CloudFront.py
@@ -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):
@@ -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']
@@ -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:
@@ -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,
Please sign in to comment.
Something went wrong with that request. Please try again.