def get_service(url, from_context, to_context, auth_key, token_lifetime=1):
    '''
    Read secret data from Confidant via its API.
    '''
    # Return a dict, always with an attribute that specifies whether or not the
    # function was able to successfully get a result.
    ret = {'result': False}
    # Populate the auth encryption context dict that'll be used for KMS.
    auth_context = {
        'from': from_context,
        'to': to_context
    }
    # Specify the standard time format for dates required by Confidant.
    time_format = "%Y%m%dT%H%M%SZ"
    # Generate string formatted timestamps for not_before and not_after, for
    # the lifetime specified in minutes.
    now = datetime.datetime.utcnow()
    not_before = now.strftime(time_format)
    _not_after = now + datetime.timedelta(minutes=token_lifetime)
    not_after = _not_after.strftime(time_format)
    # Generate a json string for the encryption payload contents.
    payload = json.dumps({
        'not_before': not_before,
        'not_after': not_after
    })
    try:
        kms = boto3.client('kms')
    except Exception:
        logging.exception('Failed to connect to KMS.')
        return ret
    try:
        # Generate a base64 encoded KMS encrypted token to use for
        # authentication. We encrypt the token lifetime information as the
        # payload for verification in Confidant.
        token = kms.encrypt(
            KeyId=auth_key,
            Plaintext=payload,
            EncryptionContext=auth_context
        )['CiphertextBlob']
        token = base64.b64encode(token)
    except Exception:
        logging.exception('Failed to create auth token.')
        return ret
    try:
        # Make a request to confidant with the provided url, to fetch the
        # service (from_context), providing the from context and base64 encoded
        # token for authentication.
        response = requests.get(
            '{0}/v1/services/{1}'.format(url, from_context),
            auth=(from_context, token),
            allow_redirects=False,
            timeout=2
        )
    except requests.ConnectionError:
        logging.error('Failed to connect to confidant.')
        return ret
    except requests.Timeout:
        logging.error('Confidant request timed out.')
        return ret
    if response.status_code == 404:
        logging.debug('Service not found in confidant.')
        return ret
    elif response.status_code == 401:
        logging.error('Authentication or authorization failed.')
        return ret
    elif response.status_code != 200:
        msg = 'Received unexpected return from confidant (status: {0})'
        msg = msg.format(response.status_code)
        logging.error(msg)
        return ret
    try:
        data = response.json()
    except __HOLE__:
        logging.error('Received badly formatted json data from confidant.')
        return ret
    ret['service'] = data
    ret['result'] = True
    return ret
dataset/ETHPy150Open lyft/confidant/confidant_client.py/get_service