Skip to content

Commit

Permalink
Merge pull request #14 from tikurahul/main
Browse files Browse the repository at this point in the history
Disable request level logging for http requests.
tikurahul authored Apr 18, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 4e84de0 + 20fc6cf commit 4fed3a7
Showing 3 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gcpbuildcache/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ gradlePlugin {
}

group = "androidx.build.gradle.gcpbuildcache"
version = "1.0.0-alpha01"
version = "1.0.0-alpha02"

testing {
suites {
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ package androidx.build.gradle.gcpbuildcache
import com.google.api.gax.retrying.RetrySettings
import com.google.auth.oauth2.GoogleCredentials
import com.google.cloud.ReadChannel
import com.google.cloud.http.HttpTransportOptions
import com.google.cloud.storage.BlobId
import com.google.cloud.storage.BlobInfo
import com.google.cloud.storage.StorageOptions
@@ -93,6 +94,10 @@ internal class GcpStorageService(
Logging.getLogger("GcpStorageService")
}

private val transportOptions by lazy {
GcpTransportOptions(HttpTransportOptions.newBuilder())
}

// The OAuth scopes for reading and writing to buckets.
// https://cloud.google.com/storage/docs/authentication
private const val STORAGE_READ_ONLY = "https://www.googleapis.com/auth/devstorage.read_only"
@@ -130,7 +135,9 @@ internal class GcpStorageService(
retrySettings.retryDelayMultiplier = 2.0
return StorageOptions.newBuilder().setCredentials(credentials)
.setStorageRetryStrategy(StorageRetryStrategy.getUniformStorageRetryStrategy()).setProjectId(projectId)
.setRetrySettings(retrySettings.build()).build()
.setRetrySettings(retrySettings.build())
.setTransportOptions(transportOptions)
.build()
}

private fun credentials(
@@ -151,8 +158,9 @@ internal class GcpStorageService(
val path = gcpCredentials.pathToCredentials
if (!path.exists()) throw GradleException("Credentials path $path does not exist")
if (!path.isFile) throw GradleException("Credentials path $path is not a file")

GoogleCredentials.fromStream(path.inputStream()).createScoped(scopes)
// Use the underlying transport factory to ensure logging is disabled.
GoogleCredentials.fromStream(path.inputStream(), transportOptions.httpTransportFactory)
.createScoped(scopes)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package androidx.build.gradle.gcpbuildcache

import com.google.api.client.http.HttpRequestInitializer
import com.google.cloud.ServiceOptions
import com.google.cloud.http.HttpTransportOptions

/**
* Sets up transport options and disables logging.
*/
internal class GcpTransportOptions(builder: Builder) : HttpTransportOptions(builder) {
override fun getHttpRequestInitializer(serviceOptions: ServiceOptions<*, *>?): HttpRequestInitializer {
// Delegate to the underlying initializer.
val initializer = super.getHttpRequestInitializer(serviceOptions)
return HttpRequestInitializer {
it.isLoggingEnabled = false
initializer.initialize(it)
}
}
}

0 comments on commit 4fed3a7

Please sign in to comment.