protected def getCfClient()

in app/controllers/ProxyFrameworkAdminController.scala [62:120]


  protected def getCfClient(region:String) =
    AmazonCloudFormationClientBuilder.standard()
      .withCredentials(credentialsProvider(awsProfile))
      .withRegion(region).build()
  /**
    * (asynchronously) scan cloudformation within the given region for deployments of the proxy framework
    * @param region String of the region to search
    * @return a Future containing a Sequence of StackSummary objects along with the region name
    */
  def scanRegionForDeployments(region:String):Future[(String,Try[Seq[StackSummary]])] = Future {
    val searchParam = config.getOptional[String]("proxyFramework.descriptionSearch").getOrElse("Proxying framework for ArchiveHunter")
    val cfClient = getCfClient(region)

    logger.info(s"Looking for deployments in region $region based on a template description of '$searchParam'")
    /**
      * recursively get stack information from CF
      * @param rq ListStacksRequest instance
      * @param continuationToken Optional continuation token, for recursion. Don't specify when calling
      * @param currentValues Initial set of StackSummary. Don't specify when calling
      * @return a Seq of StackSummaries containing info about relevant stacks
      */
    def getNextPage(rq:ListStacksRequest, continuationToken:Option[String]=None, currentValues:Seq[StackSummary]=Seq()):Seq[StackSummary] = {
      val finalRq = continuationToken match {
        case Some(tok)=>rq.withNextToken(tok)
        case None=>rq
      }

      logger.debug(s"getting next page of results, continuation token is $continuationToken")
      val result = cfClient.listStacks(finalRq)
      logger.debug(s"results page: ${result.getStackSummaries.asScala}")
      Option(result.getNextToken) match {
        case Some(tok)=>
          logger.debug(s"Got continuation token $tok, recursing...")
          getNextPage(rq, Some(tok), currentValues ++ result.getStackSummaries.asScala.filter(_.getTemplateDescription.startsWith(searchParam)))
        case None=>
          logger.debug(s"No continuation token, reached end of results.")
          val data = Option(result.getStackSummaries) match {
            case Some(list) =>
              list.asScala.filter(summ=>
                Option(summ.getTemplateDescription).isDefined && summ.getTemplateDescription.startsWith(searchParam)
              )
            case None => Seq()
          }
          currentValues ++ data
      }
    }

    logger.debug("Looking for stacks with CREATE_COMPLETE,UPDATE_COMPLETE or UPDATE_IN_PROGRESS")
    try {
      val baseRq = new ListStacksRequest().withStackStatusFilters(Seq("CREATE_COMPLETE", "UPDATE_COMPLETE", "UPDATE_IN_PROGRESS").asJavaCollection)
      val results = getNextPage(baseRq)
      logger.debug(s"Got final results $results")
      (region, Success(results))
    } catch {
      case err:Throwable=>
        logger.error(s"Could not list stacks from $region", err)
        (region, Failure(err))
    }
  }