{"id":18886544,"url":"https://github.com/facultyai/dynamic-configuration","last_synced_at":"2025-04-14T21:31:10.164Z","repository":{"id":54533078,"uuid":"95551999","full_name":"facultyai/dynamic-configuration","owner":"facultyai","description":"Dynamic configuration loader for Scala","archived":false,"fork":false,"pushed_at":"2021-02-12T13:50:49.000Z","size":122,"stargazers_count":6,"open_issues_count":4,"forks_count":2,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-03-25T20:20:49.791Z","etag":null,"topics":["configuration","s3","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/facultyai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-27T11:38:58.000Z","updated_at":"2024-03-25T20:20:49.792Z","dependencies_parsed_at":"2022-08-13T19:00:17.640Z","dependency_job_id":null,"html_url":"https://github.com/facultyai/dynamic-configuration","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facultyai%2Fdynamic-configuration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facultyai%2Fdynamic-configuration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facultyai%2Fdynamic-configuration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facultyai%2Fdynamic-configuration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/facultyai","download_url":"https://codeload.github.com/facultyai/dynamic-configuration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223647332,"owners_count":17179232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","s3","scala"],"created_at":"2024-11-08T07:28:18.527Z","updated_at":"2024-11-08T07:28:19.041Z","avatar_url":"https://github.com/facultyai.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dynamic configuration tools\n\n[![Build Status](https://travis-ci.org/facultyai/dynamic-configuration.svg)](https://travis-ci.org/facultyai/dynamic-configuration)\n\nThis repository provides tools for setting up configuration that refreshes at\nparticular intervals. It assumes that the current configuration lives in a file\non the local file system, on Amazon S3, or on a web server that speaks HTTP. It\ntries to refresh the configuration at regular intervals.\n\nAssume that, for instance, you want to create a class to frozzle some widgets.\nThis class needs access to the current model of the widget to be frozzled. To\navoid hard-coding the model in your code, you decide to keep a reference to the\nmodel in a file on S3. You want to be able to update that file and have your\nwidget frozzler automatically pick up the changes.\n\nLet's assume that your configuration is formatted as JSON:\n\n```json\n{\n  \"widget-model\": \"faculty-1292\"\n}\n```\n\nTo load and automatically refresh the configuration from S3, create a case\nclass that represents your configuration (e.g. `FrozzlerConfiguration` in the\nexample below). Then, call `DynamicConfiguration.fromS3`, passing in the bucket\nand key at which your configuration file is located and a method for converting\nfrom the string content of your configuration to a\n`Try[FrozzlerConfiguration]`.\n\n`DynamicConfiguration.fromS3` will return a `DynamicConfiguration` object with\na `currentConfiguration` method. This returns an option with either the current\nconfiguration, or `None` if the configuration is not loaded yet.\n\n```scala\nimport scala.concurrent.duration._\nimport scala.util.Try\n\nimport com.amazonaws.regions.Regions\nimport com.amazonaws.services.s3.AmazonS3ClientBuilder\nimport ai.faculty.configuration.{DynamicConfiguration, RefreshOptions}\nimport org.json4s._\n\nfinal case class FrozzlerConfiguration(model: String)\n\nclass WidgetFrozzler(\n    configurationS3Bucket: String,\n    configurationS3Key: String\n) {\n\n  implicit val actorSystem = ActorSystem()\n\n  private def parseConfiguration(content: String) = {\n    // Parse the contents of the configuration file.\n    val contentAsJson = JsonMethods.parse(content)\n    val JString(model) = (contentAsJson \\ \"widget-model\")\n    FrozzlerConfiguration(model)\n  }\n\n  val refreshOptions = RefreshOptions(\n    initialDelay = 0.millis,\n    updateInterval = 5.seconds\n  )\n\n  val s3Client = AmazonS3ClientBuilder\n    .standard()\n    .withRegion(Regions.EU_WEST_1)\n    .build\n\n  lazy val configurationService =\n    DynamicConfiguration.fromS3[FrozzlerConfiguration](\n      s3Client,\n      configurationS3Bucket,\n      configurationS3Key,\n      refreshOptions\n    ) { contents =\u003e\n      Try { parseConfiguration(contents) }\n    }\n\n  def frozzleWidgets =\n    configurationService.currentConfiguration match {\n      case Some(configuration) =\u003e\n        val currentModel = configuration.model\n        println(s\"Creating widget with model $currentModel\")\n      case None =\u003e\n        println(\"Configuration not ready\")\n    }\n}\n```\n\nThis is turned into a fully functional example in the\n[`/examples/simple`][example] directory.\n\n[example]: https://github.com/facultyai/dynamic-configuration/tree/master/examples/simple\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacultyai%2Fdynamic-configuration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffacultyai%2Fdynamic-configuration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacultyai%2Fdynamic-configuration/lists"}