GetLifecyclePolicy PureBasic Example
IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"
IncludeFile "CkAuthAws.pb"
Procedure ChilkatExample()
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
rest.i = CkRest::ckCreate()
If rest.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i
authAws.i = CkAuthAws::ckCreate()
If authAws.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkAuthAws::setCkAccessKey(authAws, "AWS_ACCESS_KEY")
CkAuthAws::setCkSecretKey(authAws, "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.)
CkAuthAws::setCkRegion(authAws, "us-west-2")
CkAuthAws::setCkServiceName(authAws, "dlm")
; SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest::ckSetAuthAws(rest,authAws)
; URL: https://dlm.us-west-2.amazonaws.com/
; Use the same region as specified above.
success = CkRest::ckConnect(rest,"dlm.us-west-2.amazonaws.com",443,1,1)
If success <> 1
Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
ProcedureReturn
EndIf
CkRest::ckAddHeader(rest,"Content-Type","application/x-amz-json-1.1")
CkRest::ckAddHeader(rest,"X-Amz-Target","GetLifecyclePolicy")
sbResponseBody.i = CkStringBuilder::ckCreate()
If sbResponseBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkRest::ckFullRequestNoBodySb(rest,"GET","/policies/{policyId}/",sbResponseBody)
If success <> 1
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
respStatusCode.i = CkRest::ckResponseStatusCode(rest)
Debug "response status code = " + Str(respStatusCode)
If respStatusCode <> 200
Debug "Response Header:"
Debug CkRest::ckResponseHeader(rest)
Debug "Response Body:"
Debug CkStringBuilder::ckGetAsString(sbResponseBody)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
jResp.i = CkJsonObject::ckCreate()
If jResp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoadSb(jResp,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
Name.s
j.i
count_j.i
CmkArn.s
Encrypted.i
Interval.i
IntervalUnit.s
Target.s
strVal.s
CopyTags.i
CronExpression.s
CreateRuleInterval.i
CreateRuleIntervalUnit.s
Location.s
Count.i
DeprecateRuleInterval.i
DeprecateRuleIntervalUnit.s
FastRestoreRuleCount.i
FastRestoreRuleInterval.i
FastRestoreRuleIntervalUnit.s
RetainRuleCount.i
RetainRuleInterval.i
RetainRuleIntervalUnit.s
TargetRegion.s
UnshareInterval.i
UnshareIntervalUnit.s
k.i
count_k.i
Key.s
Value.s
DateCreated.i = CkJsonObject::ckIntOf(jResp,"Policy.DateCreated")
DateModified.i = CkJsonObject::ckIntOf(jResp,"Policy.DateModified")
Description.s = CkJsonObject::ckStringOf(jResp,"Policy.Description")
ExecutionRoleArn.s = CkJsonObject::ckStringOf(jResp,"Policy.ExecutionRoleArn")
PolicyArn.s = CkJsonObject::ckStringOf(jResp,"Policy.PolicyArn")
DescriptionRegex.s = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.EventSource.Parameters.DescriptionRegex")
EventType.s = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.EventSource.Parameters.EventType")
v_Type.s = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.EventSource.Type")
ExcludeBootVolume.i = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Parameters.ExcludeBootVolume")
NoReboot.i = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Parameters.NoReboot")
PolicyType.s = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.PolicyType")
PolicyId.s = CkJsonObject::ckStringOf(jResp,"Policy.PolicyId")
State.s = CkJsonObject::ckStringOf(jResp,"Policy.State")
StatusMessage.s = CkJsonObject::ckStringOf(jResp,"Policy.StatusMessage")
v_String.s = CkJsonObject::ckStringOf(jResp,"Policy.Tags.string")
i.i = 0
count_i.i = CkJsonObject::ckSizeOfArray(jResp,"Policy.PolicyDetails.Actions")
While i < count_i
CkJsonObject::setCkI(jResp, i)
Name = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Actions[i].Name")
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"Policy.PolicyDetails.Actions[i].CrossRegionCopy")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
CmkArn = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.CmkArn")
Encrypted = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.Encrypted")
Interval = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.Interval")
IntervalUnit = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.IntervalUnit")
Target = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].Target")
j = j + 1
Wend
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner")
While i < count_i
CkJsonObject::setCkI(jResp, i)
strVal = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner[i]")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"Policy.PolicyDetails.ResourceLocations")
While i < count_i
CkJsonObject::setCkI(jResp, i)
strVal = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.ResourceLocations[i]")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"Policy.PolicyDetails.ResourceTypes")
While i < count_i
CkJsonObject::setCkI(jResp, i)
strVal = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.ResourceTypes[i]")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"Policy.PolicyDetails.Schedules")
While i < count_i
CkJsonObject::setCkI(jResp, i)
CopyTags = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Schedules[i].CopyTags")
CronExpression = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].CreateRule.CronExpression")
CreateRuleInterval = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Schedules[i].CreateRule.Interval")
CreateRuleIntervalUnit = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].CreateRule.IntervalUnit")
Location = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].CreateRule.Location")
Count = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Schedules[i].DeprecateRule.Count")
DeprecateRuleInterval = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Schedules[i].DeprecateRule.Interval")
DeprecateRuleIntervalUnit = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].DeprecateRule.IntervalUnit")
FastRestoreRuleCount = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Schedules[i].FastRestoreRule.Count")
FastRestoreRuleInterval = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Schedules[i].FastRestoreRule.Interval")
FastRestoreRuleIntervalUnit = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].FastRestoreRule.IntervalUnit")
Name = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].Name")
RetainRuleCount = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Schedules[i].RetainRule.Count")
RetainRuleInterval = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Schedules[i].RetainRule.Interval")
RetainRuleIntervalUnit = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].RetainRule.IntervalUnit")
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"Policy.PolicyDetails.Schedules[i].CreateRule.Times")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
strVal = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].CreateRule.Times[j]")
j = j + 1
Wend
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
CmkArn = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CmkArn")
CopyTags = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CopyTags")
DeprecateRuleInterval = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.Interval")
DeprecateRuleIntervalUnit = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.IntervalUnit")
Encrypted = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Encrypted")
RetainRuleInterval = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.Interval")
RetainRuleIntervalUnit = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.IntervalUnit")
Target = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Target")
TargetRegion = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].TargetRegion")
j = j + 1
Wend
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
strVal = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones[j]")
j = j + 1
Wend
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"Policy.PolicyDetails.Schedules[i].ShareRules")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
UnshareInterval = CkJsonObject::ckIntOf(jResp,"Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareInterval")
UnshareIntervalUnit = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareIntervalUnit")
k = 0
count_k = CkJsonObject::ckSizeOfArray(jResp,"Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts")
While k < count_k
CkJsonObject::setCkK(jResp, k)
strVal = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts[k]")
k = k + 1
Wend
j = j + 1
Wend
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"Policy.PolicyDetails.Schedules[i].TagsToAdd")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
Key = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Key")
Value = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Value")
j = j + 1
Wend
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"Policy.PolicyDetails.Schedules[i].VariableTags")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
Key = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].VariableTags[j].Key")
Value = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.Schedules[i].VariableTags[j].Value")
j = j + 1
Wend
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"Policy.PolicyDetails.TargetTags")
While i < count_i
CkJsonObject::setCkI(jResp, i)
Key = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.TargetTags[i].Key")
Value = CkJsonObject::ckStringOf(jResp,"Policy.PolicyDetails.TargetTags[i].Value")
i = i + 1
Wend
; 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"
; }
; }
; }
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndProcedure