Chilkat Online Tools

ReplicateKey DataFlex Example

AWS Key Management Service

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Variant vAuthAws
    Handle hoAuthAws
    Handle hoJson
    Variant vSbRequestBody
    Handle hoSbRequestBody
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Integer iRespStatusCode
    Handle hoJResp
    String sStrVal
    String sTagKey
    String sTagValue
    String sArn
    String sAWSAccountId
    String sCloudHsmClusterId
    Integer iCreationDate
    String sCustomerMasterKeySpec
    String sCustomKeyStoreId
    Integer iDeletionDate
    String sDescription
    Integer iEnabled
    String sExpirationModel
    String sKeyId
    String sKeyManager
    String sKeySpec
    String sKeyState
    String sKeyUsage
    Integer iMultiRegion
    String sMultiRegionKeyType
    String sPrimaryKeyArn
    String sRegion
    String sOrigin
    Integer iPendingDeletionWindowInDays
    Integer iValidTo
    String sReplicaPolicy
    Integer i
    Integer iCount_i
    String sTemp1
    Integer iTemp1

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

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    Get Create (RefClass(cComChilkatAuthAws)) To hoAuthAws
    If (Not(IsComObjectCreated(hoAuthAws))) Begin
        Send CreateComObject of hoAuthAws
    End
    Set ComAccessKey Of hoAuthAws To "AWS_ACCESS_KEY"
    Set ComSecretKey Of hoAuthAws To "AWS_SECRET_KEY"

    // Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
    Set ComRegion Of hoAuthAws To "us-west-2"
    Set ComServiceName Of hoAuthAws To "kms"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    Get pvComObject of hoAuthAws to vAuthAws
    Get ComSetAuthAws Of hoRest vAuthAws To iSuccess

    // URL: https://kms.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    Get ComConnect Of hoRest "kms.us-west-2.amazonaws.com" 443 True True To iSuccess
    If (iSuccess <> True) Begin
        Get ComConnectFailReason Of hoRest To iTemp1
        Showln "ConnectFailReason: " iTemp1
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // The following code creates the JSON request body.
    // The JSON created by this code is shown below.

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateInt Of hoJson "BypassPolicyLockoutSafetyCheck" 123 To iSuccess
    Get ComUpdateString Of hoJson "Description" "string" To iSuccess
    Get ComUpdateString Of hoJson "KeyId" "string" To iSuccess
    Get ComUpdateString Of hoJson "Policy" "string" To iSuccess
    Get ComUpdateString Of hoJson "ReplicaRegion" "string" To iSuccess
    Get ComUpdateString Of hoJson "Tags[0].TagKey" "string" To iSuccess
    Get ComUpdateString Of hoJson "Tags[0].TagValue" "string" To iSuccess

    // The JSON request body created by the above code:

    // {
    //   "BypassPolicyLockoutSafetyCheck": boolean,
    //   "Description": "string",
    //   "KeyId": "string",
    //   "Policy": "string",
    //   "ReplicaRegion": "string",
    //   "Tags": [
    //     {
    //       "TagKey": "string",
    //       "TagValue": "string"
    //     }
    //   ]
    // }

    Get ComAddHeader Of hoRest "Content-Type" "application/x-amz-json-1.1" To iSuccess
    Get ComAddHeader Of hoRest "X-Amz-Target" "TrentService.ReplicateKey" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
    If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
        Send CreateComObject of hoSbRequestBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComEmitSb Of hoJson vSbRequestBody To iSuccess
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComFullRequestSb Of hoRest "POST" "/" vSbRequestBody vSbResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComResponseStatusCode Of hoRest To iRespStatusCode
    Showln "response status code = " iRespStatusCode
    If (iRespStatusCode <> 200) Begin
        Showln "Response Header:"
        Get ComResponseHeader Of hoRest To sTemp1
        Showln sTemp1
        Showln "Response Body:"
        Get ComGetAsString Of hoSbResponseBody To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    // Use this online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.Arn" To sArn
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.AWSAccountId" To sAWSAccountId
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.CloudHsmClusterId" To sCloudHsmClusterId
    Get ComIntOf Of hoJResp "ReplicaKeyMetadata.CreationDate" To iCreationDate
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.CustomerMasterKeySpec" To sCustomerMasterKeySpec
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.CustomKeyStoreId" To sCustomKeyStoreId
    Get ComIntOf Of hoJResp "ReplicaKeyMetadata.DeletionDate" To iDeletionDate
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.Description" To sDescription
    Get ComIntOf Of hoJResp "ReplicaKeyMetadata.Enabled" To iEnabled
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.ExpirationModel" To sExpirationModel
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.KeyId" To sKeyId
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.KeyManager" To sKeyManager
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.KeySpec" To sKeySpec
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.KeyState" To sKeyState
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.KeyUsage" To sKeyUsage
    Get ComIntOf Of hoJResp "ReplicaKeyMetadata.MultiRegion" To iMultiRegion
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.MultiRegionConfiguration.MultiRegionKeyType" To sMultiRegionKeyType
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.MultiRegionConfiguration.PrimaryKey.Arn" To sPrimaryKeyArn
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.MultiRegionConfiguration.PrimaryKey.Region" To sRegion
    Get ComStringOf Of hoJResp "ReplicaKeyMetadata.Origin" To sOrigin
    Get ComIntOf Of hoJResp "ReplicaKeyMetadata.PendingDeletionWindowInDays" To iPendingDeletionWindowInDays
    Get ComIntOf Of hoJResp "ReplicaKeyMetadata.ValidTo" To iValidTo
    Get ComStringOf Of hoJResp "ReplicaPolicy" To sReplicaPolicy
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "ReplicaKeyMetadata.EncryptionAlgorithms" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "ReplicaKeyMetadata.EncryptionAlgorithms[i]" To sStrVal
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "ReplicaKeyMetadata.MacAlgorithms" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "ReplicaKeyMetadata.MacAlgorithms[i]" To sStrVal
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "ReplicaKeyMetadata.MultiRegionConfiguration.ReplicaKeys" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "ReplicaKeyMetadata.MultiRegionConfiguration.ReplicaKeys[i].Arn" To sArn
        Get ComStringOf Of hoJResp "ReplicaKeyMetadata.MultiRegionConfiguration.ReplicaKeys[i].Region" To sRegion
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "ReplicaKeyMetadata.SigningAlgorithms" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "ReplicaKeyMetadata.SigningAlgorithms[i]" To sStrVal
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "ReplicaTags" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "ReplicaTags[i].TagKey" To sTagKey
        Get ComStringOf Of hoJResp "ReplicaTags[i].TagValue" To sTagValue
        Move (i + 1) To i
    Loop

    // A sample JSON response body parsed by the above code:

    // {
    //   "ReplicaKeyMetadata": {
    //     "Arn": "string",
    //     "AWSAccountId": "string",
    //     "CloudHsmClusterId": "string",
    //     "CreationDate": number,
    //     "CustomerMasterKeySpec": "string",
    //     "CustomKeyStoreId": "string",
    //     "DeletionDate": number,
    //     "Description": "string",
    //     "Enabled": boolean,
    //     "EncryptionAlgorithms": [
    //       "string"
    //     ],
    //     "ExpirationModel": "string",
    //     "KeyId": "string",
    //     "KeyManager": "string",
    //     "KeySpec": "string",
    //     "KeyState": "string",
    //     "KeyUsage": "string",
    //     "MacAlgorithms": [
    //       "string"
    //     ],
    //     "MultiRegion": boolean,
    //     "MultiRegionConfiguration": {
    //       "MultiRegionKeyType": "string",
    //       "PrimaryKey": {
    //         "Arn": "string",
    //         "Region": "string"
    //       },
    //       "ReplicaKeys": [
    //         {
    //           "Arn": "string",
    //           "Region": "string"
    //         }
    //       ]
    //     },
    //     "Origin": "string",
    //     "PendingDeletionWindowInDays": number,
    //     "SigningAlgorithms": [
    //       "string"
    //     ],
    //     "ValidTo": number
    //   },
    //   "ReplicaPolicy": "string",
    //   "ReplicaTags": [
    //     {
    //       "TagKey": "string",
    //       "TagValue": "string"
    //     }
    //   ]
    // }


End_Procedure