File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -28,11 +28,16 @@ sealed interface GcpCredentials
2828/* *
2929 * Use Application Default to authenticate to Google Cloud Platform.
3030 */
31- object ApplicationDefaultGcpCredentials: GcpCredentials
31+ object ApplicationDefaultGcpCredentials : GcpCredentials
3232
3333/* *
3434 * Use Service Account to authenticate to Google Cloud Platform.
3535 *
36- * @param pathToCredentials a file that stores the exported service account credentials.
36+ * @param credentials a block which returns the exported service account credentials payload .
3737 */
38- class ExportedKeyGcpCredentials (val pathToCredentials : File ): GcpCredentials
38+ class ExportedKeyGcpCredentials (val credentials : () -> String ) : GcpCredentials {
39+ /* *
40+ * Builds an [ExportedKeyGcpCredentials] from a file containing the exported service account keys.
41+ */
42+ constructor (file: File ) : this ({ file.readText() })
43+ }
Original file line number Diff line number Diff line change @@ -155,12 +155,13 @@ internal class GcpStorageService(
155155 GoogleCredentials .getApplicationDefault().createScoped(scopes)
156156 }
157157 is ExportedKeyGcpCredentials -> {
158- val path = gcpCredentials.pathToCredentials
159- if (! path.exists()) throw GradleException (" Credentials path $path does not exist" )
160- if (! path.isFile) throw GradleException (" Credentials path $path is not a file" )
158+ val contents = gcpCredentials.credentials.invoke()
159+ if (contents.isBlank()) throw GradleException (" Credentials are empty." )
161160 // Use the underlying transport factory to ensure logging is disabled.
162- GoogleCredentials .fromStream(path.inputStream(), transportOptions.httpTransportFactory)
163- .createScoped(scopes)
161+ GoogleCredentials .fromStream(
162+ contents.byteInputStream(charset = Charsets .UTF_8 ),
163+ transportOptions.httpTransportFactory
164+ ).createScoped(scopes)
164165 }
165166 }
166167 }
You can’t perform that action at this time.
0 commit comments