@@ -2,6 +2,8 @@ package ftl.client.google
22
33import com.google.api.client.http.GoogleApiLogger
44import com.google.api.client.http.HttpRequestInitializer
5+ import com.google.api.client.http.apache.v2.ApacheHttpTransport
6+ import com.google.auth.http.HttpTransportFactory
57import com.google.auth.oauth2.AccessToken
68import com.google.auth.oauth2.GoogleCredentials
79import com.google.auth.oauth2.ServiceAccountCredentials
@@ -10,6 +12,12 @@ import flank.common.isWindows
1012import ftl.config.FtlConstants
1113import ftl.http.HttpTimeoutIncrease
1214import ftl.run.exception.FlankGeneralError
15+ import org.apache.http.HttpHost
16+ import org.apache.http.auth.AuthScope
17+ import org.apache.http.auth.UsernamePasswordCredentials
18+ import org.apache.http.impl.client.BasicCredentialsProvider
19+ import org.apache.http.impl.client.ProxyAuthenticationStrategy
20+ import org.apache.http.impl.conn.DefaultProxyRoutePlanner
1321import java.io.IOException
1422import java.util.Date
1523
@@ -19,7 +27,12 @@ val credential: GoogleCredentials by lazy {
1927 else ->
2028 runCatching {
2129 GoogleApiLogger .silenceComputeEngine()
22- ServiceAccountCredentials .getApplicationDefault()
30+ val httpTransportFactory = getHttpTransportFactory()
31+ if (httpTransportFactory != null ) {
32+ ServiceAccountCredentials .getApplicationDefault(httpTransportFactory)
33+ } else {
34+ ServiceAccountCredentials .getApplicationDefault()
35+ }
2336 }.getOrElse {
2437 when {
2538 isWindows -> loadCredentialsWindows()
@@ -29,6 +42,31 @@ val credential: GoogleCredentials by lazy {
2942 }
3043}
3144
45+ private fun getHttpTransportFactory (): HttpTransportFactory ? {
46+ val proxyHost = System .getProperty(" http.proxyHost" ) ? : return null
47+ val proxyPort = System .getProperty(" http.proxyPort" )?.toInt() ? : return null
48+ val proxyPassword = System .getProperty(" http.proxyPassword" ) ? : return null
49+ val proxyUsername = System .getProperty(" http.proxyUser" ) ? : return null
50+
51+ val proxyHostDetails = HttpHost (proxyHost, proxyPort)
52+ val httpRoutePlanner = DefaultProxyRoutePlanner (proxyHostDetails)
53+
54+ val credentialsProvider = BasicCredentialsProvider ()
55+ credentialsProvider.setCredentials(
56+ AuthScope (proxyHostDetails.getHostName(), proxyHostDetails.getPort()),
57+ UsernamePasswordCredentials (proxyUsername, proxyPassword)
58+ )
59+
60+ val httpClient = ApacheHttpTransport .newDefaultHttpClientBuilder()
61+ .setRoutePlanner(httpRoutePlanner)
62+ .setProxyAuthenticationStrategy(ProxyAuthenticationStrategy .INSTANCE )
63+ .setDefaultCredentialsProvider(credentialsProvider)
64+ .build()
65+
66+ val httpTransport = ApacheHttpTransport (httpClient)
67+ return HttpTransportFactory { httpTransport }
68+ }
69+
3270private fun loadCredentialsWindows () = runCatching {
3371 loadGoogleAccountCredentials()
3472}.getOrElse {
0 commit comments