Beispiel #1
0
from __future__ import unicode_literals

import logging

from oauthlib.common import generate_token, urldecode
from oauthlib.oauth2 import WebApplicationClient, InsecureTransportError
from oauthlib.oauth2 import LegacyApplicationClient
from oauthlib.oauth2 import TokenExpiredError, is_secure_transport
import requests

# log = logging.getLogger(__name__)
from gmail_Utilities import Utilities, KennyLoggins
kl = KennyLoggins()
log = kl.get_logger("TA-gmail-audit", "gmail_authorize_endpoint", logging.DEBUG)

class TokenUpdated(Warning):
    def __init__(self, token):
        super(TokenUpdated, self).__init__()
        self.token = token


class OAuth2Session(requests.Session):
    """Versatile OAuth 2 extension to :class:`requests.Session`.

    Supports any grant type adhering to :class:`oauthlib.oauth2.Client` spec
    including the four core OAuth 2 grants.

    Can be used to create authorization urls, fetch tokens and access protected
    resources using the :class:`requests.Session` interface you are used to.

    - :class:`oauthlib.oauth2.WebApplicationClient` (default): Authorization Code Grant
Beispiel #2
0
# Necessary
_CRED = None
_DOMAIN = None

_SPLUNK_HOME = os.getenv("SPLUNK_HOME")
if _SPLUNK_HOME is None:
    _SPLUNK_HOME = make_splunkhome_path([""])

_APP_HOME = os.path.join(util.get_apps_dir(), _APP_NAME)
_app_local_directory = os.path.join(_APP_HOME, "local")
_BIN_PATH = os.path.join(_APP_HOME, "bin")

SCOPES = 'https://www.googleapis.com/auth/admin.directory.user'

kl = KennyLoggins()
# log = kl.get_logger(_APP_NAME, "modularinput", log.INFO)
log = kl.get_logger(_APP_NAME, "modularinput", log.DEBUG)

log.debug("logging setup complete")


def send_to_splunk(splunk_host, auth_token, payload, sourcetype, eventtime):
    """Sends an event to the HTTP Event collector of a Splunk Instance"""

    splunk_session = requests.Session()
    try:

        hostname = socket.gethostname()
        post_data = {"host": hostname}
import logging
import os
import splunk
import uuid
# Google Stuff
import httplib2
import socks
from gmail_Utilities import Utilities, KennyLoggins
from google_auth_oauthlib.flow import Flow

httplib2.CA_CERTS = "{}/{}".format(os.path.join(util.get_apps_dir(), _APP_NAME, 'bin'), "cacerts.txt")
_LOCALDIR = os.path.join(util.get_apps_dir(), _APP_NAME, 'local')
if not os.path.exists(_LOCALDIR):
    os.makedirs(_LOCALDIR)

kl = KennyLoggins()
logger = kl.get_logger(_APP_NAME, "gmail_authorize_endpoint", logging.INFO)


class gmail_authorize(splunk.rest.BaseRestHandler):
    def _catch_error(self, e):
        myJson = {"log_level": "ERROR"}
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        myJson["errors"] = [{"msg": str(e),
                             "exception_type": "{}".format(type(e)),
                             "exception_arguments": "{}".format(e),
                             "filename": fname,
                             "line": exc_tb.tb_lineno
                             }]
        return myJson