def validate_mailgun_webhook(timestamp, token, signature):
 message = ''.join((timestamp, token))
 expected_mac = hmac.new(g.secrets['mailgun_api_key'], message, hashlib.sha256).hexdigest()
 if (not constant_time_compare(expected_mac, signature)):
  g.stats.simple_event('mailgun.incoming.bad_signature')
  return False
 if (abs((int(timestamp) - time.time())) > MAX_TIMESTAMP_DEVIATION):
  g.stats.simple_event('mailgun.incoming.bad_timestamp')
  return False
 return True

def validate_mailgun_webhook ( timestamp , token , signature ) : message = '' . join ( ( timestamp , token ) ) expected_mac = hmac . new ( g . secrets [ 'mailgun_api_key' ] , message , hashlib . sha256 ) . hexdigest ( ) if ( not constant_time_compare ( expected_mac , signature ) ) : g . stats . simple_event ( 'mailgun.incoming.bad_signature' ) return False if ( abs ( ( int ( timestamp ) - time . time ( ) ) ) > MAX_TIMESTAMP_DEVIATION ) : g . stats . simple_event ( 'mailgun.incoming.bad_timestamp' ) return False return True
check whether this is a valid webhook sent by mailgun .