def _generate_blob_sas_url(prefix, extension): """ Helper to generate SAS URL for creating a BLOB. """ blob_name = '{0}/{1}{2}'.format(prefix, str(uuid4()), extension) if settings.USE_AWS: return { 'url': _make_url_sassy(blob_name, permission='w', duration=60 * 60 * 24), 'id': blob_name } else: url = make_blob_sas_url(settings.BUNDLE_AZURE_ACCOUNT_NAME, settings.BUNDLE_AZURE_ACCOUNT_KEY, settings.BUNDLE_AZURE_CONTAINER, blob_name, permission='w', duration=60 * 60 * 24) logger.debug("_generate_blob_sas_url: sas=%s; blob_name=%s.", url, blob_name) return { 'url': url, 'id': blob_name, 'version': PREFERRED_STORAGE_X_MS_VERSION }
def _generate_blob_sas_url(prefix, extension): """ Helper to generate SAS URL for creating a BLOB. """ blob_name = '{0}/{1}{2}'.format(prefix, str(uuid4()), extension) url = make_blob_sas_url(settings.BUNDLE_AZURE_ACCOUNT_NAME, settings.BUNDLE_AZURE_ACCOUNT_KEY, settings.BUNDLE_AZURE_CONTAINER, blob_name, duration=60) logger.debug("_generate_blob_sas_url: sas=%s; blob_name=%s.", url, blob_name) return {'url': url, 'id': blob_name, 'version': PREFERRED_STORAGE_X_MS_VERSION}
def get_sas(value): """ Helper to generate SAS URL for any BLOB. """ blob_name = value url = make_blob_sas_url(settings.BUNDLE_AZURE_ACCOUNT_NAME, settings.BUNDLE_AZURE_ACCOUNT_KEY, settings.BUNDLE_AZURE_CONTAINER, blob_name,permission='r', duration=60) print url return url
def get_sas(value): """ Helper to generate SAS URL for any BLOB. """ blob_name = value url = make_blob_sas_url(settings.BUNDLE_AZURE_ACCOUNT_NAME, settings.BUNDLE_AZURE_ACCOUNT_KEY, settings.BUNDLE_AZURE_CONTAINER, blob_name, permission='r', duration=60) print url return url
def _generate_blob_sas_url(prefix, extension): """ Helper to generate SAS URL for creating a BLOB. """ blob_name = "{0}/{1}{2}".format(prefix, str(uuid4()), extension) url = make_blob_sas_url( settings.BUNDLE_AZURE_ACCOUNT_NAME, settings.BUNDLE_AZURE_ACCOUNT_KEY, settings.BUNDLE_AZURE_CONTAINER, blob_name, permission="w", duration=60, ) logger.debug("_generate_blob_sas_url: sas=%s; blob_name=%s.", url, blob_name) return {"url": url, "id": blob_name, "version": PREFERRED_STORAGE_X_MS_VERSION}
def _make_url_sassy(path, permission='r', duration=60 * 60 * 24): if settings.USE_AWS: if permission == 'r': # GET instead of r (read) for AWS method = 'GET' elif permission == 'w': # GET instead of w (write) for AWS method = 'PUT' else: # Default to get if we don't know method = 'GET' # Remove the beginning of the URL (before bucket name) so we just have the path to the file path = path.split(settings.AWS_STORAGE_PRIVATE_BUCKET_NAME)[-1] # Spaces replaced with +'s, so we have to replace those... path = path.replace('+', ' ') return BundleStorage.connection.generate_url( expires_in=duration, method=method, bucket=settings.AWS_STORAGE_PRIVATE_BUCKET_NAME, key=path, query_auth=True, ) else: sassy_url = make_blob_sas_url( settings.BUNDLE_AZURE_ACCOUNT_NAME, settings.BUNDLE_AZURE_ACCOUNT_KEY, settings.BUNDLE_AZURE_CONTAINER, path, permission=permission, duration=duration ) # Ugly way to check if we didn't get the path, should work... if '<Code>InvalidUri</Code>' not in sassy_url: return sassy_url else: return ''