aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/core/messaging/GoogleBus.scala
diff options
context:
space:
mode:
authorJakob Odersky <jakob@driver.xyz>2018-08-22 12:51:36 -0700
committerJakob Odersky <jakob@driver.xyz>2018-09-12 14:17:39 -0700
commit5ec270aa98b806f32338fa25357abdf45dd0625b (patch)
treef1423f8add00cc2f899d2f8259b9ab33ba3c914b /src/main/scala/xyz/driver/core/messaging/GoogleBus.scala
parent3eb6a9e96bd8bf111490f390ea94a1c6d7677eff (diff)
downloaddriver-core-5ec270aa98b806f32338fa25357abdf45dd0625b.tar.gz
driver-core-5ec270aa98b806f32338fa25357abdf45dd0625b.tar.bz2
driver-core-5ec270aa98b806f32338fa25357abdf45dd0625b.zip
Trait-based initialization and other utilities
Adds the concept of a 'platform', a centralized place in which environment-specific information will be managed, and provides common initialization logic for most "standard" apps. As part of the common initialization, other parts of core have also been reworked: - HTTP-related unmarshallers and path matchers have been factored out from core.json to a new core.rest.directives package (core.json extends those unmarshallers and matchers for backwards compatibility) - CORS handling has also been moved to a dedicated utility trait - Some custom headers have been moved from raw headers to typed ones in core.rest.headers - The concept of a "reporter" has been introduced. A reporter is a context-aware combination of tracing and logging. It is intended to issue diagnostic messages that can be traced across service boundaries. Closes #192 Closes #195
Diffstat (limited to 'src/main/scala/xyz/driver/core/messaging/GoogleBus.scala')
-rw-r--r--src/main/scala/xyz/driver/core/messaging/GoogleBus.scala15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/main/scala/xyz/driver/core/messaging/GoogleBus.scala b/src/main/scala/xyz/driver/core/messaging/GoogleBus.scala
index 9895708..b296c50 100644
--- a/src/main/scala/xyz/driver/core/messaging/GoogleBus.scala
+++ b/src/main/scala/xyz/driver/core/messaging/GoogleBus.scala
@@ -2,7 +2,7 @@ package xyz.driver.core
package messaging
import java.nio.ByteBuffer
-import java.nio.file.{Files, Paths}
+import java.nio.file.{Files, Path, Paths}
import java.security.Signature
import java.time.Instant
import java.util
@@ -245,14 +245,23 @@ object GoogleBus {
implicit val subscrptionPullFormat: RootJsonFormat[SubscriptionPull] = jsonFormat1(SubscriptionPull)
}
+ def fromKeyfile(keyfile: Path, namespace: String)(
+ implicit executionContext: ExecutionContext,
+ backend: SttpBackend[Future, _]): GoogleBus = {
+ val creds = ServiceAccountCredentials.fromStream(Files.newInputStream(keyfile))
+ new GoogleBus(creds, namespace)
+ }
+
+ @deprecated(
+ "Reading from the environment adds opaque dependencies and hance leads to extra complexity. Use fromKeyfile instead.",
+ "driver-core 1.12.2")
def fromEnv(implicit executionContext: ExecutionContext, backend: SttpBackend[Future, _]): GoogleBus = {
def env(key: String) = {
require(sys.env.contains(key), s"Environment variable $key is not set.")
sys.env(key)
}
val keyfile = Paths.get(env("GOOGLE_APPLICATION_CREDENTIALS"))
- val creds = ServiceAccountCredentials.fromStream(Files.newInputStream(keyfile))
- new GoogleBus(creds, env("SERVICE_NAMESPACE"))
+ fromKeyfile(keyfile, env("SERVICE_NAMESPACE"))
}
}