Skip to content

Instantly share code, notes, and snippets.

@simao
Created June 25, 2021 09:46
Show Gist options
  • Save simao/3b347729c568c8929422fce57efc222a to your computer and use it in GitHub Desktop.
Save simao/3b347729c568c8929422fce57efc222a to your computer and use it in GitHub Desktop.
diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf
index 93e6ce8..9323b18 100644
--- a/src/main/resources/application.conf
+++ b/src/main/resources/application.conf
@@ -49,6 +49,7 @@ director = {
}
userProfile = {
+ enable = true
host = "localhost"
host = ${?USER_PROFILE_HOST}
port = 8085
diff --git a/src/main/scala/com/advancedtelematic/campaigner/Boot.scala b/src/main/scala/com/advancedtelematic/campaigner/Boot.scala
index e9c0cee..0d6ac75 100644
--- a/src/main/scala/com/advancedtelematic/campaigner/Boot.scala
+++ b/src/main/scala/com/advancedtelematic/campaigner/Boot.scala
@@ -2,7 +2,7 @@ package com.advancedtelematic.campaigner
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.{Directives, Route}
-import com.advancedtelematic.campaigner.client.{DeviceRegistryHttpClient, DirectorHttpClient, ResolverHttpClient, UserProfileHttpClient}
+import com.advancedtelematic.campaigner.client.{DeviceRegistryHttpClient, DirectorHttpClient, NoOpUserProfile, ResolverHttpClient, UserProfileHttpClient}
import com.advancedtelematic.campaigner.http.Routes
import com.advancedtelematic.libats.http.LogDirectives._
import com.advancedtelematic.libats.http.VersionDirectives._
@@ -36,6 +36,8 @@ trait Settings {
FiniteDuration(_config.getDuration("scheduler.delay").toNanos, TimeUnit.NANOSECONDS)
val schedulerBatchSize =
_config.getInt("scheduler.batchSize")
+
+ val userProfileEnable = _config.getBoolean("userProfile.enable")
}
object Boot extends BootApp
@@ -56,7 +58,12 @@ object Boot extends BootApp
def deviceRegistry(implicit tracing: ServerRequestTracing) = new DeviceRegistryHttpClient(deviceRegistryUri, defaultHttpClient)
def director(implicit tracing: ServerRequestTracing) = new DirectorHttpClient(directorUri, defaultHttpClient)
- def userProfile(implicit tracing: ServerRequestTracing) = new UserProfileHttpClient(userProfileUri, defaultHttpClient)
+
+ def userProfile(implicit tracing: ServerRequestTracing) = if (userProfileEnable)
+ new UserProfileHttpClient(userProfileUri, defaultHttpClient)
+ else
+ new NoOpUserProfile
+
val resolver = new ResolverHttpClient(defaultHttpClient)
val tracing = Tracing.fromConfig(config, projectName)
diff --git a/src/main/scala/com/advancedtelematic/campaigner/client/UserProfileClient.scala b/src/main/scala/com/advancedtelematic/campaigner/client/UserProfileClient.scala
index 65b5ee9..d450c18 100644
--- a/src/main/scala/com/advancedtelematic/campaigner/client/UserProfileClient.scala
+++ b/src/main/scala/com/advancedtelematic/campaigner/client/UserProfileClient.scala
@@ -2,6 +2,7 @@ package com.advancedtelematic.campaigner.client
import akka.actor.ActorSystem
import akka.http.scaladsl.model._
+import akka.http.scaladsl.util.FastFuture
import akka.stream.Materializer
import com.advancedtelematic.campaigner.data.Codecs.uriDecoder
import com.advancedtelematic.libats.data.DataType.Namespace
@@ -41,3 +42,7 @@ class UserProfileHttpClient(uri: Uri, httpClient: HttpRequest => Future[HttpResp
}
}
+
+class NoOpUserProfile extends UserProfileClient {
+ override def externalResolverUri(ns: Namespace): Future[Option[Uri]] = FastFuture.successful(None)
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment