Chilkat Online Tools

GetLifecyclePolicy PowerBuilder Example

Amazon Data Lifecycle Manager

integer li_rc
oleobject loo_Rest
integer li_Success
oleobject loo_AuthAws
oleobject loo_SbResponseBody
integer li_RespStatusCode
oleobject loo_JResp
string ls_Name
integer j
integer li_Count_j
string ls_CmkArn
integer li_Encrypted
integer li_Interval
string ls_IntervalUnit
string ls_Target
string ls_StrVal
integer li_CopyTags
string ls_CronExpression
integer li_CreateRuleInterval
string ls_CreateRuleIntervalUnit
string ls_Location
integer li_Count
integer li_DeprecateRuleInterval
string ls_DeprecateRuleIntervalUnit
integer li_FastRestoreRuleCount
integer li_FastRestoreRuleInterval
string ls_FastRestoreRuleIntervalUnit
integer li_RetainRuleCount
integer li_RetainRuleInterval
string ls_RetainRuleIntervalUnit
string ls_TargetRegion
integer li_UnshareInterval
string ls_UnshareIntervalUnit
integer k
integer li_Count_k
string ls_Key
string ls_Value
integer li_DateCreated
integer li_DateModified
string ls_Description
string ls_ExecutionRoleArn
string ls_PolicyArn
string ls_DescriptionRegex
string ls_EventType
string ls_V_Type
integer li_ExcludeBootVolume
integer li_NoReboot
string ls_PolicyType
string ls_PolicyId
string ls_State
string ls_StatusMessage
string ls_V_String
integer i
integer li_Count_i

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

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_AuthAws = create oleobject
li_rc = loo_AuthAws.ConnectToNewObject("Chilkat_9_5_0.AuthAws")

loo_AuthAws.AccessKey = "AWS_ACCESS_KEY"
loo_AuthAws.SecretKey = "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.)
loo_AuthAws.Region = "us-west-2"
loo_AuthAws.ServiceName = "dlm"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
loo_Rest.SetAuthAws(loo_AuthAws)

// URL: https://dlm.us-west-2.amazonaws.com/
// Use the same region as specified above.
li_Success = loo_Rest.Connect("dlm.us-west-2.amazonaws.com",443,1,1)
if li_Success <> 1 then
    Write-Debug "ConnectFailReason: " + string(loo_Rest.ConnectFailReason)
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_AuthAws
    return
end if

loo_Rest.AddHeader("Content-Type","application/x-amz-json-1.1")
loo_Rest.AddHeader("X-Amz-Target","GetLifecyclePolicy")

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Rest.FullRequestNoBodySb("GET","/policies/{policyId}/",loo_SbResponseBody)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_AuthAws
    destroy loo_SbResponseBody
    return
end if

li_RespStatusCode = loo_Rest.ResponseStatusCode
Write-Debug "response status code = " + string(li_RespStatusCode)
if li_RespStatusCode <> 200 then
    Write-Debug "Response Header:"
    Write-Debug loo_Rest.ResponseHeader
    Write-Debug "Response Body:"
    Write-Debug loo_SbResponseBody.GetAsString()
    destroy loo_Rest
    destroy loo_AuthAws
    destroy loo_SbResponseBody
    return
end if

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)

// 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

li_DateCreated = loo_JResp.IntOf("Policy.DateCreated")
li_DateModified = loo_JResp.IntOf("Policy.DateModified")
ls_Description = loo_JResp.StringOf("Policy.Description")
ls_ExecutionRoleArn = loo_JResp.StringOf("Policy.ExecutionRoleArn")
ls_PolicyArn = loo_JResp.StringOf("Policy.PolicyArn")
ls_DescriptionRegex = loo_JResp.StringOf("Policy.PolicyDetails.EventSource.Parameters.DescriptionRegex")
ls_EventType = loo_JResp.StringOf("Policy.PolicyDetails.EventSource.Parameters.EventType")
ls_V_Type = loo_JResp.StringOf("Policy.PolicyDetails.EventSource.Type")
li_ExcludeBootVolume = loo_JResp.IntOf("Policy.PolicyDetails.Parameters.ExcludeBootVolume")
li_NoReboot = loo_JResp.IntOf("Policy.PolicyDetails.Parameters.NoReboot")
ls_PolicyType = loo_JResp.StringOf("Policy.PolicyDetails.PolicyType")
ls_PolicyId = loo_JResp.StringOf("Policy.PolicyId")
ls_State = loo_JResp.StringOf("Policy.State")
ls_StatusMessage = loo_JResp.StringOf("Policy.StatusMessage")
ls_V_String = loo_JResp.StringOf("Policy.Tags.string")
i = 0
li_Count_i = loo_JResp.SizeOfArray("Policy.PolicyDetails.Actions")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Name = loo_JResp.StringOf("Policy.PolicyDetails.Actions[i].Name")
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("Policy.PolicyDetails.Actions[i].CrossRegionCopy")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_CmkArn = loo_JResp.StringOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.CmkArn")
        li_Encrypted = loo_JResp.IntOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.Encrypted")
        li_Interval = loo_JResp.IntOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.Interval")
        ls_IntervalUnit = loo_JResp.StringOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.IntervalUnit")
        ls_Target = loo_JResp.StringOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].Target")
        j = j + 1
    loop
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner")
do while i < li_Count_i
    loo_JResp.I = i
    ls_StrVal = loo_JResp.StringOf("Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner[i]")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("Policy.PolicyDetails.ResourceLocations")
do while i < li_Count_i
    loo_JResp.I = i
    ls_StrVal = loo_JResp.StringOf("Policy.PolicyDetails.ResourceLocations[i]")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("Policy.PolicyDetails.ResourceTypes")
do while i < li_Count_i
    loo_JResp.I = i
    ls_StrVal = loo_JResp.StringOf("Policy.PolicyDetails.ResourceTypes[i]")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("Policy.PolicyDetails.Schedules")
do while i < li_Count_i
    loo_JResp.I = i
    li_CopyTags = loo_JResp.IntOf("Policy.PolicyDetails.Schedules[i].CopyTags")
    ls_CronExpression = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].CreateRule.CronExpression")
    li_CreateRuleInterval = loo_JResp.IntOf("Policy.PolicyDetails.Schedules[i].CreateRule.Interval")
    ls_CreateRuleIntervalUnit = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].CreateRule.IntervalUnit")
    ls_Location = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].CreateRule.Location")
    li_Count = loo_JResp.IntOf("Policy.PolicyDetails.Schedules[i].DeprecateRule.Count")
    li_DeprecateRuleInterval = loo_JResp.IntOf("Policy.PolicyDetails.Schedules[i].DeprecateRule.Interval")
    ls_DeprecateRuleIntervalUnit = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].DeprecateRule.IntervalUnit")
    li_FastRestoreRuleCount = loo_JResp.IntOf("Policy.PolicyDetails.Schedules[i].FastRestoreRule.Count")
    li_FastRestoreRuleInterval = loo_JResp.IntOf("Policy.PolicyDetails.Schedules[i].FastRestoreRule.Interval")
    ls_FastRestoreRuleIntervalUnit = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].FastRestoreRule.IntervalUnit")
    ls_Name = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].Name")
    li_RetainRuleCount = loo_JResp.IntOf("Policy.PolicyDetails.Schedules[i].RetainRule.Count")
    li_RetainRuleInterval = loo_JResp.IntOf("Policy.PolicyDetails.Schedules[i].RetainRule.Interval")
    ls_RetainRuleIntervalUnit = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].RetainRule.IntervalUnit")
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].CreateRule.Times")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].CreateRule.Times[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_CmkArn = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CmkArn")
        li_CopyTags = loo_JResp.IntOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CopyTags")
        li_DeprecateRuleInterval = loo_JResp.IntOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.Interval")
        ls_DeprecateRuleIntervalUnit = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.IntervalUnit")
        li_Encrypted = loo_JResp.IntOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Encrypted")
        li_RetainRuleInterval = loo_JResp.IntOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.Interval")
        ls_RetainRuleIntervalUnit = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.IntervalUnit")
        ls_Target = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Target")
        ls_TargetRegion = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].TargetRegion")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].ShareRules")
    do while j < li_Count_j
        loo_JResp.J = j
        li_UnshareInterval = loo_JResp.IntOf("Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareInterval")
        ls_UnshareIntervalUnit = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareIntervalUnit")
        k = 0
        li_Count_k = loo_JResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts")
        do while k < li_Count_k
            loo_JResp.K = k
            ls_StrVal = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts[k]")
            k = k + 1
        loop
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].TagsToAdd")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_Key = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Key")
        ls_Value = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Value")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].VariableTags")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_Key = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].VariableTags[j].Key")
        ls_Value = loo_JResp.StringOf("Policy.PolicyDetails.Schedules[i].VariableTags[j].Value")
        j = j + 1
    loop
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("Policy.PolicyDetails.TargetTags")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Key = loo_JResp.StringOf("Policy.PolicyDetails.TargetTags[i].Key")
    ls_Value = loo_JResp.StringOf("Policy.PolicyDetails.TargetTags[i].Value")
    i = i + 1
loop

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

// {
//   "Policy": {
//     "DateCreated": number,
//     "DateModified": number,
//     "Description": "string",
//     "ExecutionRoleArn": "string",
//     "PolicyArn": "string",
//     "PolicyDetails": {
//       "Actions": [
//         {
//           "CrossRegionCopy": [
//             {
//               "EncryptionConfiguration": {
//                 "CmkArn": "string",
//                 "Encrypted": boolean
//               },
//               "RetainRule": {
//                 "Interval": number,
//                 "IntervalUnit": "string"
//               },
//               "Target": "string"
//             }
//           ],
//           "Name": "string"
//         }
//       ],
//       "EventSource": {
//         "Parameters": {
//           "DescriptionRegex": "string",
//           "EventType": "string",
//           "SnapshotOwner": [
//             "string"
//           ]
//         },
//         "Type": "string"
//       },
//       "Parameters": {
//         "ExcludeBootVolume": boolean,
//         "NoReboot": boolean
//       },
//       "PolicyType": "string",
//       "ResourceLocations": [
//         "string"
//       ],
//       "ResourceTypes": [
//         "string"
//       ],
//       "Schedules": [
//         {
//           "CopyTags": boolean,
//           "CreateRule": {
//             "CronExpression": "string",
//             "Interval": number,
//             "IntervalUnit": "string",
//             "Location": "string",
//             "Times": [
//               "string"
//             ]
//           },
//           "CrossRegionCopyRules": [
//             {
//               "CmkArn": "string",
//               "CopyTags": boolean,
//               "DeprecateRule": {
//                 "Interval": number,
//                 "IntervalUnit": "string"
//               },
//               "Encrypted": boolean,
//               "RetainRule": {
//                 "Interval": number,
//                 "IntervalUnit": "string"
//               },
//               "Target": "string",
//               "TargetRegion": "string"
//             }
//           ],
//           "DeprecateRule": {
//             "Count": number,
//             "Interval": number,
//             "IntervalUnit": "string"
//           },
//           "FastRestoreRule": {
//             "AvailabilityZones": [
//               "string"
//             ],
//             "Count": number,
//             "Interval": number,
//             "IntervalUnit": "string"
//           },
//           "Name": "string",
//           "RetainRule": {
//             "Count": number,
//             "Interval": number,
//             "IntervalUnit": "string"
//           },
//           "ShareRules": [
//             {
//               "TargetAccounts": [
//                 "string"
//               ],
//               "UnshareInterval": number,
//               "UnshareIntervalUnit": "string"
//             }
//           ],
//           "TagsToAdd": [
//             {
//               "Key": "string",
//               "Value": "string"
//             }
//           ],
//           "VariableTags": [
//             {
//               "Key": "string",
//               "Value": "string"
//             }
//           ]
//         }
//       ],
//       "TargetTags": [
//         {
//           "Key": "string",
//           "Value": "string"
//         }
//       ]
//     },
//     "PolicyId": "string",
//     "State": "string",
//     "StatusMessage": "string",
//     "Tags": {
//       "string": "string"
//     }
//   }
// }


destroy loo_Rest
destroy loo_AuthAws
destroy loo_SbResponseBody
destroy loo_JResp