Skip to content

Commit 89488af

Browse files
committed
Merge pull request #24 from androidx/invalidbucketname
Validate that configured bucket for the project is valid
2 parents 25f9708 + f4d34df commit 89488af

File tree

8 files changed

+34
-7
lines changed

8 files changed

+34
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In your `settings.gradle.kts` file add the following
88

99
```kotlin
1010
plugins {
11-
id("androidx.build.gradle.gcpbuildcache") version "1.0.0-alpha05"
11+
id("androidx.build.gradle.gcpbuildcache") version "1.0.0-alpha06"
1212
}
1313

1414
import androidx.build.gradle.gcpbuildcache.GcpBuildCache
@@ -36,7 +36,7 @@ If you are using Groovy, then you should do the following:
3636

3737
```groovy
3838
plugins {
39-
id("androidx.build.gradle.gcpbuildcache") version "1.0.0-alpha05"
39+
id("androidx.build.gradle.gcpbuildcache") version "1.0.0-alpha06"
4040
}
4141
4242
import androidx.build.gradle.gcpbuildcache.GcpBuildCache

RELEASE-NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release notes for GCP backed Gradle Remote Cache
22

3+
## 1.0.0-alpha06
4+
5+
- Warn when a user incorrectly configures GCP bucket to be used for the cache.
6+
37
## 1.0.0-alpha05
48

59
- Downloads `Blob`s to an intermediate `Buffer` or a `File` depending on the size of the blob.

gcpbuildcache/build.gradle.kts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,15 @@ gradlePlugin {
4545
id = "androidx.build.gradle.gcpbuildcache"
4646
displayName = "Gradle GCP Build Cache Plugin"
4747
description = """
48-
Implementation of Gradle Build Cache that allows to use Google Cloud Platform
49-
storage buckets as a back end.
48+
- Warn when a user incorrectly configures GCP bucket to be used for the cache.
5049
""".trimIndent()
5150
implementationClass = "androidx.build.gradle.gcpbuildcache.GcpGradleBuildCachePlugin"
5251
}
5352
}
5453
}
5554

5655
group = "androidx.build.gradle.gcpbuildcache"
57-
version = "1.0.0-alpha05"
56+
version = "1.0.0-alpha06"
5857

5958
testing {
6059
suites {

gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache/FileSystemStorageService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ internal class FileSystemStorageService(
7676
return file.delete()
7777
}
7878

79+
override fun validateConfiguration() {
80+
// There is nothing to validate
81+
}
82+
7983
override fun close() {
8084
location.deleteRecursively()
8185
}

gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache/GcpBuildCacheService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ internal class GcpBuildCacheService(
7070
storageService.store(cacheKey, output.toByteArray())
7171
}
7272

73+
fun validateConfiguration() {
74+
storageService.validateConfiguration()
75+
}
76+
7377
companion object {
7478
// Build Cache Key Helpers
7579
private val SLASHES = """"/+""".toRegex()

gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache/GcpBuildCacheServiceFactory.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ class GcpBuildCacheServiceFactory : BuildCacheServiceFactory<GcpBuildCache> {
3939
"${buildCache.credentials is ExportedKeyGcpCredentials}"
4040
)
4141

42-
return GcpBuildCacheService(
42+
val service = GcpBuildCacheService(
4343
buildCache.projectId,
4444
buildCache.bucketName,
4545
buildCache.credentials,
4646
buildCache.isPush,
4747
buildCache.isEnabled
4848
)
49+
service.validateConfiguration()
50+
return service
4951
}
5052
}

gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache/GcpStorageService.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ internal class GcpStorageService(
4545
logger.info("Not Enabled")
4646
return null
4747
}
48-
4948
val blobId = BlobId.of(bucketName, cacheKey)
5049
logger.info("Loading $cacheKey from ${blobId.name}")
5150
return load(storageOptions, blobId, sizeThreshold)
@@ -80,6 +79,16 @@ internal class GcpStorageService(
8079
return Companion.delete(storageOptions, blobId)
8180
}
8281

82+
override fun validateConfiguration() {
83+
if (storageOptions?.service?.get(bucketName, Storage.BucketGetOption.fields()) == null) {
84+
throw Exception("""
85+
Bucket $bucketName under project $projectId cannot be found or it is not accessible using the provided
86+
credentials.
87+
""".trimIndent()
88+
)
89+
}
90+
}
91+
8392
override fun close() {
8493
// Does nothing
8594
}

gcpbuildcache/src/main/kotlin/androidx/build/gradle/gcpbuildcache/StorageService.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ interface StorageService : Closeable {
5959
* @param cacheKey is the unique key that can identify a resource that needs to be removed.
6060
*/
6161
fun delete(cacheKey: String): Boolean
62+
63+
/**
64+
* Checks of the current configuration is valid. Throws an exception if the state is bad.
65+
*/
66+
fun validateConfiguration()
6267
}

0 commit comments

Comments
 (0)