@@ -18,7 +18,8 @@ import pureconfig.generic.ProductHint
1818import pureconfig .generic .auto ._
1919import pureconfig .{CamelCase , ConfigFieldMapping }
2020
21- import java .io .FileInputStream
21+ import java .io .{ByteArrayInputStream , FileInputStream }
22+ import java .nio .charset .StandardCharsets
2223import java .nio .file .StandardOpenOption
2324import java .security .{DigestOutputStream , MessageDigest }
2425
@@ -158,10 +159,20 @@ object GcsStorageBackend {
158159 blocker.delay {
159160 Either
160161 .catchNonFatal {
161- val builder = conf.jsonKeyPath match {
162- case Some (jsonKeyPath) =>
162+ val credentialsFileContent = conf.credentialsFile
163+ .map { credentialsFilePath =>
164+ new FileInputStream (credentialsFilePath)
165+ }
166+ .orElse {
167+ sys.env.get(" GOOGLE_APPLICATION_CREDENTIALS_RAW" ).map { credentialFileRaw =>
168+ new ByteArrayInputStream (credentialFileRaw.getBytes(StandardCharsets .UTF_8 ))
169+ }
170+ }
171+
172+ val builder = credentialsFileContent match {
173+ case Some (inputStream) =>
163174 StorageOptions .newBuilder
164- .setCredentials(ServiceAccountCredentials .fromStream(new FileInputStream (jsonKeyPath) ))
175+ .setCredentials(ServiceAccountCredentials .fromStream(inputStream ))
165176 case None =>
166177 StorageOptions .getDefaultInstance.toBuilder
167178 }
@@ -206,7 +217,7 @@ object GcsStorageBackend {
206217 }
207218}
208219
209- case class GcsBackendConfiguration (projectId : String , bucketName : String , jsonKeyPath : Option [String ] = None )
220+ case class GcsBackendConfiguration (projectId : String , bucketName : String , credentialsFile : Option [String ] = None )
210221
211222object GcsBackendConfiguration {
212223 // configure pureconfig:
0 commit comments