def extract_target_endpoints(targets, known):
    """
        There are subscribed endpoints (@known) and there are targets that a user
    wants to share the resource with. This function gets a "union" of the two and
    will return only those targets that are in the known state.

        @param targets: a list of urls or aliases to get urls from the the subscription list.
        @param known: a subscription dictionary of { 'alias' : 'url' } pairs.
    """
    if not targets:
        return known.values()

    result = []
    for target in targets:
        url = None

        #Check for the Alias match
        if target in known:
            url = known[target]

        #Check for URL match
        if url is None and target in known.values():
            url = target

        if url is not None and not url in result: # found and not duplicate
            result.append(url)

    return result