def __init__(self, encryption_context): """ If you override the constructor, make sure to call this constructor, the session key is necessary to construct the encryption context necessary for encrypting and decrypting messages Args: encryption_context: [EncryptionContext] object which is necessary for message handler to decrypt incoming messages """ self.system_auth_header = "" self.encryption_context = encryption_context if hasattr(encryption_context, 'session_key'): self.system_auth_header = SplunkAuthHeader(encryption_context.session_key)
def get(self, request): """ Handler which passes off requests to the relevant GET handler """ request_type = request[QUERY].get(REQUEST_TYPE) if request_type not in VALID_GET_REQUESTS: return { 'payload': 'No request_type supplied', 'status': http.BAD_REQUEST, } authtoken = request[SESSION][AUTHTOKEN] user = request[SESSION][USER] auth_header = SplunkAuthHeader(authtoken) request_context = RequestContext(auth_header, current_user=user, system_auth_header=auth_header) if request_type == DASHBOARD_LIST_REQUEST: response = dashboard_list_request(request, self.async_client_factory, request_context) elif request_type == APP_LIST_REQUEST: response = get_app_list_request(request, self.async_client_factory, request_context) elif request_type == ALL_APPS_REQUEST: response = get_all_apps_request(request, self.async_client_factory, request_context) elif request_type == TV_LIST_REQUEST: response = get_tv_request(request, self.async_kvstore_client, request_context) elif request_type == TV_BOOKMARK_REQUEST: response = get_tv_bookmark_request(request, self.async_kvstore_client, request_context) status = http.OK if 'error' in response: status = http.INTERNAL_SERVER_ERROR return { 'payload': response, 'status': status, }
def delete(self, request): """ Handler which passes off requests to the relevant DELETE handler """ authtoken = request[SESSION][AUTHTOKEN] request_type = request[QUERY].get(REQUEST_TYPE) user = request[SESSION][USER] auth_header = SplunkAuthHeader(authtoken) system_auth_header = auth_header request_context = RequestContext(auth_header, current_user=user, system_auth_header=system_auth_header) if request_type not in VALID_DELETE_REQUESTS: return { 'payload': 'Invalid request_type supplied or request_type not present', 'status': http.BAD_REQUEST, } if request_type == TV_BOOKMARK_REQUEST: response = delete_tv_bookmark_request(request, self.async_kvstore_client, request_context) elif request_type == TV_CONFIG_REQUEST: response = delete_tv_config_request(request, self.async_client_factory, request_context) status = http.OK if 'error' in response: status = http.INTERNAL_SERVER_ERROR return { 'payload': response, 'status': status, }
def build_client_factory(self): """ Setup a cloudgatewayclientfactory object before a connection is established to Cloudgateway. Configures things like the uri to connect on, auth headers, websocket protocol options, etc. Returns: CloudgatewayClientFactory object """ headers = {'Authorization': sb_auth_header(self.encryption_context)} if self.shard_id: headers[constants.HEADER_SHARD_ID] = self.shard_id self.logger.info("Using shard_id={}".format(self.shard_id)) ws_url = "wss://{0}/deployment".format( self.config.get_spacebridge_server()) proxy, auth = self.config.get_ws_https_proxy_settings() if auth: headers['Proxy-Authorization'] = 'Basic ' + auth factory = CloudgatewayClientFactory(ws_url, headers=headers, proxy=proxy) factory.configure( cloudgateway_client_protocol.SpacebridgeWebsocketProtocol, self.max_reconnect_delay) factory.setProtocolOptions(autoFragmentSize=65536) factory.protocol.encryption_context = self.encryption_context factory.protocol.system_auth_header = SplunkAuthHeader( self.system_session_key) factory.protocol.parent_process_monitor = self.parent_process_monitor factory.protocol.logger = self.logger factory.protocol.mode = self.mode factory.protocol.cluster_monitor = self.cluster_monitor return factory
def post(self, request): """ Handler which passes off requests to the relevant POST handler """ authtoken = request[SESSION][AUTHTOKEN] request_type = request[QUERY].get(REQUEST_TYPE) user = request[SESSION][USER] auth_header = SplunkAuthHeader(authtoken) system_auth_header = auth_header request_context = RequestContext(auth_header, current_user=user, system_auth_header=system_auth_header) if request_type not in VALID_POST_REQUESTS: return { 'payload': 'No request_type supplied', 'status': http.BAD_REQUEST, } if request_type == APP_LIST_REQUEST: response = post_app_list_request(request, self.async_client_factory, request_context) elif request_type == TV_CONFIG_REQUEST: response = post_tv_config_request(request, self.async_client_factory, request_context) elif request_type == TV_CONFIG_BULK_REQUEST: response = post_tv_config_bulk_request(request, self.async_client_factory, request_context) elif request_type == TV_BOOKMARK_REQUEST: response = post_tv_bookmark_request(request, self.async_kvstore_client, request_context) elif request_type == ACTIVATE_TV_BOOKMARK_REQUEST: response = activate_tv_bookmark_request(request, self.async_client_factory, request_context) elif request_type == DRONE_MODE_IPAD_SUBSCRIBE_REQUEST: response = drone_mode_ipad_subscribe_request( request, self.async_client_factory, request_context) elif request_type == DRONE_MODE_TV_SUBSCRIBE_REQUEST: response = drone_mode_tv_subscribe_request( request, self.async_client_factory, request_context) elif request_type == MPC_BROADCAST_REQUEST: response = mpc_broadcast_request(request, self.async_client_factory, request_context) elif request_type == TV_INTERACTION_REQUEST: response = tv_interaction_request(request, self.async_client_factory, request_context) elif request_type == TV_CAPTAIN_URL_REQUEST: response = tv_captain_url_request(request, self.async_client_factory, request_context) elif request_type == SUBSCRIPTION_PING: response = subscription_ping(request, self.async_client_factory, request_context) status = http.OK if 'error' in response: status = http.INTERNAL_SERVER_ERROR return { 'payload': response, 'status': status, }