Skip to content

Commit

Permalink
Merge branch 'master' into type-hierarchy-route
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergrabinski authored Feb 20, 2024
2 parents 1b55530 + ca6cdb8 commit d7a3cb5
Show file tree
Hide file tree
Showing 60 changed files with 431 additions and 794 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-delta-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Delta Plugins unit tests
on:
pull_request:
paths:
- 'ship/**'
- 'delta/kernel/**'
- 'delta/plugins/**'
- 'delta/rdf/**'
- 'delta/sdk/**'
- 'delta/sourcing-psql/**'
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/ci-delta-ship.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Delta Ship unit tests
on:
pull_request:
paths:
- 'delta/kernel/**'
- 'delta/plugins/**'
- 'delta/rdf/**'
- 'delta/sdk/**'
- 'delta/sourcing-psql/**'
- 'delta/testkit/**'
- 'build.sbt'
- 'project/**'
- '.github/workflows/ci-delta-ship.yml'
jobs:
run:
if: github.event_name == 'pull_request'
runs-on: it
timeout-minutes: 20
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
check-latest: true
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Unit tests
run: |
sbt -Dsbt.color=always -Dsbt.supershell=false \
clean \
ship-unit-tests-with-coverage
23 changes: 23 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ val circeVersion = "0.14.6"
val circeOpticsVersion = "0.15.0"
val circeExtrasVersions = "0.14.3"
val classgraphVersion = "4.8.165"
val declineVersion = "2.4.1"
val distageVersion = "1.2.5"
val doobieVersion = "1.0.0-RC5"
val fs2Version = "3.9.4"
Expand Down Expand Up @@ -92,6 +93,7 @@ lazy val circeOptics = "io.circe" %% "circe-optics"
lazy val circeParser = "io.circe" %% "circe-parser" % circeVersion
lazy val classgraph = "io.github.classgraph" % "classgraph" % classgraphVersion
lazy val distageCore = "io.7mind.izumi" %% "distage-core" % distageVersion
lazy val declineEffect = "com.monovore" %% "decline-effect" % declineVersion
lazy val doobiePostgres = "org.tpolecat" %% "doobie-postgres" % doobieVersion
lazy val doobie = Seq(
doobiePostgres,
Expand Down Expand Up @@ -719,6 +721,25 @@ lazy val delta = project
.settings(shared, compilation, noPublish)
.aggregate(kernel, testkit, sourcingPsql, rdf, sdk, app, plugins)

lazy val ship = project
.in(file("ship"))
.settings(
name := "nexus-ship",
moduleName := "nexus-ship"
)
.enablePlugins(UniversalPlugin, JavaAppPackaging, JavaAgent, DockerPlugin, BuildInfoPlugin)
.settings(shared, compilation, servicePackaging, assertJavaVersion, kamonSettings, coverage, release)
.dependsOn(sdk % "compile->compile;test->test", testkit % "test->compile")
.settings(
libraryDependencies ++= Seq(declineEffect),
addCompilerPlugin(betterMonadicFor),
run / fork := true,
buildInfoKeys := Seq[BuildInfoKey](version),
buildInfoPackage := "ch.epfl.bluebrain.nexus.delta.ship",
Docker / packageName := "nexus-ship",
coverageFailOnMinimum := false
)

lazy val cargo = taskKey[(File, String)]("Run Cargo to build 'nexus-fixer'")

lazy val storage = project
Expand Down Expand Up @@ -1061,4 +1082,6 @@ addCommandAlias("app-unit-tests", runTestsCommandsForModules(List("app")))
addCommandAlias("app-unit-tests-with-coverage", runTestsWithCoverageCommandsForModules(List("app")))
addCommandAlias("plugins-unit-tests", runTestsCommandsForModules(List("plugins")))
addCommandAlias("plugins-unit-tests-with-coverage", runTestsWithCoverageCommandsForModules(List("plugins")))
addCommandAlias("ship-unit-tests", runTestsCommandsForModules(List("ship")))
addCommandAlias("ship-unit-tests-with-coverage", runTestsWithCoverageCommandsForModules(List("ship")))
addCommandAlias("integration-tests", runTestsCommandsForModules(List("tests")))
Original file line number Diff line number Diff line change
Expand Up @@ -51,43 +51,41 @@ class EventsRoutes(
extractCaller { implicit caller =>
lastEventId { offset =>
concat(
get {
concat(
// SSE for all events with a given selector
(resolveSelector & pathPrefix("events") & pathEndOrSingleSlash) { selector =>
concat(
authorizeFor(AclAddress.Root, events.read).apply {
emit(sseEventLog.streamBy(selector, offset))
},
(head & authorizeFor(AclAddress.Root, events.read)) {
complete(OK)
}
)
},
// SSE for events with a given selector within a given organization
(resolveSelector & label & pathPrefix("events") & pathEndOrSingleSlash) { (selector, org) =>
concat(
authorizeFor(org, events.read).apply {
emit(sseEventLog.streamBy(selector, org, offset).attemptNarrow[OrganizationRejection])
},
(head & authorizeFor(org, events.read)) {
complete(OK)
}
)
},
// SSE for events with a given selector within a given project
(resolveSelector & projectRef & pathPrefix("events") & pathEndOrSingleSlash) { (selector, project) =>
concat(
authorizeFor(project, events.read).apply {
emit(sseEventLog.streamBy(selector, project, offset).attemptNarrow[ProjectRejection])
},
(head & authorizeFor(project, events.read)) {
complete(OK)
}
)
}
)
}
concat(
// SSE for all events with a given selector
(resolveSelector & pathPrefix("events") & pathEndOrSingleSlash & get) { selector =>
concat(
authorizeFor(AclAddress.Root, events.read).apply {
emit(sseEventLog.streamBy(selector, offset))
},
(head & authorizeFor(AclAddress.Root, events.read)) {
complete(OK)
}
)
},
// SSE for events with a given selector within a given organization
(resolveSelector & label & pathPrefix("events") & pathEndOrSingleSlash & get) { (selector, org) =>
concat(
authorizeFor(org, events.read).apply {
emit(sseEventLog.streamBy(selector, org, offset).attemptNarrow[OrganizationRejection])
},
(head & authorizeFor(org, events.read)) {
complete(OK)
}
)
},
// SSE for events with a given selector within a given project
(resolveSelector & projectRef & pathPrefix("events") & pathEndOrSingleSlash) { (selector, project) =>
concat(
(get & authorizeFor(project, events.read)).apply {
emit(sseEventLog.streamBy(selector, project, offset).attemptNarrow[ProjectRejection])
},
(head & authorizeFor(project, events.read)) {
complete(OK)
}
)
}
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ final class ResolversRoutes(
emitSource(resolvers.fetch(resolverRef, project))
},
// Fetch a resource using a resolver
(get & idSegmentRef) { resourceIdRef =>
idSegmentRef.apply { resourceIdRef =>
concat(
pathEndOrSingleSlash {
(pathEndOrSingleSlash & get) {
parameter("showReport".as[Boolean].withDefault(default = false)) { showReport =>
val outputType =
if (showReport) ResolvedResourceOutputType.Report else ResolvedResourceOutputType.JsonLd
resolveResource(resourceIdRef, project, resolutionType(resolver), outputType)
}
},
(pathPrefix("source") & pathEndOrSingleSlash) {
(pathPrefix("source") & pathEndOrSingleSlash & get) {
resolveResource(
resourceIdRef,
project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ final class ResourcesRoutes(
projectRef.apply { project =>
concat(
// Create a resource without schema nor id segment
(post & pathEndOrSingleSlash & noParameter("rev") & entity(as[NexusSource]) & indexingMode & tagParam) {
(pathEndOrSingleSlash & post & noParameter("rev") & entity(as[NexusSource]) & indexingMode & tagParam) {
(source, mode, tag) =>
authorizeFor(project, Write).apply {
emit(
Expand All @@ -84,9 +84,9 @@ final class ResourcesRoutes(
val schemaOpt = underscoreToOption(schema)
concat(
// Create a resource with schema but without id segment
(post & pathEndOrSingleSlash & noParameter("rev") & tagParam) { tag =>
authorizeFor(project, Write).apply {
entity(as[NexusSource]) { source =>
(pathEndOrSingleSlash & post & noParameter("rev") & entity(as[NexusSource]) & tagParam) {
(source, tag) =>
authorizeFor(project, Write).apply {
emit(
Created,
resources
Expand All @@ -97,7 +97,6 @@ final class ResourcesRoutes(
.rejectWhen(wrongJsonOrNotFound)
)
}
}
},
idSegment { resource =>
concat(
Expand Down Expand Up @@ -132,7 +131,7 @@ final class ResourcesRoutes(
}
},
// Deprecate a resource
(delete & parameter("rev".as[Int])) { rev =>
(pathEndOrSingleSlash & delete & parameter("rev".as[Int])) { rev =>
authorizeFor(project, Write).apply {
emit(
resources
Expand All @@ -145,7 +144,7 @@ final class ResourcesRoutes(
}
},
// Fetch a resource
(get & idSegmentRef(resource) & varyAcceptHeaders) { resourceRef =>
(pathEndOrSingleSlash & get & idSegmentRef(resource) & varyAcceptHeaders) { resourceRef =>
emitOrFusionRedirect(
project,
resourceRef,
Expand Down Expand Up @@ -176,7 +175,6 @@ final class ResourcesRoutes(
},
(pathPrefix("update-schema") & put & pathEndOrSingleSlash) {
authorizeFor(project, Write).apply {

emit(
IO.fromOption(schemaOpt)(NoSchemaProvided)
.flatMap { schema =>
Expand All @@ -187,7 +185,6 @@ final class ResourcesRoutes(
.attemptNarrow[ResourceRejection]
.rejectWhen(wrongJsonOrNotFound)
)

}
},
(pathPrefix("refresh") & put & pathEndOrSingleSlash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final class ResourcesTrialRoutes(
pathPrefix("resources") {
extractCaller { implicit caller =>
projectRef.apply { project =>
(get & idSegment & idSegmentRef & pathPrefix("validate") & pathEndOrSingleSlash) { (schema, id) =>
(idSegment & idSegmentRef & pathPrefix("validate") & pathEndOrSingleSlash & get) { (schema, id) =>
authorizeFor(project, Write).apply {
val schemaOpt = underscoreToOption(schema)
emit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ final class SchemasRoutes(
def index(schema: SchemaResource): IO[Unit] = indexAction(schema.value.project, schema, mode)
concat(
// Create a schema without id segment
(post & pathEndOrSingleSlash & noParameter("rev") & entity(as[Json])) { source =>
(pathEndOrSingleSlash & post & noParameter("rev") & entity(as[Json])) { source =>
authorizeFor(ref, Write).apply {
emitMetadata(Created, schemas.create(ref, source).flatTap(index))
}
Expand All @@ -100,7 +100,7 @@ final class SchemasRoutes(
// Create or update a schema
put {
authorizeFor(ref, Write).apply {
(parameter("rev".as[Int].?) & pathEndOrSingleSlash & entity(as[Json])) {
(parameter("rev".as[Int].?) & entity(as[Json])) {
case (None, source) =>
// Create a schema with id segment
emitMetadata(Created, schemas.create(id, ref, source).flatTap(index))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class DeltaModule(appCfg: AppConfig, config: Config)(implicit classLoader: Class
include(VersionModule)
include(QuotasModule)
include(EventsModule)
include(ExportModule)
include(StreamModule)
include(SupervisionModule)
include(TypeHierarchyModule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PostgresServiceDependencySpec extends CatsEffectSpec with DoobieScalaTestF

"fetch its service name and version" in {
new PostgresServiceDependency(xas).serviceDescription.accepted shouldEqual
ServiceDescription(Name.unsafe("postgres"), "15.5")
ServiceDescription(Name.unsafe("postgres"), "15.6")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,18 @@ class ResourcesRoutesSpec extends BaseRouteSpec with CatsIOValues {
}
}
}

"return not found for an unknown `xxx` suffix" in {
val methods = List(Get, Put, Post, Delete)
givenAResource { id =>
forAll(methods) { method =>
method(s"/v1/resources/myorg/myproject/myschema/${UrlUtils.encode(id)}/xxx") ~> asReader ~> routes ~> check {
status shouldEqual StatusCodes.NotFound
response.asJson.hcursor.get[String]("@type").toOption should contain("ResourceNotFound")
}
}
}
}
}

private def resourceMetadata(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class BlazegraphViewsRoutes(
projectRef { implicit project =>
// Create a view without id segment
concat(
(post & entity(as[Json]) & noParameter("rev") & pathEndOrSingleSlash & indexingMode) { (source, mode) =>
(pathEndOrSingleSlash & post & entity(as[Json]) & noParameter("rev") & indexingMode) { (source, mode) =>
authorizeFor(project, Write).apply {
emit(
Created,
Expand Down Expand Up @@ -139,7 +139,7 @@ class BlazegraphViewsRoutes(
)
},
// Undeprecate a blazegraph view
(put & pathPrefix("undeprecate") & parameter("rev".as[Int]) &
(pathPrefix("undeprecate") & put & parameter("rev".as[Int]) &
authorizeFor(project, Write) & pathEndOrSingleSlash) { rev =>
emit(
views
Expand Down Expand Up @@ -207,15 +207,15 @@ class BlazegraphViewsRoutes(

private def incomingOutgoing(id: IdSegment, ref: ProjectRef)(implicit caller: Caller) =
concat(
(pathPrefix("incoming") & fromPaginated & pathEndOrSingleSlash & extractUri) { (pagination, uri) =>
(pathPrefix("incoming") & fromPaginated & pathEndOrSingleSlash & get & extractUri) { (pagination, uri) =>
implicit val searchJsonLdEncoder: JsonLdEncoder[SearchResults[SparqlLink]] =
searchResultsJsonLdEncoder(ContextValue(Vocabulary.contexts.metadata), pagination, uri)

authorizeFor(ref, Read).apply {
emit(viewsQuery.incoming(id, ref, pagination).attemptNarrow[BlazegraphViewRejection])
}
},
(pathPrefix("outgoing") & fromPaginated & pathEndOrSingleSlash & extractUri & parameter(
(pathPrefix("outgoing") & fromPaginated & pathEndOrSingleSlash & get & extractUri & parameter(
"includeExternalLinks".as[Boolean] ? true
)) { (pagination, uri, includeExternal) =>
implicit val searchJsonLdEncoder: JsonLdEncoder[SearchResults[SparqlLink]] =
Expand Down
Loading

0 comments on commit d7a3cb5

Please sign in to comment.