Skip to content

Commit

Permalink
Merge pull request #24 from androidx/invalidbucketname
Browse files Browse the repository at this point in the history
Validate that configured bucket for the project is valid
  • Loading branch information
liutikas committed Jun 29, 2022
2 parents 25f9708 + f4d34df commit 89488af
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ In your `settings.gradle.kts` file add the following

```kotlin
plugins {
id("androidx.build.gradle.gcpbuildcache") version "1.0.0-alpha05"
id("androidx.build.gradle.gcpbuildcache") version "1.0.0-alpha06"
}

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

```groovy
plugins {
id("androidx.build.gradle.gcpbuildcache") version "1.0.0-alpha05"
id("androidx.build.gradle.gcpbuildcache") version "1.0.0-alpha06"
}
import androidx.build.gradle.gcpbuildcache.GcpBuildCache
Expand Down
4 changes: 4 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release notes for GCP backed Gradle Remote Cache

## 1.0.0-alpha06

- Warn when a user incorrectly configures GCP bucket to be used for the cache.

## 1.0.0-alpha05

- Downloads `Blob`s to an intermediate `Buffer` or a `File` depending on the size of the blob.
Expand Down
5 changes: 2 additions & 3 deletions gcpbuildcache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@ gradlePlugin {
id = "androidx.build.gradle.gcpbuildcache"
displayName = "Gradle GCP Build Cache Plugin"
description = """
Implementation of Gradle Build Cache that allows to use Google Cloud Platform
storage buckets as a back end.
- Warn when a user incorrectly configures GCP bucket to be used for the cache.
""".trimIndent()
implementationClass = "androidx.build.gradle.gcpbuildcache.GcpGradleBuildCachePlugin"
}
}
}

group = "androidx.build.gradle.gcpbuildcache"
version = "1.0.0-alpha05"
version = "1.0.0-alpha06"

testing {
suites {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ internal class FileSystemStorageService(
return file.delete()
}

override fun validateConfiguration() {
// There is nothing to validate
}

override fun close() {
location.deleteRecursively()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ internal class GcpBuildCacheService(
storageService.store(cacheKey, output.toByteArray())
}

fun validateConfiguration() {
storageService.validateConfiguration()
}

companion object {
// Build Cache Key Helpers
private val SLASHES = """"/+""".toRegex()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ class GcpBuildCacheServiceFactory : BuildCacheServiceFactory<GcpBuildCache> {
"${buildCache.credentials is ExportedKeyGcpCredentials}"
)

return GcpBuildCacheService(
val service = GcpBuildCacheService(
buildCache.projectId,
buildCache.bucketName,
buildCache.credentials,
buildCache.isPush,
buildCache.isEnabled
)
service.validateConfiguration()
return service
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ internal class GcpStorageService(
logger.info("Not Enabled")
return null
}

val blobId = BlobId.of(bucketName, cacheKey)
logger.info("Loading $cacheKey from ${blobId.name}")
return load(storageOptions, blobId, sizeThreshold)
Expand Down Expand Up @@ -80,6 +79,16 @@ internal class GcpStorageService(
return Companion.delete(storageOptions, blobId)
}

override fun validateConfiguration() {
if (storageOptions?.service?.get(bucketName, Storage.BucketGetOption.fields()) == null) {
throw Exception("""
Bucket $bucketName under project $projectId cannot be found or it is not accessible using the provided
credentials.
""".trimIndent()
)
}
}

override fun close() {
// Does nothing
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ interface StorageService : Closeable {
* @param cacheKey is the unique key that can identify a resource that needs to be removed.
*/
fun delete(cacheKey: String): Boolean

/**
* Checks of the current configuration is valid. Throws an exception if the state is bad.
*/
fun validateConfiguration()
}

0 comments on commit 89488af

Please sign in to comment.