Skip to content

Commit

Permalink
fix: Set Artifact ID using the static method. (#1938)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttosta-google authored Apr 11, 2024
1 parent 315ecfb commit d14bd65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public static void reset() {
* @throws IllegalStateException if the SQLAdmin client has already been initialized
*/
public static void addArtifactId(String artifactId) {
InternalConnectorRegistry.getInstance().addArtifactId(artifactId);
InternalConnectorRegistry.addArtifactId(artifactId, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,33 @@ private static String getVersion() {
* Internal use only: Sets the default string which is appended to the SQLAdmin API client
* User-Agent header.
*
* <p>This is used by the specific database connector socket factory implementations to append
* their database name to the user agent.
* @param artifactId is the Artifact ID.
* @param addVersion whether the version should be appended to the ID.
*/
public static void addArtifactId(String artifactId) {
String userAgent = artifactId + "/" + version;
public static void addArtifactId(String artifactId, boolean addVersion) {
String userAgent = artifactId;

if (addVersion) {
userAgent += "/" + version;
}
if (!userAgents.contains(userAgent)) {
userAgents.add(userAgent);
}
}

/**
* Internal use only: Sets the default string which is appended to the SQLAdmin API client
* User-Agent header.
*
* <p>This is used by the specific database connector socket factory implementations to append
* their database name to the user agent. The version is appended to the ID.
*
* @param artifactId is the Artifact ID.
*/
public static void addArtifactId(String artifactId) {
addArtifactId(artifactId, true);
}

/** Resets the values of User Agent fields for unit tests. */
@VisibleForTesting
static void resetUserAgent() {
Expand Down

0 comments on commit d14bd65

Please sign in to comment.