def upload(filepaths): """ For each path in file paths: * Determine if a key in S3 exists for the given template. If not, create it. * If the key does exist, check to see if we need to update the key. If not, do nothing. """ assert isinstance(filepaths, (list, tuple)) for path in filepaths: key = get_key(path) template_data = minify(path) if key is None: validate([path]) key = get_key(path, validate=False) key.set_contents_from_string(template_data) key.change_storage_class("REDUCED_REDUNDANCY") url = get_url_for_key(key) logger.info("Uploaded new template %s", url) else: md5 = hashlib.md5(template_data) if md5.hexdigest() != key.etag.replace('"', ""): validate([path]) url = get_url_for_key(key) logger.info("Uploading %s", url) key.set_contents_from_string(template_data) key.change_storage_class("REDUCED_REDUNDANCY")
def validate(filepaths): assert isinstance(filepaths, (list, tuple)) for path in filepaths: logger.info("Validating %s", path) template_body = minify(path) cloud_formation.validate_template(template_body=template_body)