def handleRequest()

in src/main/scala/com/gu/salesforce/messageHandler/MessageHandlerLambda.scala [65:84]


  def handleRequest(inputStream: InputStream, outputStream: OutputStream, context: Context): Unit = {

    logger.info(s"Salesforce message handler lambda ${Config.stage} is starting up...")
    logger.info(s"using config from ${Config.bucket}/${Config.key}")
    val inputEvent = Json.parse(inputStream)
    if (!credentialsAreValid(inputEvent)) {
      logger.info("Request could not be authenticated")
      outputForAPIGateway(outputStream, unauthorized)
    } else {
      logger.info("Authenticated request successfully...")
      val body = (inputEvent \ "body").as[String]
      val parsedMessage = parseMessage(body)
      if (parsedMessage.OrganizationId.startsWith(Config.salesforceOrganizationId)) {
        processNotifications(parsedMessage.Notification, outputStream)
      } else {
        logger.info("Unexpected salesforce organization id in xml message")
        outputForAPIGateway(outputStream, unauthorized)
      }
    }
  }