All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyun.kms.kms20160120.handlers.GetSecretValueTransferHandler Maven / Gradle / Ivy

Go to download

Alibaba Cloud KMS SDK for Java Copyright (C) Alibaba Cloud Computing All rights reserved. 版权所有 (C)阿里云计算有限公司 http://www.aliyun.com

There is a newer version: 1.2.5
Show 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.GetSecretValueRequest;
import com.aliyun.dkms.gcs.sdk.models.GetSecretValueResponse;
import com.aliyun.kms.kms20160120.model.KmsConfig;
import com.aliyun.kms.kms20160120.model.KmsRuntimeOptions;
import com.aliyun.kms20160120.models.GetSecretValueResponseBody;
import com.aliyun.tea.TeaException;
import com.aliyun.teaopenapi.models.OpenApiRequest;

import java.net.HttpURLConnection;
import java.util.Map;

public class GetSecretValueTransferHandler implements KmsTransferHandler {

    private Client client;
    private String action;

    public GetSecretValueTransferHandler(Client client, KmsConfig kmsConfig, String action) {
        this.client = client;
        this.action = action;
    }

    @Override
    public GetSecretValueRequest buildDKMSRequest(OpenApiRequest request, KmsRuntimeOptions runtimeOptions) throws TeaException {
        Map query = request.getQuery();
        GetSecretValueRequest getSecretValueDKmsRequest = new GetSecretValueRequest();
        getSecretValueDKmsRequest.setSecretName(query.get("SecretName"));
        getSecretValueDKmsRequest.setFetchExtendedConfig(Boolean.parseBoolean(query.getOrDefault("FetchExtendedConfig", "false")));
        getSecretValueDKmsRequest.setVersionId(query.get("VersionId"));
        getSecretValueDKmsRequest.setVersionStage(query.get("VersionStage"));
        return getSecretValueDKmsRequest;
    }


    @Override
    public GetSecretValueResponse callDKMS(GetSecretValueRequest getSecretValueRequest, KmsRuntimeOptions runtimeOptions) throws Exception {
        RuntimeOptions dkmsRuntimeOptions = transferRuntimeOptions(runtimeOptions);
        dkmsRuntimeOptions.setResponseHeaders(responseHeaders);
        return this.client.getSecretValueWithOptions(getSecretValueRequest, dkmsRuntimeOptions);
    }

    @Override
    public Map transferToOpenApiResponse(GetSecretValueResponse getSecretValueResponse, KmsRuntimeOptions runtimeOptions) throws TeaException {
        GetSecretValueResponseBody body = new GetSecretValueResponseBody();
        body.setAutomaticRotation(getSecretValueResponse.getAutomaticRotation());
        body.setCreateTime(getSecretValueResponse.getCreateTime());
        body.setExtendedConfig(getSecretValueResponse.getExtendedConfig());
        body.setLastRotationDate(getSecretValueResponse.getLastRotationDate());
        body.setNextRotationDate(getSecretValueResponse.getNextRotationDate());
        body.setRotationInterval(getSecretValueResponse.getRotationInterval());
        body.setSecretData(getSecretValueResponse.getSecretData());
        body.setSecretDataType(getSecretValueResponse.getSecretDataType());
        body.setSecretName(getSecretValueResponse.getSecretName());
        body.setSecretType(getSecretValueResponse.getSecretType());
        body.setVersionId(getSecretValueResponse.getVersionId());
        GetSecretValueResponseBody.GetSecretValueResponseBodyVersionStages versionStage = new GetSecretValueResponseBody.GetSecretValueResponseBodyVersionStages();
        versionStage.setVersionStage(getSecretValueResponse.getVersionStages());
        body.setVersionStages(versionStage);
        body.setRequestId(getSecretValueResponse.getRequestId());
        com.aliyun.kms20160120.models.GetSecretValueResponse response = new com.aliyun.kms20160120.models.GetSecretValueResponse();
        response.setBody(body);
        response.setHeaders(getSecretValueResponse.getResponseHeaders());
        response.setStatusCode(HttpURLConnection.HTTP_OK);
        return response.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