def rest_adjust(data, adjustments):
    """
    Apply a per-key 'actions' to a dictionary *if* the key is present.

    When mapping between the gRPC and the REST representations of resources
    (Bucket, Object, etc.) we sometimes need to change the name and/or format
    of some fields.

    The `adjustments` describes what keys (if present) need adjustment, and
    a function that returns the new key and value for the item in `data`.

    Parameters
    ----------
    data : dict
        A dictionary, typically the REST representation of a resource
    adjustments : dict
        The keys in `data` that, if present, need adjustment. The values
        in this dictionary are functions returning a (key, value) tuple
        that replaces the existing tuple in `data`.

    Returns
    -------
    dict
        A copy of `data` with the changes prescribed by `adjustments`.
    """
    modified = data.copy()
    for key, action in adjustments.items():
        value = modified.pop(key, None)
        if value is not None:
            k, v = action(value)
            if k is not None:
                modified[k] = v
    return modified