Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
jachro committed Aug 24, 2023
2 parents f7bcf4f + 6f03b04 commit 5b055d7
Show file tree
Hide file tree
Showing 62 changed files with 2,005 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import io.renku.db.DBConfigProvider
import io.renku.triplesgenerator.TgLockDB.SessionResource
import io.renku.triplesgenerator.{TgLockDB, TgLockDbConfigProvider}
import io.renku.triplesstore._
import io.renku.triplesstore.client.util.JenaRunMode
import org.typelevel.log4cats.Logger

import scala.concurrent.duration._
Expand Down
13 changes: 12 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ lazy val root = project
triplesGeneratorApi,
entitiesSearch,
entitiesViewingsCollector,
projectAuth,
triplesGenerator,
knowledgeGraph
)
Expand Down Expand Up @@ -159,6 +160,15 @@ lazy val entitiesSearch = project
.dependsOn(graphCommons % "compile->compile; test->test")
.enablePlugins(AutomateHeaderPlugin)

lazy val projectAuth = project
.in(file("project-auth"))
.settings(commonSettings)
.dependsOn(
renkuModelTinyTypes % "compile->compile; test->test",
triplesStoreClient % "compile->compile; test->test"
)
.enablePlugins(AutomateHeaderPlugin)

lazy val triplesGeneratorApi = project
.in(file("triples-generator-api"))
.withId("triples-generator-api")
Expand Down Expand Up @@ -187,7 +197,8 @@ lazy val triplesGenerator = project
.dependsOn(
triplesGeneratorApi % "compile->compile; test->test",
entitiesSearch,
entitiesViewingsCollector % "compile->compile; test->test"
entitiesViewingsCollector % "compile->compile; test->test",
projectAuth % "compile->compile; test->test"
)
.enablePlugins(
JavaAppPackaging,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ trait SearchInfoDatasets {

def provisionProjects(projects: entities.Project*)(implicit
entityFunctions: EntityFunctions[entities.Project],
graphsProducer: GraphsProducer[entities.Project]
graphsProducer: GraphsProducer[entities.Project],
renkuUrl: RenkuUrl
): IO[Unit] = projects.traverse_[IO, Unit](provisionProject)

def provisionProject(
project: entities.Project
)(implicit
entityFunctions: EntityFunctions[entities.Project],
graphsProducer: GraphsProducer[entities.Project]
graphsProducer: GraphsProducer[entities.Project],
renkuUrl: RenkuUrl
): IO[Unit] =
uploadIO(projectsDataset, graphsProducer(project): _*) >> insertSearchInfo(project)

Expand Down
1 change: 1 addition & 0 deletions generators/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ libraryDependencies ++=
Dependencies.circeCore ++
Dependencies.jsonld4s ++
Dependencies.catsCore ++
Dependencies.fs2Core ++
Dependencies.scalacheck).map(_ % Test) ++
Dependencies.ip4s
17 changes: 16 additions & 1 deletion generators/src/test/scala/io/renku/generators/Generators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@

package io.renku.generators

import cats.arrow.FunctionK
import cats.data.NonEmptyList
import cats.effect.IO
import cats.syntax.all._
import cats.{Applicative, Functor, Monad, Semigroupal}
import cats.{Applicative, Functor, Monad, Semigroupal, ~>}
import com.comcast.ip4s.Port
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.collection.NonEmpty
import eu.timepit.refined.numeric.{Negative, NonNegative, NonPositive, Positive}
import eu.timepit.refined.string.Url
import fs2.Stream
import io.circe.{Encoder, Json}
import org.scalacheck.Gen._
import org.scalacheck.{Arbitrary, Gen}
Expand Down Expand Up @@ -354,6 +357,9 @@ object Generators {
def generateNonEmptyList(min: Int = 1, max: Int = 5): NonEmptyList[T] =
generateExample(nonEmptyList(generator, min, max))

def asStream: Stream[Gen, T] =
Stream.eval(generator) ++ asStream

def generateOption: Option[T] = Gen.option(generator).sample getOrElse generateOption

def generateSome: Option[T] = Option(generator.generateOne)
Expand Down Expand Up @@ -410,6 +416,15 @@ object Generators {
}
}

private def runGen[A](ga: Gen[A]): IO[A] = IO(ga.generateOne)

private val genToIO: Gen ~> IO =
FunctionK.lift[Gen, IO](runGen)

implicit class GenStreamOps[A](gens: Stream[Gen, A]) {
def toIO: Stream[IO, A] = gens.translate(genToIO)
}

implicit def asArbitrary[T](implicit generator: Gen[T]): Arbitrary[T] = Arbitrary(generator)

implicit val semigroupalGen: Semigroupal[Gen] = new Semigroupal[Gen] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import io.renku.config.ConfigLoader.urlTinyTypeReader
import io.renku.http.client.{BasicAuthCredentials, BasicAuthPassword, BasicAuthUsername}
import io.renku.tinytypes.constraints.{Url, UrlOps}
import io.renku.tinytypes.{TinyTypeFactory, UrlTinyType}
import io.renku.triplesstore.client.http.{ConnectionConfig, Retry}
import org.http4s.{BasicCredentials, Uri}
import pureconfig.ConfigReader

trait FusekiConnectionConfig {
Expand All @@ -50,6 +52,13 @@ trait DatasetConnectionConfig extends FusekiConnectionConfig {
val fusekiUrl: FusekiUrl
val datasetName: DatasetName
val authCredentials: BasicAuthCredentials

def toCC(retryCfg: Option[Retry.RetryConfig] = None): ConnectionConfig =
ConnectionConfig(
Uri.unsafeFromString(fusekiUrl.value) / datasetName.value,
Some(BasicCredentials(authCredentials.username.value, authCredentials.password.value)),
retryCfg
)
}

final case class ProjectsConnectionConfig(fusekiUrl: FusekiUrl, authCredentials: BasicAuthCredentials)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package io.renku.triplesstore

import eu.timepit.refined.auto._
import io.renku.testtools.IOSpec
import io.renku.triplesstore.client.util.JenaRunMode
import org.scalatest.Suite

/** Use this trait as a replacement for [[InMemoryJenaForSpec]] to connect to a locally/externally running Jena without
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ package io.renku.triplesstore
import cats.effect.IO
import cats.effect.unsafe.IORuntime
import cats.syntax.all._
import com.dimafeng.testcontainers.{FixedHostPortGenericContainer, GenericContainer, SingleContainer}
import eu.timepit.refined.api.Refined
import com.dimafeng.testcontainers.SingleContainer
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric.Positive
import io.circe.{Decoder, HCursor, Json}
import io.renku.graph.model._
import io.renku.graph.model.entities.{EntityFunctions, Person}
Expand All @@ -36,8 +34,7 @@ import io.renku.jsonld._
import io.renku.logging.TestSparqlQueryTimeRecorder
import io.renku.triplesstore.client.model.{Quad, Triple}
import io.renku.triplesstore.client.syntax._
import org.testcontainers.containers
import org.testcontainers.containers.wait.strategy.Wait
import io.renku.triplesstore.client.util.{JenaContainer, JenaRunMode}

import scala.collection.mutable
import scala.language.reflectiveCalls
Expand All @@ -48,35 +45,9 @@ trait InMemoryJena {

private val adminCredentials = BasicAuthCredentials(BasicAuthUsername("admin"), BasicAuthPassword("admin"))

lazy val container: SingleContainer[_] = jenaRunMode match {
case JenaRunMode.GenericContainer =>
GenericContainer(
dockerImage = "renku/renku-jena:0.0.21",
exposedPorts = Seq(3030),
waitStrategy = Wait forHttp "/$/ping"
)
case JenaRunMode.FixedPortContainer(fixedPort) =>
FixedHostPortGenericContainer(
imageName = "renku/renku-jena:0.0.21",
exposedPorts = Seq(3030),
exposedHostPort = fixedPort,
exposedContainerPort = fixedPort,
waitStrategy = Wait forHttp "/$/ping"
)
case JenaRunMode.Local(_) =>
new GenericContainer(new containers.GenericContainer("") {
override def start(): Unit = ()
override def stop(): Unit = ()
})
}

private lazy val fusekiServerPort: Int Refined Positive = jenaRunMode match {
case JenaRunMode.GenericContainer => Refined.unsafeApply(container.mappedPort(container.exposedPorts.head))
case JenaRunMode.FixedPortContainer(port) => port
case JenaRunMode.Local(port) => port
}
lazy val container: SingleContainer[_] = JenaContainer.create(jenaRunMode)

lazy val fusekiUrl: FusekiUrl = FusekiUrl(s"http://localhost:$fusekiServerPort")
lazy val fusekiUrl: FusekiUrl = FusekiUrl(JenaContainer.fusekiUrl(jenaRunMode, container))

private val datasets: mutable.Map[FusekiUrl => DatasetConnectionConfig, DatasetConfigFile] = mutable.Map.empty

Expand Down
4 changes: 4 additions & 0 deletions project-auth/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
organization := "io.renku"
name := "project-auth"

libraryDependencies ++= Dependencies.http4sClient
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2023 Swiss Data Science Center (SDSC)
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
* Eidgenössische Technische Hochschule Zürich (ETHZ).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.renku.projectauth

import io.renku.graph.model.projects.{ResourceId, Slug, Visibility}
import io.renku.graph.model.{RenkuUrl, Schemas}
import io.renku.jsonld.JsonLD.JsonLDArray
import io.renku.jsonld.syntax._
import io.renku.jsonld.{EntityTypes, JsonLD, JsonLDEncoder}

final case class ProjectAuthData(
slug: Slug,
members: Set[ProjectMember],
visibility: Visibility
)

object ProjectAuthData {
implicit def jsonLDEncoder(implicit renkuUrl: RenkuUrl): JsonLDEncoder[ProjectAuthData] =
JsonLDEncoder.instance { data =>
JsonLD.entity(
ResourceId(data.slug).asEntityId,
EntityTypes.of(Schemas.schema / "Project"),
Schemas.renku / "slug" -> data.slug.asJsonLD,
Schemas.renku / "visibility" -> data.visibility.asJsonLD,
Schemas.renku / "memberId" -> JsonLDArray(data.members.map(_.gitLabId.asJsonLD).toSeq),
Schemas.renku / "memberRole" -> JsonLDArray(data.members.map(_.encoded.asJsonLD).toSeq)
)
}
}
Loading

0 comments on commit 5b055d7

Please sign in to comment.