Skip to content

Commit

Permalink
Add user agent (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
oobujieshi authored and yingzhi-aliyun committed Nov 17, 2023
1 parent 84f86bb commit 9da5772
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
9 changes: 4 additions & 5 deletions sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.aliyun.kms</groupId>
<artifactId>kms-transfer-client</artifactId>
<packaging>jar</packaging>
<version>0.2.0</version>
<version>0.2.1</version>
<name>kms-transfer-client</name>
<url>http://www.aliyun.com</url>
<description>Alibabacloud KMS Transfer Client for Java
Expand All @@ -30,7 +30,7 @@
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibabacloud-dkms-gcs-sdk</artifactId>
<version>0.4.0</version>
<version>0.5.1</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
Expand All @@ -54,9 +54,8 @@

<licenses>
<license>
<name/>
<url/>
<distribution/>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<scm>
Expand Down
12 changes: 12 additions & 0 deletions sdk/src/main/java/com/aliyun/kms/KmsTransferAcsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class KmsTransferAcsClient extends DefaultAcsClient {
public KmsTransferAcsClient(Config config) throws ClientException {
super();
try {
setUserAgent(config);
client = new Client(config);
} catch (Exception e) {
throw new ClientException(e);
Expand All @@ -42,6 +43,7 @@ public KmsTransferAcsClient(Config config) throws ClientException {
public KmsTransferAcsClient(String regionId, Config config) throws ClientException {
super(regionId);
try {
setUserAgent(config);
client = new Client(config);
} catch (Exception e) {
throw new ClientException(e);
Expand All @@ -58,6 +60,7 @@ public KmsTransferAcsClient(IClientProfile profile, Config config) {
super(profile);
ignoreSSLCerts = profile.getHttpClientConfig() == null ? false : profile.getHttpClientConfig().isIgnoreSSLCerts();
try {
setUserAgent(config);
client = new Client(config);
} catch (Exception e) {
throw new RuntimeException(e);
Expand All @@ -74,6 +77,7 @@ public KmsTransferAcsClient(IClientProfile profile, AlibabaCloudCredentials cred
super(profile, credentials);
ignoreSSLCerts = profile.getHttpClientConfig() == null ? false : profile.getHttpClientConfig().isIgnoreSSLCerts();
try {
setUserAgent(config);
client = new Client(config);
} catch (Exception e) {
throw new RuntimeException(e);
Expand All @@ -90,6 +94,7 @@ public KmsTransferAcsClient(IClientProfile profile, AlibabaCloudCredentialsProvi
super(profile, credentialsProvider);
ignoreSSLCerts = profile.getHttpClientConfig() == null ? false : profile.getHttpClientConfig().isIgnoreSSLCerts();
try {
setUserAgent(config);
client = new Client(config);
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -145,4 +150,11 @@ private <T extends AcsResponse> HttpResponse dispatchDKmsAction(KmsTransferHandl
return handler.handlerDKmsRequestWithOptions(request, runtimeOptions);
}

private void setUserAgent(Config config) {
if (config.getUserAgent() != null) {
config.setUserAgent(config.getUserAgent() + " " + SDK_USER_AGENT);
} else {
config.setUserAgent(SDK_USER_AGENT);
}
}
}
3 changes: 3 additions & 0 deletions sdk/src/main/java/com/aliyun/kms/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ public interface Constants {
String MIGRATION_KEY_VERSION_ID_KEY = "x-kms-migrationkeyversionid";
int NUMBER_OF_BYTES_AES_256 = 32;
int NUMBER_OF_BYTES_AES_128 = 16;
String SDK_NAME = "alibabacloud-dkms-transfer-java-sdk";
String SDK_VERSION = "0.2.1";
String SDK_USER_AGENT = SDK_NAME + "/" + SDK_VERSION;
}

0 comments on commit 9da5772

Please sign in to comment.