~jan0sch/smederee

Showing details for patch 628db0c6d90a2d60d739bcaa3198cd5111bba868.
2022-07-20 (Wed), 6:39 AM - Jens Grassel - 628db0c6d90a2d60d739bcaa3198cd5111bba868

darcs: Add configuration for darcs commands to the service.

Summary of changes
2 files modified with 87 lines added and 1 lines removed
  • modules/hub/src/main/resources/reference.conf with 20 added and 0 removed lines
  • modules/hub/src/main/scala/de/smederee/hub/config/SmedereeHubConfig.scala with 67 added and 1 removed lines
diff -rN -u old-smederee/modules/hub/src/main/resources/reference.conf new-smederee/modules/hub/src/main/resources/reference.conf
--- old-smederee/modules/hub/src/main/resources/reference.conf	2025-02-03 04:45:38.529275334 +0000
+++ new-smederee/modules/hub/src/main/resources/reference.conf	2025-02-03 04:45:38.529275334 +0000
@@ -93,6 +93,26 @@
     }
   }
 
+  # Configuration for the darcs module for vcs related operations via darcs.
+  darcs {
+    # The directory used to store the actual repositories structured after owner.
+    # ```
+    # repositories-directory
+    #   \_ user1
+    #        \_ repo1
+    #        \_ repo2
+    #   \_ user2
+    #        \_ repo1
+    # ```
+    repositories-directory = /var/db/smederee/darcs
+    repositories-directory = ${?SMEDEREE_DARCS_REPOS_DIR}
+    # The path to the darcs binary executable. If not a full path (i.e. just
+    # `darcs`) it must be present on the `$PATH` of the environment under which
+    # the server is running.
+    executable = "darcs"
+    executable = ${?SMEDEREE_DARCS_EXECUTABLE}
+  }
+
   # The email middleware configuration for sending email messages.
   email {
     # The hostname of the email server (SMTP) to connect to.
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/config/SmedereeHubConfig.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/config/SmedereeHubConfig.scala
--- old-smederee/modules/hub/src/main/scala/de/smederee/hub/config/SmedereeHubConfig.scala	2025-02-03 04:45:38.529275334 +0000
+++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/config/SmedereeHubConfig.scala	2025-02-03 04:45:38.529275334 +0000
@@ -10,6 +10,7 @@
 package de.smederee.hub.config
 
 import java.nio.charset.StandardCharsets
+import java.nio.file._
 
 import cats.kernel.Eq
 import cats.syntax.all._
@@ -102,6 +103,37 @@
     }
 }
 
+opaque type DirectoryPath = Path
+object DirectoryPath {
+
+  /** Create an instance of DirectoryPath from the given Path type.
+    *
+    * @param source
+    *   An instance of type Path which will be returned as a DirectoryPath.
+    * @return
+    *   The appropriate instance of DirectoryPath.
+    */
+  def apply(source: Path): DirectoryPath = source
+
+  /** Try to create an instance of DirectoryPath from the given Path.
+    *
+    * @param source
+    *   A Path that should fulfil the requirements to be converted into a DirectoryPath.
+    * @return
+    *   An option to the successfully converted DirectoryPath.
+    */
+  def from(source: Path): Option[DirectoryPath] = Option(source)
+
+  /** Try to create an instance of DirectoryPath from the given String.
+    *
+    * @param source
+    *   A String that should fulfil the requirements to be converted into a DirectoryPath.
+    * @return
+    *   An option to the successfully converted DirectoryPath.
+    */
+  def fromString(source: String): Option[DirectoryPath] = Try(Paths.get(source)).toOption
+}
+
 opaque type FailedAttempts = Int
 object FailedAttempts {
 
@@ -226,6 +258,8 @@
   *   The configuration of the authentication feature.
   * @param billing
   *   The configuration of the billing feature.
+  * @param darcs
+  *   Configuration for the darcs module for vcs related operations via darcs.
   * @param email
   *   The email middleware configuration for sending email messages.
   * @param external
@@ -239,6 +273,7 @@
     port: Port,
     authentication: AuthenticationConfiguration,
     billing: BillingConfiguration,
+    darcs: DarcsConfiguration,
     email: EmailMiddlewareConfiguration,
     external: ExternalLinkConfig,
     signup: SignupConfiguration
@@ -266,11 +301,12 @@
     )
 
   given ConfigReader[ServiceConfig] =
-    ConfigReader.forProduct7(
+    ConfigReader.forProduct8(
       "host",
       "port",
       AuthenticationConfiguration.parentKey.toString,
       BillingConfiguration.parentKey.toString,
+      DarcsConfiguration.parentKey.toString,
       "email",
       ExternalLinkConfig.parentKey.toString,
       SignupConfiguration.parentKey.toString
@@ -365,6 +401,36 @@
   given ConfigReader[BillingConfiguration] = ConfigReader.forProduct1("enabled")(BillingConfiguration.apply)
 }
 
+/** Configuration for the darcs module for vcs related operations via darcs.
+  *
+  * @param executable
+  *   The path to the darcs binary executable. If not a full path (i.e. just `darcs`) it must be present on
+  *   the `$PATH` of the environment under which the server is running.
+  * @param repositoriesDirectory
+  *   The directory used to store the actual repositories structured after owner.
+  *   {{{
+  * repositories-directory
+  *   \_ user1
+  *       \_ repo1
+  *       \_ repo2
+  *   \_ user2
+  *       \_ repo1
+  *   }}}
+  */
+final case class DarcsConfiguration(executable: Path, repositoriesDirectory: DirectoryPath)
+
+object DarcsConfiguration {
+  // The default configuration key under which to lookup the darcs configuration.
+  final val parentKey: ConfigKey = ConfigKey("darcs")
+
+  given Eq[DarcsConfiguration] = Eq.fromUniversalEquals
+
+  given ConfigReader[DirectoryPath] = ConfigReader.fromStringOpt(DirectoryPath.fromString)
+
+  given ConfigReader[DarcsConfiguration] =
+    ConfigReader.forProduct2("executable", "repositories-directory")(DarcsConfiguration.apply)
+}
+
 /** @param host
   *   The official hostname of the service which will be used for the CSRF protection, generation of links in
   *   e-mails etc.