Skip to content

Commit ec4133d

Browse files
authored
Merge branch 'main' into new-library/health-l1quL
2 parents 4214dc7 + 24b1719 commit ec4133d

64 files changed

Lines changed: 1803 additions & 535 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/generated_files_sync.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ jobs:
175175
|grep --invert-match samples \
176176
|grep --invert-match benchmark \
177177
|grep --invert-match grafeas \
178+
|grep --invert-match '/tools/' \
178179
|grep --invert-match 'cloud-build.*v2' \
179180
|grep --invert-match 'google/monitoring/v3/DroppedLabelsOuterClass.java' \
180181
|grep --invert-match 'google/cloud/policytroubleshooter/v1/Explanations.java')

.kokoro/common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ excluded_modules=(
2727
'sdk-platform-java'
2828
'sdk-platform-java/java-shared-dependencies/dependency-analyzer'
2929
'sdk-platform-java/java-shared-dependencies/dependency-convergence-check'
30-
'sdk-platform-java/java-showcase'
30+
'java-showcase'
3131
'sdk-platform-java/java-showcase-3.21.0'
3232
'sdk-platform-java/java-showcase-3.25.8'
3333
'java-spanner'
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_a:3.61.0" # {x-version-update:google-cloud-shared-dependencies:current}
7+
}
8+
9+
env_vars: {
10+
key: "JOB_TYPE"
11+
value: "graalvm-single"
12+
}
13+
14+
# TODO: remove this after we've migrated all tests and scripts
15+
env_vars: {
16+
key: "GCLOUD_PROJECT"
17+
value: "gcloud-devel"
18+
}
19+
20+
env_vars: {
21+
key: "GOOGLE_CLOUD_PROJECT"
22+
value: "gcloud-devel"
23+
}
24+
25+
env_vars: {
26+
key: "GOOGLE_APPLICATION_CREDENTIALS"
27+
value: "secret_manager/java-it-service-account"
28+
}
29+
30+
env_vars: {
31+
key: "SECRET_MANAGER_KEYS"
32+
value: "java-it-service-account"
33+
}
34+
35+
env_vars: {
36+
key: "IT_SERVICE_ACCOUNT_EMAIL"
37+
value: "it-service-account@gcloud-devel.iam.gserviceaccount.com"
38+
}
39+
env_vars: {
40+
key: "BUILD_SUBDIR"
41+
value: "java-pubsub"
42+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Configure the docker image for kokoro-trampoline.
4+
env_vars: {
5+
key: "TRAMPOLINE_IMAGE"
6+
value: "gcr.io/cloud-devrel-kokoro-resources/java8"
7+
}
8+
9+
env_vars: {
10+
key: "JOB_TYPE"
11+
value: "integration-single"
12+
}
13+
14+
# TODO: remove this after we've migrated all tests and scripts
15+
env_vars: {
16+
key: "GCLOUD_PROJECT"
17+
value: "gcloud-devel"
18+
}
19+
20+
env_vars: {
21+
key: "GOOGLE_CLOUD_PROJECT"
22+
value: "gcloud-devel"
23+
}
24+
25+
env_vars: {
26+
key: "GOOGLE_APPLICATION_CREDENTIALS"
27+
value: "secret_manager/java-it-service-account"
28+
}
29+
30+
env_vars: {
31+
key: "SECRET_MANAGER_KEYS"
32+
value: "java-it-service-account"
33+
}
34+
35+
36+
env_vars: {
37+
key: "BUILD_SUBDIR"
38+
value: "java-pubsub"
39+
}

generation_config.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,3 +3098,55 @@ libraries:
30983098
GAPICs:
30993099
- proto_path: google/cloud/workstations/v1
31003100
- proto_path: google/cloud/workstations/v1beta
3101+
<<<<<<< new-library/health-l1quL
3102+
=======
3103+
- api_shortname: common-protos
3104+
name_pretty: Common Protos
3105+
product_documentation: https://github.com/googleapis/api-common-protos
3106+
api_description: Protobuf classes for Google's common protos.
3107+
release_level: stable
3108+
client_documentation: https://cloud.google.com/java/docs/reference/proto-google-common-protos/latest/history
3109+
distribution_name: com.google.api.grpc:proto-google-common-protos
3110+
excluded_dependencies: proto-google-common-protos,grpc-google-common-protos,proto-google-common-protos-parent
3111+
excluded_poms: proto-google-common-protos-bom,proto-google-common-protos
3112+
library_type: OTHER
3113+
3114+
GAPICs:
3115+
- proto_path: google/api
3116+
- proto_path: google/apps/card/v1
3117+
- proto_path: google/cloud
3118+
- proto_path: google/cloud/audit
3119+
- proto_path: google/cloud/location
3120+
- proto_path: google/geo/type
3121+
- proto_path: google/logging/type
3122+
- proto_path: google/longrunning
3123+
- proto_path: google/rpc
3124+
- proto_path: google/rpc/context
3125+
- proto_path: google/shopping/type
3126+
- proto_path: google/type
3127+
- api_shortname: showcase
3128+
excluded_poms: gapic-showcase-bom
3129+
name_pretty: Showcase
3130+
api_description: Showcase module
3131+
product_documentation: https://cloud.google.com/dummy
3132+
distribution_name: com.google.cloud:gapic-showcase
3133+
library_type: OTHER
3134+
GAPICs:
3135+
- proto_path: schema/google/showcase/v1beta1
3136+
- api_shortname: iam
3137+
name_pretty: IAM
3138+
product_documentation: https://cloud.google.com/iam
3139+
api_description: Manages access control for Google Cloud Platform resources
3140+
release_level: stable
3141+
client_documentation: https://cloud.google.com/java/docs/reference/proto-google-iam-v1/latest/overview
3142+
distribution_name: com.google.api.grpc:proto-google-iam-v1
3143+
excluded_dependencies: "grpc-google-iam-v1"
3144+
excluded_poms: "proto-google-iam-v1-bom,google-iam-policy,proto-google-iam-v1"
3145+
library_type: OTHER
3146+
GAPICs:
3147+
- proto_path: google/iam/v1
3148+
- proto_path: google/iam/v2
3149+
- proto_path: google/iam/v2beta
3150+
- proto_path: google/iam/v3
3151+
- proto_path: google/iam/v3beta
3152+
>>>>>>> main
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
drivers/**
22
target-it/**
33
*logs*/**
4-
**/ITBigQueryJDBCLocalTest.java
4+
**/ITBigQueryJDBCLocalTest.java
5+
6+
tools/**/*.class
7+
tools/**/*.jfr

java-bigquery/google-cloud-bigquery-jdbc/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@
307307
<artifactId>mockito-core</artifactId>
308308
<scope>test</scope>
309309
</dependency>
310+
<dependency>
311+
<groupId>org.mockito</groupId>
312+
<artifactId>mockito-inline</artifactId>
313+
<scope>test</scope>
314+
</dependency>
310315
<dependency>
311316
<groupId>org.mockito</groupId>
312317
<artifactId>mockito-junit-jupiter</artifactId>

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryConnection.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@
5858
import java.util.Map;
5959
import java.util.Properties;
6060
import java.util.Set;
61+
import java.util.UUID;
6162
import java.util.concurrent.ConcurrentHashMap;
6263
import java.util.concurrent.Executor;
6364
import java.util.concurrent.TimeUnit;
64-
import java.util.concurrent.atomic.AtomicLong;
6565

6666
/**
6767
* An implementation of {@link java.sql.Connection} for establishing a connection with BigQuery and
@@ -74,7 +74,6 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
7474
private final BigQueryJdbcCustomLogger LOG = new BigQueryJdbcCustomLogger(this.toString());
7575
String connectionClassName = this.toString();
7676
private final String connectionId;
77-
private static final AtomicLong connectionIdCounter = new AtomicLong(1);
7877
private static final String DEFAULT_JDBC_TOKEN_VALUE = "Google-BigQuery-JDBC-Driver";
7978
private static final String DEFAULT_VERSION = "0.0.0";
8079
private HeaderProvider headerProvider;
@@ -143,13 +142,14 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
143142
String partnerToken;
144143
DatabaseMetaData databaseMetaData;
145144
Boolean reqGoogleDriveScope;
145+
private boolean isReadOnlyTokenUsed = false;
146146

147147
BigQueryConnection(String url) throws IOException {
148148
this(url, DataSource.fromUrl(url));
149149
}
150150

151151
BigQueryConnection(String url, DataSource ds) throws IOException {
152-
this.connectionId = String.valueOf(connectionIdCounter.getAndIncrement());
152+
this.connectionId = UUID.randomUUID().toString();
153153
try (BigQueryJdbcMdc.MdcCloseable mdc =
154154
BigQueryJdbcMdc.registerInstance(this, this.connectionId)) {
155155
LOG.finest("++enter++");
@@ -172,6 +172,7 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
172172
this.jobTimeoutInSeconds = ds.getJobTimeout();
173173
this.authProperties =
174174
BigQueryJdbcOAuthUtility.parseOAuthProperties(ds, this.connectionClassName);
175+
this.isReadOnlyTokenUsed = checkIsReadOnlyTokenUsed(this.authProperties);
175176
this.catalog = ds.getProjectId();
176177
this.universeDomain = ds.getUniverseDomain();
177178

@@ -1193,4 +1194,18 @@ public CallableStatement prepareCall(
11931194
}
11941195
return prepareCall(sql);
11951196
}
1197+
1198+
public boolean isReadOnlyTokenUsed() {
1199+
return this.isReadOnlyTokenUsed;
1200+
}
1201+
1202+
private boolean checkIsReadOnlyTokenUsed(Map<String, String> authProps) {
1203+
String readonlyValue =
1204+
authProps.get(BigQueryJdbcUrlUtility.OAUTH_ACCESS_TOKEN_READONLY_PROPERTY_NAME);
1205+
if (readonlyValue != null) {
1206+
return BigQueryJdbcUrlUtility.convertIntToBoolean(
1207+
readonlyValue, BigQueryJdbcUrlUtility.OAUTH_ACCESS_TOKEN_READONLY_PROPERTY_NAME);
1208+
}
1209+
return false;
1210+
}
11961211
}

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcMdc.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616

1717
package com.google.cloud.bigquery.jdbc;
1818

19+
import java.util.UUID;
1920
import java.util.concurrent.ConcurrentHashMap;
20-
import java.util.concurrent.atomic.AtomicLong;
2121

2222
/**
2323
* Lightweight MDC implementation for the BigQuery JDBC driver using InheritableThreadLocal.
2424
* Allocates a dedicated, independent InheritableThreadLocal object per concrete BigQueryConnection
2525
* instance.
2626
*/
2727
class BigQueryJdbcMdc {
28-
private static final AtomicLong nextId = new AtomicLong(1);
2928
private static final ConcurrentHashMap<BigQueryConnection, InheritableThreadLocal<String>>
3029
instanceLocals = new ConcurrentHashMap<>();
3130
private static final ConcurrentHashMap<BigQueryConnection, String> instanceIds =
@@ -41,9 +40,8 @@ static MdcCloseable registerInstance(BigQueryConnection connection, String id) {
4140
instanceIds.computeIfAbsent(
4241
connection,
4342
k -> {
44-
String suffix =
45-
(id != null && !id.isEmpty()) ? id : String.valueOf(nextId.getAndIncrement());
46-
return "JdbcConnection-" + suffix;
43+
String baseId = (id != null && !id.isEmpty()) ? id : UUID.randomUUID().toString();
44+
return baseId;
4745
});
4846

4947
currentConnectionId.set(cleanId);

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOAuthUtility.java

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ static Map<String, String> parseOAuthProperties(DataSource ds, String callerClas
170170
}
171171
oauthProperties.put(
172172
BigQueryJdbcUrlUtility.OAUTH_ACCESS_TOKEN_PROPERTY_NAME, ds.getOAuthAccessToken());
173+
oauthProperties.put(
174+
BigQueryJdbcUrlUtility.OAUTH_ACCESS_TOKEN_READONLY_PROPERTY_NAME,
175+
String.valueOf(ds.getOAuthAccessTokenReadonly()));
173176
LOG.fine("OAuthAccessToken provided.");
174177
break;
175178
case APPLICATION_DEFAULT_CREDENTIALS:
@@ -230,26 +233,22 @@ static Map<String, String> parseOAuthProperties(DataSource ds, String callerClas
230233
break;
231234
}
232235

233-
if (authType == AuthType.GOOGLE_SERVICE_ACCOUNT
234-
|| authType == AuthType.GOOGLE_USER_ACCOUNT
235-
|| authType == AuthType.PRE_GENERATED_TOKEN) {
236-
oauthProperties.put(
237-
BigQueryJdbcUrlUtility.OAUTH_SA_IMPERSONATION_EMAIL_PROPERTY_NAME,
238-
ds.getOAuthSAImpersonationEmail());
239-
oauthProperties.put(
240-
BigQueryJdbcUrlUtility.OAUTH_SA_IMPERSONATION_CHAIN_PROPERTY_NAME,
241-
ds.getOAuthSAImpersonationChain());
242-
oauthProperties.put(
243-
BigQueryJdbcUrlUtility.OAUTH_SA_IMPERSONATION_SCOPES_PROPERTY_NAME,
244-
ds.getOAuthSAImpersonationScopes() != null
245-
? ds.getOAuthSAImpersonationScopes()
246-
: BIGQUERY_SCOPE);
247-
oauthProperties.put(
248-
BigQueryJdbcUrlUtility.OAUTH_SA_IMPERSONATION_TOKEN_LIFETIME_PROPERTY_NAME,
249-
ds.getOAuthSAImpersonationTokenLifetime() != null
250-
? ds.getOAuthSAImpersonationTokenLifetime()
251-
: BigQueryJdbcUrlUtility.DEFAULT_OAUTH_SA_IMPERSONATION_TOKEN_LIFETIME_VALUE);
252-
}
236+
oauthProperties.put(
237+
BigQueryJdbcUrlUtility.OAUTH_SA_IMPERSONATION_EMAIL_PROPERTY_NAME,
238+
ds.getOAuthSAImpersonationEmail());
239+
oauthProperties.put(
240+
BigQueryJdbcUrlUtility.OAUTH_SA_IMPERSONATION_CHAIN_PROPERTY_NAME,
241+
ds.getOAuthSAImpersonationChain());
242+
oauthProperties.put(
243+
BigQueryJdbcUrlUtility.OAUTH_SA_IMPERSONATION_SCOPES_PROPERTY_NAME,
244+
ds.getOAuthSAImpersonationScopes() != null
245+
? ds.getOAuthSAImpersonationScopes()
246+
: BIGQUERY_SCOPE);
247+
oauthProperties.put(
248+
BigQueryJdbcUrlUtility.OAUTH_SA_IMPERSONATION_TOKEN_LIFETIME_PROPERTY_NAME,
249+
ds.getOAuthSAImpersonationTokenLifetime() != null
250+
? ds.getOAuthSAImpersonationTokenLifetime()
251+
: BigQueryJdbcUrlUtility.DEFAULT_OAUTH_SA_IMPERSONATION_TOKEN_LIFETIME_VALUE);
253252
return oauthProperties;
254253
}
255254

@@ -284,12 +283,9 @@ static GoogleCredentials getCredentials(
284283
getPreGeneratedTokensCredentials(authProperties, overrideProperties, callerClassName);
285284
break;
286285
case APPLICATION_DEFAULT_CREDENTIALS:
287-
// This auth method doesn't support service account impersonation
288-
289286
credentials = getApplicationDefaultCredentials(callerClassName);
290287
break;
291288
case EXTERNAL_ACCOUNT_AUTH:
292-
// This auth method doesn't support service account impersonation
293289
credentials = getExternalAccountAuthCredentials(authProperties, callerClassName);
294290
break;
295291
default:

0 commit comments

Comments
 (0)