Skip to content

Commit d14bd65

Browse files
authoredApr 11, 2024··
fix: Set Artifact ID using the static method. (#1938)
1 parent 315ecfb commit d14bd65

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed
 

‎core/src/main/java/com/google/cloud/sql/ConnectorRegistry.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ public static void reset() {
6464
* @throws IllegalStateException if the SQLAdmin client has already been initialized
6565
*/
6666
public static void addArtifactId(String artifactId) {
67-
InternalConnectorRegistry.getInstance().addArtifactId(artifactId);
67+
InternalConnectorRegistry.addArtifactId(artifactId, false);
6868
}
6969
}

‎core/src/main/java/com/google/cloud/sql/core/InternalConnectorRegistry.java

+21-4
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,33 @@ private static String getVersion() {
231231
* Internal use only: Sets the default string which is appended to the SQLAdmin API client
232232
* User-Agent header.
233233
*
234-
* <p>This is used by the specific database connector socket factory implementations to append
235-
* their database name to the user agent.
234+
* @param artifactId is the Artifact ID.
235+
* @param addVersion whether the version should be appended to the ID.
236236
*/
237-
public static void addArtifactId(String artifactId) {
238-
String userAgent = artifactId + "/" + version;
237+
public static void addArtifactId(String artifactId, boolean addVersion) {
238+
String userAgent = artifactId;
239+
240+
if (addVersion) {
241+
userAgent += "/" + version;
242+
}
239243
if (!userAgents.contains(userAgent)) {
240244
userAgents.add(userAgent);
241245
}
242246
}
243247

248+
/**
249+
* Internal use only: Sets the default string which is appended to the SQLAdmin API client
250+
* User-Agent header.
251+
*
252+
* <p>This is used by the specific database connector socket factory implementations to append
253+
* their database name to the user agent. The version is appended to the ID.
254+
*
255+
* @param artifactId is the Artifact ID.
256+
*/
257+
public static void addArtifactId(String artifactId) {
258+
addArtifactId(artifactId, true);
259+
}
260+
244261
/** Resets the values of User Agent fields for unit tests. */
245262
@VisibleForTesting
246263
static void resetUserAgent() {

0 commit comments

Comments
 (0)
Please sign in to comment.