diff --git a/.env b/.env index af4818e8..413fd816 100644 --- a/.env +++ b/.env @@ -1,13 +1,7 @@ -# API key for cutt.ly -CUTTLY_API_KEY= # Credentials to retrieve the SSL certificate KEYSTORE_PASSWORD= KEYMANAGER_PASSWORD= KEYSTORE_PATH= -# Credentials to access rdfshape DB on mongo db atlas -MONGO_DATABASE= -MONGO_USER= -MONGO_PASSWORD= # Github token needed to download weso dependencies # GITHUB_TOKEN= diff --git a/Dockerfile b/Dockerfile index 97ae1351..44bd73b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,16 +16,9 @@ RUN curl -s https://bintray.com/sbt/rpm/rpm | \ # ARGs - Override with: --build-arg [ARGUMENT]=[VALUE] # Values in .env will not be taken into account! -# Permalink service creds. -ARG MONGO_DATABASE="" -ARG MONGO_USER="" -ARG MONGO_PASSWORD="" -# Needed at container runtime. -ENV MONGO_DATABASE=$MONGO_DATABASE -ENV MONGO_USER=$MONGO_USER -ENV MONGO_PASSWORD=$MONGO_PASSWORD -# Github token needed to download weso packages +# Github token needed to download weso packages at build time. ARG GITHUB_TOKEN="" + # Port for the app to run ENV PORT=80 # Add rdfshape output-directory to path diff --git a/README.md b/README.md index 00fdf915..7974fc21 100644 --- a/README.md +++ b/README.md @@ -40,19 +40,20 @@ RDFShape is already deployed [here](http://rdfshape.weso.es). ## Build a docker image -* Use the provided Dockerfile to build rdfshape image. +* Use the provided Dockerfile to build RdfShape image. * When building the Docker image, you may provide the following arguments via `--build-arg`: - * [GITHUB_TOKEN]: A valid GitHub token to download WESO project dependencies - from Github packages. This is required to build the image. - * [MONGO_DATABASE, MONGO_USER, MONGO_PASSWORD]: The credentials to a MongoDB - Atlas instance in order to use the permalink service. These are optional, - but permalinks won't work if left undefined. WESO members may - use [these credentials](https://github.com/weso/wesolocal/wiki/Servicios-de-Terceros#mongo-db-atlas). - -> Deprecated: -> * Install [SBT](https://www.scala-sbt.org/) -> * Run `sbt docker:publishLocal` which will create a docker file at `target/docker` + * **GITHUB_TOKEN**: + - A valid GitHub token to download WESO project dependencies from Github + packages. This is required when manually building the image. + - Images available + in [Docker Hub](https://hub.docker.com/r/wesogroup/rdfshape-api) have + already been built using a read-only token for downloading the + dependencies. + +* When running a container, you may provide the following environment variables + via `--env`: + - **PORT** (optional): Port where the API is exposed inside the container. Default is 80. # Dependencies @@ -83,5 +84,5 @@ pull request to add more features or submit issues: * [Issues about SHACLex validation library](https://github.com/labra/shaclex/issues) - + RdfShape contributors diff --git a/modules/server/src/main/scala/es/weso/server/PermalinkService.scala b/modules/server/src/main/scala/es/weso/server/PermalinkService.scala index 9be4e305..29517f92 100644 --- a/modules/server/src/main/scala/es/weso/server/PermalinkService.scala +++ b/modules/server/src/main/scala/es/weso/server/PermalinkService.scala @@ -2,7 +2,7 @@ package es.weso.server import cats.effect._ import es.weso.server.APIDefinitions._ -import es.weso.server.QueryParams.{HostNameParam, UrlCodeParam, UrlParam} +import es.weso.server.QueryParams.{UrlCodeParam, UrlParam} import org.http4s._ import org.http4s.client.Client import org.http4s.dsl.Http4sDsl @@ -60,8 +60,13 @@ class PermalinkService(client: Client[IO]) extends Http4sDsl[IO] { subscription.request(1) override def onNext(result: InsertOneResult): Unit = println(s"Created permalink: $url => $urlCode") - override def onError(e: Throwable): Unit = + override def onError(e: Throwable): Unit = { println(s"Permalink creation failed: ${e.getMessage}") + InternalServerError( + s"Could not generate the permalink for url: $url" + ) + } + override def onComplete(): Unit = println("Permalink processing completed.") }) @@ -73,7 +78,7 @@ class PermalinkService(client: Client[IO]) extends Http4sDsl[IO] { BadRequest(s"Invalid URL provided for shortening: $url") case _: Exception => InternalServerError( - s"Could not execute generate the permalink for url: $url" + s"Could not generate the permalink for url: $url" ) } @@ -132,11 +137,13 @@ class PermalinkService(client: Client[IO]) extends Http4sDsl[IO] { ) } } - // DB credentials - private val mongoUser = sys.env.getOrElse("MONGO_USER", "") - private val mongoPassword = sys.env.getOrElse("MONGO_PASSWORD", "") - private val mongoDatabase = sys.env.getOrElse("MONGO_DATABASE", "") - private val collectionName = "permalinks" + // DB credentials. Access is limited to application needs. + private val mongoUser = sys.env.getOrElse("MONGO_USER", "rdfshape-user") + private val mongoPassword = + sys.env.getOrElse("MONGO_PASSWORD", "rdfshape-user") + private val mongoDatabase = sys.env.getOrElse("MONGO_DATABASE", "rdfshape") + private val collectionName = + sys.env.getOrElse("MONGO_COLLECTION", "permalinks") private val mongoConnectionString = s"mongodb+srv://$mongoUser:$mongoPassword@cluster0.pnja6.mongodb.net/$mongoDatabase" + "?retryWrites=true&w=majority"