def match_resource(resource, bid, cid):
    """Helper that returns True if the specified bucket id and collection id
    match the given resource.
    """
    resource_name, matchdict = resource
    resource_bucket = matchdict['id'] if resource_name == 'bucket' else matchdict['bucket_id']
    resource_collection = matchdict['id'] if resource_name == 'collection' else None

    same_bucket = resource_bucket == bid
    same_collection = resource_collection and resource_collection == cid

    if same_bucket and (resource_name == 'bucket' or same_collection):
        return True

    return False