'Returns an authorized HTTP object to be used to build a Google cloud
service hook connection.'

def _authorize(self):

    key_path = self._get_field('key_path', False)
    scope = self._get_field('scope', False)
    kwargs = {}
    if self.delegate_to:
        kwargs['sub'] = self.delegate_to
    if (not key_path):
        logging.info('Getting    connection    using    `gcloud    auth`    user,    since    no    key    file    is    defined    for    hook.')
        credentials = GoogleCredentials.get_application_default()
    else:
        if (not scope):
            raise AirflowException('Scope    should    be    defined    when    using    a    key    file.')
        scopes = [s.strip() for s in scope.split(',')]
        if key_path.endswith('.json'):
            logging.info('Getting    connection    using    a    JSON    key    file.')
            credentials = ServiceAccountCredentials.from_json_keyfile_name(key_path, scopes)
        elif key_path.endswith('.p12'):
            raise AirflowException('Legacy    P12    key    file    are    not    supported,    use    a    JSON    key    file.')
        else:
            raise AirflowException('Unrecognised    extension    for    key    file.')
    http = httplib2.Http()
    return credentials.authorize(http)
