def list_packages_by_name(dynamodb, package_name): _name = name.normalize(package_name) table = dynamodb.Table(TABLE) dynamodb_packages = table.query( IndexName='normalized_name-index', KeyConditionExpression=Key('normalized_name').eq(_name), ProjectionExpression='filename', ScanIndexForward=False, ) packages = [(s3.signed_url(package['filename']), package['filename']) for package in dynamodb_packages['Items']] return packages
def s3(event, context): dynamodb = boto3.resource('dynamodb') table = dynamodb.Table(TABLE) filename = event.get('Records')[0]['s3']['object']['key'] package_name = compute_package_name(filename) version = compute_version(filename) normalized_name = normalize(package_name) if 'Delete' in event['Records'][0]['eventName']: delete_item(version, table, filename) return None put_item(version, filename, normalized_name, table) return None
def list_packages_by_name(dynamodb, package_name): _name = name.normalize(package_name) table = dynamodb.Table(TABLE) dynamodb_packages = table.query( IndexName='normalized_name-index', KeyConditionExpression=Key('normalized_name').eq(_name), ProjectionExpression='filename', ScanIndexForward=False, ) sorted_packages = sorted(dynamodb_packages['Items'], key=lambda k: k['filename']) packages = [(package['filename'], package['filename']) for package in sorted_packages] return packages
def get_latest_version_by_name(dynamodb, package_name): _name = name.normalize(package_name) table = dynamodb.Table(TABLE) dynamodb_packages = table.query( IndexName='normalized_name_created_time-index', KeyConditionExpression=Key('normalized_name').eq(_name), ProjectionExpression='version', ScanIndexForward=False, Limit=1, ) if dynamodb_packages['Items']: return dynamodb_packages['Items'][0]['version'] else: return ''
def get_max_version_by_name(dynamodb, package_name, major_version): _name = name.normalize(package_name) table = dynamodb.Table(TABLE) dynamodb_packages = table.query( IndexName='name_major_version-index', KeyConditionExpression=Key('name_major_version').eq( '%s-%s' % (_name, major_version)), ProjectionExpression='version', ScanIndexForward=False, Limit=1, ) if dynamodb_packages['Items']: ver = dynamodb_packages['Items'][0]['version'] return ver else: return '%s.0' % major_version