<commit_before>
package org.broadinstitute.dsde.agora.server

import com.typesafe.config.{Config, ConfigFactory}
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._
import org.broadinstitute.dsde.agora.server.model.AgoraEntityType
import org.broadinstitute.dsde.agora.server.model.AgoraEntityType.EntityType
import org.broadinstitute.dsde.agora.server.webservice.routes.{AgoraDirectives, MockAgoraDirectives, OpenIdConnectDirectives}
import slick.jdbc.JdbcBackend.Database

object AgoraConfig {

  private val config: Config = ConfigFactory.load()

  // Environments
  val LocalEnvironment = "local"
  val DevEnvironment = "dev"
  val StagingEnvironment = "staging"
  val ProdEnvironment = "prod"

  val Environments = List[String](LocalEnvironment, DevEnvironment, StagingEnvironment, ProdEnvironment)

  lazy val environment = config.as[Option[String]]("environment").getOrElse(LocalEnvironment)
  if (!Environments.contains(AgoraConfig.environment))
    throw new IllegalArgumentException("Illegal environment '" + AgoraConfig.environment + "' specified.")

  var authenticationDirectives: AgoraDirectives = _
  var usesEmbeddedMongo: Boolean = _
  lazy val mockAuthenticatedUserEmail = config.as[Option[String]]("mockAuthenticatedUserEmail").getOrElse("<EMAIL>")

  // Local
  if (environment.equals(LocalEnvironment)) {
    authenticationDirectives = MockAgoraDirectives
    usesEmbeddedMongo = true
  }

  // Dev
  if (environment.equals(DevEnvironment)) {
    authenticationDirectives = OpenIdConnectDirectives
    usesEmbeddedMongo = false
  }

  // Staging
  if (environment.equals(StagingEnvironment)) {
    authenticationDirectives = OpenIdConnectDirectives
    usesEmbeddedMongo = false
  }

  // Prod
  if (environment.equals(ProdEnvironment)) {
    authenticationDirectives = OpenIdConnectDirectives
    usesEmbeddedMongo = false
  }


  // Agora
  private lazy val embeddedUrlPort = config.as[Option[Int]]("embeddedUrl.port")
  private lazy val embeddedUrlPortStr = embeddedUrlPort match {
    case None => ""
    case x: Some[Int] => ":" + x.get
  }
  private lazy val baseUrl = scheme + "://" + host + embeddedUrlPortStr + "/" + "api" + "/" + version + "/"
  private lazy val scheme = config.as[Option[String]]("webservice.scheme").getOrElse("http")
  lazy val host = config.as[Option[String]]("webservice.host").getOrElse("localhost")
  lazy val port = config.as[Option[Int]]("webservice.port").getOrElse(8000)
  lazy val version = config.as[Option[String]]("webservice.version").getOrElse("v1")
  lazy val methodsRoute = config.as[Option[String]]("methods.route").getOrElse("methods")
  lazy val methodsUrl = baseUrl + methodsRoute + "/"
  lazy val configurationsRoute = config.as[Option[String]]("configurations.route").getOrElse("configurations")
  lazy val configurationsUrl = baseUrl + configurationsRoute + "/"
  lazy val webserviceInterface = config.as[Option[String]]("webservice.interface").getOrElse("0.0.0.0")
  lazy val supervisorLogging = config.as[Option[Boolean]]("supervisor.logging").getOrElse(true)
  lazy val kamonInstrumentation = config.as[Option[Boolean]]("kamon.instrumentation").getOrElse(true)
  lazy val adminSweepInterval = config.as[Option[Int]]("admin.sweep.interval").getOrElse(15)

  // Mongo
  lazy val mongoDbHosts = config.as[List[String]]("mongodb.hosts")
  lazy val mongoDbPorts = config.as[List[Int]]("mongodb.ports")<commit_msg>Use LocalEnvironment variable rather than hardcoded string<commit_after>
package org.broadinstitute.dsde.agora.server

import com.typesafe.config.{Config, ConfigFactory}
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._
import org.broadinstitute.dsde.agora.server.model.AgoraEntityType
import org.broadinstitute.dsde.agora.server.model.AgoraEntityType.EntityType
import org.broadinstitute.dsde.agora.server.webservice.routes.{AgoraDirectives, MockAgoraDirectives, OpenIdConnectDirectives}
import slick.jdbc.JdbcBackend.Database

object AgoraConfig {

  private val config: Config = ConfigFactory.load()

  // Environments
  val LocalEnvironment = "local"

  var authenticationDirectives: AgoraDirectives = _
  var usesEmbeddedMongo: Boolean = _
  lazy val mockAuthenticatedUserEmail = config.as[Option[String]]("mockAuthenticatedUserEmail").getOrElse("<EMAIL>")

  val environment = config.as[Option[String]]("environment")
  environment match {
    case Some(env) if env == LocalEnvironment => {
      authenticationDirectives = MockAgoraDirectives
      usesEmbeddedMongo = true
    }
    case _ => {
      authenticationDirectives = OpenIdConnectDirectives
      usesEmbeddedMongo = false
    }
  }

  // Agora
  private lazy val embeddedUrlPort = config.as[Option[Int]]("embeddedUrl.port")
  private lazy val embeddedUrlPortStr = embeddedUrlPort match {
    case None => ""
    case x: Some[Int] => ":" + x.get
  }
  private lazy val baseUrl = scheme + "://" + host + embeddedUrlPortStr + "/" + "api" + "/" + version + "/"
  private lazy val scheme = config.as[Option[String]]("webservice.scheme").getOrElse("http")
  lazy val host = config.as[Option[String]]("webservice.host").getOrElse("localhost")
  lazy val port = config.as[Option[Int]]("webservice.port").getOrElse(8000)
  lazy val version = config.as[Option[String]]("webservice.version").getOrElse("v1")
  lazy val methodsRoute = config.as[Option[String]]("methods.route").getOrElse("methods")
  lazy val methodsUrl = baseUrl + methodsRoute + "/"
  lazy val configurationsRoute = config.as[Option[String]]("configurations.route").getOrElse("configurations")
  lazy val configurationsUrl = baseUrl + configurationsRoute + "/"
  lazy val webserviceInterface = config.as[Option[String]]("webservice.interface").getOrElse("0.0.0.0")
  lazy val supervisorLogging = config.as[Option[Boolean]]("supervisor.logging").getOrElse(true)
  lazy val kamonInstrumentation = config.as[Option[Boolean]]("kamon.instrumentation").getOrElse(true)
  lazy val adminSweepInterval = config.as[Option[Int]]("admin.sweep.interval").getOrElse(15)

  // Mongo
  lazy val mongoDbHosts = config.as[List[String]]("mongodb.hosts")
  lazy val mongoDbPorts = config.as[List[Int]]("mongodb.ports")
{'fraction_non_alphanumeric': 0.12566715186802524, 'fraction_numerical': 0.0035581432961345623, 'mean_word_length': 5.468619246861925, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3021374', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1918, 'n_words': 335}