調用GetSecretValue介面擷取憑據值。
如果不指定版本號碼或版本狀態,則KMS預設返回被標記為ACSCurrent的版本憑據值。
如果憑據使用了使用者指定的密鑰來保護憑據值,則需要調用者同時具備相應主要金鑰的kms:Decrypt許可權。
本文將提供一個樣本,擷取一個名為secret001憑據的憑據值,返回結果顯示憑據值SecretData為testdata1。
調試
您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。
請求參數
|
名稱 |
類型 |
是否必選 |
樣本值 |
描述 |
| Action | String | 是 | GetSecretValue | 要執行的操作。取值:GetSecretValue。 |
| SecretName | String | 是 | secret001 | 憑據名稱或憑據資源名稱(ARN)。 說明 訪問其他阿里雲帳號下的憑據時,必須輸入憑據ARN。憑據ARN的格式為 acs:kms:${region}:${account}:secret/${secret-name}。 |
| VersionStage | String | 否 | ACSCurrent | 版本狀態。預設值:ACSCurrent。 輸入該參數時返回指定版本狀態的憑據值,不輸入該參數時返回ACSCurrent版本狀態的憑據值。 說明 RDS憑據、PolarDB憑據、Redis/Tair憑據、RAM憑據和ECS憑據只能擷取ACSPrevious和ACSCurrent對應版本的憑據值。 |
| VersionId | String | 否 | v1 | 版本號碼。 說明 RDS憑據、PolarDB憑據、Redis/Tair憑據、RAM憑據和ECS憑據不支援指定VersionId,設定該參數將被忽略。 |
| FetchExtendedConfig | Boolean | 否 | true | 是否擷取憑據的拓展配置。取值:
說明 通用憑據不支援拓展配置,設定該參數將被忽略。 |
| DryRun | String | 否 | false | 是否開啟DryRun模式。
DryRun模式用於測試API調用,驗證您是否具有相應資源的許可權,以及請求參數是否配置正確。DryRun模式開啟後,KMS會始終返回失敗並提示失敗原因。失敗原因包含如下:
|
關於公用請求參數的詳情,請參見公用參數。
返回資料
名稱 |
類型 |
樣本值 |
描述 |
| SecretDataType | String | binary | 憑據實值型別。取值:
|
| CreateTime | String | 2024-02-21T15:39:26Z | 建立憑據的時間。 |
| VersionId | String | v1 | 憑據的版本號碼。 |
| NextRotationDate | String | 2024-07-06T18:22:03Z | 下一次輪轉的時間。 說明 當自動輪轉開啟時,返回該參數。 |
| SecretData | String | testdata1 | 憑據值。KMS將儲存的密文憑據值進行解密後返回該參數。
|
| RotationInterval | String | 604800s | 憑據自動輪轉的周期。 格式為 說明 當自動輪轉開啟時,返回該參數。 |
| ExtendedConfig | String | {\"SecretSubType\":\"SingleUser\", \"DBInstanceId\":\"rm-uf667446pc955****\", \"CustomData\":{} } | 憑據的拓展配置。 說明 當FetchExtendedConfig取值為true時,僅RDS憑據、PolarDB憑據、Redis/Tair憑據、RAM憑據或ECS憑據返回該參數。 |
| LastRotationDate | String | 2023-07-05T08:22:03Z | 最近一次輪轉的時間。 說明 當憑據發生過輪轉時返回該參數。 |
| RequestId | String | 6a3e9c36-1150-4881-84d3-eb8672fcafad | 本次調用請求的ID,是由阿里雲為該請求產生的唯一識別碼,可用於排查和定位問題。 |
| SecretName | String | secret001 | 憑據名稱。 |
| AutomaticRotation | String | Enabled | 是否開啟了自動輪轉。取值:
說明 僅RDS憑據、PolarDB憑據、Redis/Tair憑據、RAM憑據或ECS憑據返回該參數。 |
| SecretType | String | Generic | 憑據類型。取值:
|
| VersionStages | Array of String | { "VersionStage": [ "ACSCurrent" ] } | 憑據版本的狀態標記。 |
樣本
請求樣本
http(s)://[Endpoint]/?Action=GetSecretValue
&SecretName=secret001
&VersionStage=ACSCurrent
&VersionId=v1
&FetchExtendedConfig=true
&DryRun=false
&公用請求參數
正常返回樣本
XML格式
HTTP/1.1 200 OK
Content-Type:application/xml
<GetSecretValueResponse>
<SecretDataType>binary</SecretDataType>
<CreateTime>2024-02-21T15:39:26Z</CreateTime>
<VersionId>v1</VersionId>
<NextRotationDate>2024-07-06T18:22:03Z</NextRotationDate>
<SecretData>testdata1</SecretData>
<RotationInterval>604800s</RotationInterval>
<ExtendedConfig>{\"SecretSubType\":\"SingleUser\", \"DBInstanceId\":\"rm-uf667446pc955****\", \"CustomData\":{} }</ExtendedConfig>
<LastRotationDate>2023-07-05T08:22:03Z</LastRotationDate>
<RequestId>6a3e9c36-1150-4881-84d3-eb8672fcafad</RequestId>
<SecretName>secret001</SecretName>
<AutomaticRotation>Enabled</AutomaticRotation>
<SecretType>Generic</SecretType>
<VersionStages>{ "VersionStage": [ "ACSCurrent" ] }</VersionStages>
</GetSecretValueResponse>
JSON格式
HTTP/1.1 200 OK
Content-Type:application/json
{
"SecretDataType" : "binary",
"CreateTime" : "2024-02-21T15:39:26Z",
"VersionId" : "v1",
"NextRotationDate" : "2024-07-06T18:22:03Z",
"SecretData" : "testdata1",
"RotationInterval" : "604800s",
"ExtendedConfig" : "{\\\"SecretSubType\\\":\\\"SingleUser\\\", \\\"DBInstanceId\\\":\\\"rm-uf667446pc955****\\\", \\\"CustomData\\\":{} }",
"LastRotationDate" : "2023-07-05T08:22:03Z",
"RequestId" : "6a3e9c36-1150-4881-84d3-eb8672fcafad",
"SecretName" : "secret001",
"AutomaticRotation" : "Enabled",
"SecretType" : "Generic",
"VersionStages" : [ "{ \"VersionStage\": [ \t\"ACSCurrent\" \t] }" ]
}
錯誤碼
|
HttpCode |
錯誤碼 |
錯誤資訊 |
描述 |
| 403 | Forbidden.DKMSInstanceStateInvalid | The DKMS instance state is invalid. | 您的專屬KMS狀態為無效狀態。 |
| 403 | Forbidden.DKMSInstanceNotFound | The specified DKMS Instance is not found. | 您指定的專屬kms執行個體未找到。 |
| 404 | Forbidden.KeyNotFound | The specified Key is not found. | 指定的密鑰不存在。 |
| 404 | Forbidden.ResourceNotFound | Resource not found. | 資源找不到 |
訪問錯誤中心查看更多錯誤碼。