Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.1.0+

AWS Secrets Manager - List Secrets

See more AWS Secrets Manager Examples

Lists the secrets that are stored by Secrets Manager in the AWS account. Lists the secrets that are stored by Secrets Manager in the AWS account.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nPort
LOCAL nBAutoReconnect
LOCAL oAuthAws
LOCAL cStrResponse
LOCAL nRespStatusCode
LOCAL oJResp
LOCAL cARN
LOCAL cDescription
LOCAL cLastChangedDate
LOCAL cName
LOCAL cStrVal
LOCAL oJson2
LOCAL oJarr
LOCAL i
LOCAL nCount_i
LOCAL nCount
LOCAL j
LOCAL cVersionName
LOCAL cStage

nSuccess := 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

//  Sends the following sample request.
//  Note: Chilkat will automatically add Content-Length, X-Amz-Date, Accept-Encoding, and Authorization

//  POST / HTTP/1.1
//  Host: secretsmanager.region.domain
//  Accept-Encoding: identity
//  X-Amz-Target: secretsmanager.ListSecrets
//  Content-Type: application/x-amz-json-1.1
//  X-Amz-Date: <date>
//  Authorization: AWS4-HMAC-SHA256 Credential=<credentials>,SignedHeaders=<headers>, Signature=<signature>
//  Content-Length: <payload-size-bytes>
//  
//  {}

oRest := CreateObject("Chilkat.Rest")

//  Connect to the Amazon AWS REST server.
//  such as https://secretsmanager.us-west-2.amazonaws.com/
nBTls := 1
nPort := 443
nBAutoReconnect := 1
nSuccess := oRest:Connect("secretsmanager.us-west-2.amazonaws.com", nPort, nBTls, nBAutoReconnect)

//  Provide AWS credentials for the REST call.
oAuthAws := CreateObject("Chilkat.AuthAws")
oAuthAws:AccessKey := "AWS_ACCESS_KEY"
oAuthAws:SecretKey := "AWS_SECRET_KEY"
//  the region should match our URL above..
oAuthAws:Region := "us-west-2"
oAuthAws:ServiceName := "secretsmanager"

oRest:SetAuthAws(oAuthAws)

oRest:AddHeader("Content-Type", "application/x-amz-json-1.1")
oRest:AddHeader("X-Amz-Target", "secretsmanager.ListSecrets")

cStrResponse := oRest:FullRequestString("POST", "/", "{}")
IF (oRest:LastMethodSuccess == 0)
    ? oRest:LastErrorText
    oRest:destroy()
    oAuthAws:destroy()
    RETURN
ENDIF

nRespStatusCode := oRest:ResponseStatusCode
? "response status code = " + Str(nRespStatusCode)

oJResp := CreateObject("Chilkat.JsonObject")
oJResp:EmitCompact := 0
oJResp:Load(cStrResponse)

IF (nRespStatusCode >= 400)
    ? "Response Status Code = " + Str(nRespStatusCode)
    ? "Response Header:"
    ? oRest:ResponseHeader
    ? "Response Body:"
    ? oJResp:Emit()
    oRest:destroy()
    oAuthAws:destroy()
    oJResp:destroy()
    RETURN
ENDIF

? "Response Body:"
? oJResp:Emit()

//  Sample response body:

//  {
//    "SecretList":[
//      {
//        "ARN":"arn:aws:secretsmanager:us-west-2:123456789012:secret:MyTestDatabaseSecret-a1b2c3",
//        "Description":"My test database secret",
//        "LastChangedDate":1.523477145729E9,
//        "Name":"MyTestDatabaseSecret",
//        "SecretVersionsToStages":{
//          "EXAMPLE2-90ab-cdef-fedc-ba987EXAMPLE":["AWSCURRENT"]
//        }
//      },
//      {
//        "ARN":"arn:aws:secretsmanager:us-west-2:123456789012:secret:AnotherDatabaseSecret-d4e5f6",
//        "Description":"Another secret created for a different database",
//        "LastChangedDate":1.523482025685E9,
//        "Name":"AnotherDatabaseSecret",
//        "SecretVersionsToStages":{
//          "EXAMPLE3-90ab-cdef-fedc-ba987EXAMPLE":["AWSCURRENT"]
//        }
//      }
//    ]
//  }

oJson2 := CreateObject("Chilkat.JsonObject")
oJarr := CreateObject("Chilkat.JsonArray")

i := 0
nCount_i := oJResp:SizeOfArray("SecretList")
DO WHILE i < nCount_i
    oJResp:I := i
    cARN := oJResp:StringOf("SecretList[i].ARN")
    cDescription := oJResp:StringOf("SecretList[i].Description")
    cLastChangedDate := oJResp:StringOf("SecretList[i].LastChangedDate")
    cName := oJResp:StringOf("SecretList[i].Name")

    oJResp:ObjectOf2("SecretList[i].SecretVersionsToStages", oJson2)
    nCount := oJson2:Size
    j := 0
    DO WHILE j < nCount
        cVersionName := oJson2:NameAt(j)
        oJson2:ArrayOf2(cVersionName, oJarr)
        cStage := oJarr:StringAt(0)
        ? "versionName = " + cVersionName
        ? "stage = " + cStage
        j := j + 1
    ENDDO

    i := i + 1
ENDDO

oRest:destroy()
oAuthAws:destroy()
oJResp:destroy()
oJson2:destroy()
oJarr:destroy()