<s> import json <EOL> from flask import Flask , request , abort <EOL> from st2reactor . sensor . base import Sensor <EOL> TRIGGER_REF = '<STR_LIT>' <EOL> class CircleCIWebhookSensor ( Sensor ) : <EOL> def setup ( self ) : <EOL> self . host = self . _config [ '<STR_LIT:host>' ] <EOL> self . port = self . _config [ '<STR_LIT:port>' ] <EOL> self . _endpoints = self . _config [ '<STR_LIT>' ] <EOL> self . app = Flask ( __name__ ) <EOL> self . trigger_ref = TRIGGER_REF <EOL> self . log = self . _sensor_service . get_logger ( __name__ ) <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> def status ( ) : <EOL> return json . dumps ( { '<STR_LIT>' : '<STR_LIT:OK>' } ) <EOL> @ self . app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> def build_events ( endpoint ) : <EOL> if endpoint not in self . _endpoints : <EOL> self . log . error ( '<STR_LIT>' , endpoint ) <EOL> abort ( <NUM_LIT> ) <EOL> webhook_body = request . get_json ( ) <EOL> payload = { } <EOL> payload [ '<STR_LIT>' ] = self . _get_headers_as_dict ( request . headers ) <EOL> payload [ '<STR_LIT:body>' ] = webhook_body <EOL> response = self . _sensor_service . dispatch ( self . trigger_ref , payload ) <EOL> self . log . debug ( json . dumps ( response ) ) <EOL> return json . dumps ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def run ( self ) : <EOL> self . app . run ( host = self . host , port = self . port , threaded = True ) <EOL> def cleanup ( self ) : <EOL> pass <EOL> def _get_headers_as_dict ( self , headers ) : <EOL> headers_dict = { } <EOL> for key , value in headers : <EOL> headers_dict [ key ] = value <EOL> return headers_dict <EOL> def add_trigger ( self , trigger ) : <EOL> pass <EOL> def update_trigger ( self , trigger ) : <EOL> pass <EOL> def remove_trigger ( self , trigger ) : <EOL> pass </s>
