-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6986f9
commit 834de7f
Showing
28 changed files
with
799 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/ContextWiring.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package ch.epfl.bluebrain.nexus.ship | ||
|
||
import cats.effect.{Clock, IO} | ||
import ch.epfl.bluebrain.nexus.delta.kernel.utils.ClasspathResourceLoader | ||
import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.contexts | ||
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.api.JsonLdApi | ||
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.{ContextValue, RemoteContextResolution} | ||
import ch.epfl.bluebrain.nexus.delta.sdk.acls.AclCheck | ||
import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContext | ||
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution | ||
import ch.epfl.bluebrain.nexus.delta.sdk.resources.FetchResource | ||
import ch.epfl.bluebrain.nexus.delta.sdk.resources.Resources.ResourceLog | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.config.EventLogConfig | ||
import ch.epfl.bluebrain.nexus.ship.acls.AclWiring | ||
import ch.epfl.bluebrain.nexus.ship.resolvers.ResolverWiring | ||
|
||
object ContextWiring { | ||
|
||
implicit private val loader: ClasspathResourceLoader = ClasspathResourceLoader.withContext(getClass) | ||
|
||
def remoteContextResolution: IO[RemoteContextResolution] = | ||
for { | ||
shaclCtx <- ContextValue.fromFile("contexts/shacl.json") | ||
schemasMetaCtx <- ContextValue.fromFile("contexts/schemas-metadata.json") | ||
} yield RemoteContextResolution.fixed( | ||
contexts.shacl -> shaclCtx, | ||
contexts.schemasMetadata -> schemasMetaCtx | ||
) | ||
|
||
def resolverContextResolution( | ||
resourceLog: Clock[IO] => IO[ResourceLog], | ||
fetchContext: FetchContext, | ||
config: EventLogConfig, | ||
xas: Transactors | ||
)(implicit jsonLdApi: JsonLdApi): Clock[IO] => IO[ResolverContextResolution] = { clock => | ||
val aclCheck = AclCheck(AclWiring.acls(config, clock, xas)) | ||
val resolvers = ResolverWiring.resolvers(fetchContext, config, clock, xas) | ||
|
||
for { | ||
fetchResource <- resourceLog(clock).map(FetchResource(_)) | ||
rcr <- remoteContextResolution | ||
} yield ResolverContextResolution(aclCheck, resolvers, rcr, fetchResource) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/RunShip.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package ch.epfl.bluebrain.nexus.ship | ||
|
||
import cats.effect.{Clock, IO} | ||
import ch.epfl.bluebrain.nexus.delta.kernel.Logger | ||
import ch.epfl.bluebrain.nexus.delta.kernel.utils.UUIDF | ||
import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.api.{JsonLdApi, JsonLdJavaApi} | ||
import ch.epfl.bluebrain.nexus.delta.sdk.organizations.FetchActiveOrganization | ||
import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContext | ||
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.ApiMappings | ||
import ch.epfl.bluebrain.nexus.delta.sdk.quotas.Quotas | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors | ||
import ch.epfl.bluebrain.nexus.ship.config.ShipConfig | ||
import ch.epfl.bluebrain.nexus.ship.model.InputEvent | ||
import ch.epfl.bluebrain.nexus.ship.organizations.OrganizationProvider | ||
import ch.epfl.bluebrain.nexus.ship.projects.ProjectProcessor | ||
import ch.epfl.bluebrain.nexus.ship.resolvers.ResolverProcessor | ||
import ch.epfl.bluebrain.nexus.ship.resources.{ResourceProcessor, ResourceWiring} | ||
import ch.epfl.bluebrain.nexus.ship.schemas.{SchemaProcessor, SchemaWiring} | ||
import fs2.Stream | ||
import fs2.io.file.{Files, Path} | ||
import io.circe.parser.decode | ||
|
||
class RunShip { | ||
|
||
private val logger = Logger[RunShip] | ||
|
||
def run(file: Path, config: Option[Path]): IO[ImportReport] = { | ||
val clock = Clock[IO] | ||
val uuidF = UUIDF.random | ||
// Resources may have been created with different configurations so we adopt the lenient one for the import | ||
implicit val jsonLdApi: JsonLdApi = JsonLdJavaApi.lenient | ||
for { | ||
_ <- logger.info(s"Running the import with file $file, config $config") | ||
config <- ShipConfig.load(config) | ||
report <- Transactors.init(config.database).use { xas => | ||
val orgProvider = | ||
OrganizationProvider(config.eventLog, config.serviceAccount.value, xas, clock)(uuidF) | ||
val fetchContext = FetchContext(ApiMappings.empty, xas, Quotas.disabled) | ||
val eventLogConfig = config.eventLog | ||
val baseUri = config.baseUri | ||
for { | ||
// Provision organizations | ||
_ <- orgProvider.create(config.organizations.values) | ||
events = eventStream(file) | ||
fetchActiveOrg = FetchActiveOrganization(xas) | ||
// Wiring | ||
schemaLog = SchemaWiring.schemaLog(config.eventLog, xas, jsonLdApi) | ||
resourceLog = ResourceWiring.resourceLog(fetchContext, schemaLog, eventLogConfig, xas) | ||
schemaImports = SchemaWiring.schemaImports( | ||
resourceLog, | ||
schemaLog, | ||
fetchContext, | ||
eventLogConfig, | ||
xas | ||
) | ||
rcr = ContextWiring.resolverContextResolution(resourceLog, fetchContext, eventLogConfig, xas) | ||
// Processors | ||
projectProcessor <- ProjectProcessor(fetchActiveOrg, eventLogConfig, xas)(baseUri) | ||
resolverProcessor <- ResolverProcessor(fetchContext, eventLogConfig, xas) | ||
schemaProcessor <- SchemaProcessor(schemaLog, fetchContext, schemaImports, rcr) | ||
resourceProcessor <- ResourceProcessor(resourceLog, fetchContext) | ||
report <- EventProcessor | ||
.run(events, projectProcessor, resolverProcessor, schemaProcessor, resourceProcessor) | ||
} yield report | ||
} | ||
} yield report | ||
} | ||
|
||
private def eventStream(file: Path): Stream[IO, InputEvent] = | ||
Files[IO].readUtf8Lines(file).zipWithIndex.evalMap { case (line, index) => | ||
IO.fromEither(decode[InputEvent](line)).onError { err => | ||
logger.error(err)(s"Error parsing to event at line $index") | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/acls/AclWiring.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ch.epfl.bluebrain.nexus.ship.acls | ||
|
||
import cats.effect.{Clock, IO} | ||
import ch.epfl.bluebrain.nexus.delta.sdk.acls.{Acls, AclsImpl} | ||
import ch.epfl.bluebrain.nexus.delta.sdk.permissions.model.Permission | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.config.EventLogConfig | ||
|
||
object AclWiring { | ||
|
||
def acls(config: EventLogConfig, clock: Clock[IO], xas: Transactors): Acls = { | ||
val permissionSet = Set(Permission.unsafe("resources/read")) | ||
AclsImpl( | ||
IO.pure(permissionSet), | ||
AclsImpl.findUnknownRealms(xas), | ||
permissionSet, | ||
config, | ||
xas, | ||
clock | ||
) | ||
} | ||
|
||
} |
Oops, something went wrong.