com.aliyun.kms.kms20160120.handlers.GetPublicKeyTransferHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alibabacloud-kms-java-sdk Show documentation
Show all versions of alibabacloud-kms-java-sdk Show documentation
Alibaba Cloud KMS SDK for Java
Copyright (C) Alibaba Cloud Computing
All rights reserved.
版权所有 (C)阿里云计算有限公司
http://www.aliyun.com
The newest version!
package com.aliyun.kms.kms20160120.handlers;
import com.aliyun.dkms.gcs.openapi.util.models.RuntimeOptions;
import com.aliyun.dkms.gcs.sdk.Client;
import com.aliyun.dkms.gcs.sdk.models.GetPublicKeyRequest;
import com.aliyun.dkms.gcs.sdk.models.GetPublicKeyResponse;
import com.aliyun.kms.kms20160120.model.KmsConfig;
import com.aliyun.kms.kms20160120.model.KmsRuntimeOptions;
import com.aliyun.kms.kms20160120.utils.Constants;
import com.aliyun.kms20160120.models.GetPublicKeyResponseBody;
import com.aliyun.tea.TeaException;
import com.aliyun.tea.TeaModel;
import com.aliyun.tea.utils.StringUtils;
import com.aliyun.teaopenapi.models.OpenApiRequest;
import java.net.HttpURLConnection;
import java.util.HashMap;
import java.util.Map;
public class GetPublicKeyTransferHandler implements KmsTransferHandler {
private Client client;
private String action;
public GetPublicKeyTransferHandler(Client client, KmsConfig kmsConfig, String action) {
this.client = client;
this.action = action;
}
@Override
public GetPublicKeyRequest buildDKMSRequest(OpenApiRequest request, KmsRuntimeOptions runtimeOptions) throws TeaException {
Map query = request.getQuery();
GetPublicKeyRequest getPublicKeyDKmsRequest = new GetPublicKeyRequest();
getPublicKeyDKmsRequest.setKeyId(query.get("KeyId"));
final String keyVersionId = query.get("KeyVersionId");
if(!StringUtils.isEmpty(keyVersionId)) {
getPublicKeyDKmsRequest.setRequestHeaders(new HashMap() {{
put(Constants.MIGRATION_KEY_VERSION_ID_KEY, keyVersionId);
}});
}
return getPublicKeyDKmsRequest;
}
@Override
public GetPublicKeyResponse callDKMS(GetPublicKeyRequest getPublicKeyRequest, KmsRuntimeOptions runtimeOptions) throws Exception {
RuntimeOptions dkmsRuntimeOptions = transferRuntimeOptions(runtimeOptions);
dkmsRuntimeOptions.setResponseHeaders(responseHeaders);
return client.getPublicKeyWithOptions(getPublicKeyRequest, dkmsRuntimeOptions);
}
@Override
public Map transferToOpenApiResponse(GetPublicKeyResponse getPublicKeyResponse, KmsRuntimeOptions runtimeOptions) throws TeaException {
Map responseHeaders = getPublicKeyResponse.getResponseHeaders();
String keyVersionId = null;
if (responseHeaders != null) {
keyVersionId = responseHeaders.get(Constants.MIGRATION_KEY_VERSION_ID_KEY);
}
GetPublicKeyResponseBody body = new GetPublicKeyResponseBody();
body.setKeyId(getPublicKeyResponse.getKeyId());
body.setKeyVersionId(keyVersionId);
body.setRequestId(getPublicKeyResponse.getRequestId());
body.setPublicKey(getPublicKeyResponse.getPublicKey());
final com.aliyun.kms20160120.models.GetPublicKeyResponse getPublicKeyKmsResponse = new com.aliyun.kms20160120.models.GetPublicKeyResponse();
getPublicKeyKmsResponse.setBody(body);
getPublicKeyKmsResponse.setHeaders(responseHeaders);
getPublicKeyKmsResponse.setStatusCode(HttpURLConnection.HTTP_OK);
return getPublicKeyKmsResponse.toMap();
}
@Override
public com.aliyun.dkms.gcs.openapi.Client getClient() {
return client;
}
@Override
public String getAction() {
return action;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy