GetLifecyclePolicy delphiDll Example
var
rest: HCkRest;
success: Boolean;
authAws: HCkAuthAws;
sbResponseBody: HCkStringBuilder;
respStatusCode: Integer;
jResp: HCkJsonObject;
Name: PWideChar;
j: Integer;
count_j: Integer;
CmkArn: PWideChar;
Encrypted: Integer;
Interval: Integer;
IntervalUnit: PWideChar;
Target: PWideChar;
strVal: PWideChar;
CopyTags: Integer;
CronExpression: PWideChar;
CreateRuleInterval: Integer;
CreateRuleIntervalUnit: PWideChar;
Location: PWideChar;
Count: Integer;
DeprecateRuleInterval: Integer;
DeprecateRuleIntervalUnit: PWideChar;
FastRestoreRuleCount: Integer;
FastRestoreRuleInterval: Integer;
FastRestoreRuleIntervalUnit: PWideChar;
RetainRuleCount: Integer;
RetainRuleInterval: Integer;
RetainRuleIntervalUnit: PWideChar;
TargetRegion: PWideChar;
UnshareInterval: Integer;
UnshareIntervalUnit: PWideChar;
k: Integer;
count_k: Integer;
Key: PWideChar;
Value: PWideChar;
DateCreated: Integer;
DateModified: Integer;
Description: PWideChar;
ExecutionRoleArn: PWideChar;
PolicyArn: PWideChar;
DescriptionRegex: PWideChar;
EventType: PWideChar;
v_Type: PWideChar;
ExcludeBootVolume: Integer;
NoReboot: Integer;
PolicyType: PWideChar;
PolicyId: PWideChar;
State: PWideChar;
StatusMessage: PWideChar;
v_String: PWideChar;
i: Integer;
count_i: Integer;
begin
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest := CkRest_Create();
authAws := CkAuthAws_Create();
CkAuthAws_putAccessKey(authAws,'AWS_ACCESS_KEY');
CkAuthAws_putSecretKey(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_putRegion(authAws,'us-west-2');
CkAuthAws_putServiceName(authAws,'dlm');
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws(rest,authAws);
// URL: https://dlm.us-west-2.amazonaws.com/
// Use the same region as specified above.
success := CkRest_Connect(rest,'dlm.us-west-2.amazonaws.com',443,True,True);
if (success <> True) then
begin
Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(CkRest_getConnectFailReason(rest)));
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
CkRest_AddHeader(rest,'Content-Type','application/x-amz-json-1.1');
CkRest_AddHeader(rest,'X-Amz-Target','GetLifecyclePolicy');
sbResponseBody := CkStringBuilder_Create();
success := CkRest_FullRequestNoBodySb(rest,'GET','/policies/{policyId}/',sbResponseBody);
if (success <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
respStatusCode := CkRest_getResponseStatusCode(rest);
Memo1.Lines.Add('response status code = ' + IntToStr(respStatusCode));
if (respStatusCode <> 200) then
begin
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(CkRest__responseHeader(rest));
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponseBody));
Exit;
end;
jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(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
DateCreated := CkJsonObject_IntOf(jResp,'Policy.DateCreated');
DateModified := CkJsonObject_IntOf(jResp,'Policy.DateModified');
Description := CkJsonObject__stringOf(jResp,'Policy.Description');
ExecutionRoleArn := CkJsonObject__stringOf(jResp,'Policy.ExecutionRoleArn');
PolicyArn := CkJsonObject__stringOf(jResp,'Policy.PolicyArn');
DescriptionRegex := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.EventSource.Parameters.DescriptionRegex');
EventType := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.EventSource.Parameters.EventType');
v_Type := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.EventSource.Type');
ExcludeBootVolume := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Parameters.ExcludeBootVolume');
NoReboot := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Parameters.NoReboot');
PolicyType := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.PolicyType');
PolicyId := CkJsonObject__stringOf(jResp,'Policy.PolicyId');
State := CkJsonObject__stringOf(jResp,'Policy.State');
StatusMessage := CkJsonObject__stringOf(jResp,'Policy.StatusMessage');
v_String := CkJsonObject__stringOf(jResp,'Policy.Tags.string');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'Policy.PolicyDetails.Actions');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
Name := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Actions[i].Name');
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'Policy.PolicyDetails.Actions[i].CrossRegionCopy');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
CmkArn := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.CmkArn');
Encrypted := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.Encrypted');
Interval := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.Interval');
IntervalUnit := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.IntervalUnit');
Target := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].Target');
j := j + 1;
end;
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
strVal := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner[i]');
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'Policy.PolicyDetails.ResourceLocations');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
strVal := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.ResourceLocations[i]');
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'Policy.PolicyDetails.ResourceTypes');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
strVal := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.ResourceTypes[i]');
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'Policy.PolicyDetails.Schedules');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
CopyTags := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Schedules[i].CopyTags');
CronExpression := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].CreateRule.CronExpression');
CreateRuleInterval := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Schedules[i].CreateRule.Interval');
CreateRuleIntervalUnit := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].CreateRule.IntervalUnit');
Location := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].CreateRule.Location');
Count := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Schedules[i].DeprecateRule.Count');
DeprecateRuleInterval := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Schedules[i].DeprecateRule.Interval');
DeprecateRuleIntervalUnit := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].DeprecateRule.IntervalUnit');
FastRestoreRuleCount := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Schedules[i].FastRestoreRule.Count');
FastRestoreRuleInterval := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Schedules[i].FastRestoreRule.Interval');
FastRestoreRuleIntervalUnit := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].FastRestoreRule.IntervalUnit');
Name := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].Name');
RetainRuleCount := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Schedules[i].RetainRule.Count');
RetainRuleInterval := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Schedules[i].RetainRule.Interval');
RetainRuleIntervalUnit := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].RetainRule.IntervalUnit');
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'Policy.PolicyDetails.Schedules[i].CreateRule.Times');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
strVal := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].CreateRule.Times[j]');
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
CmkArn := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CmkArn');
CopyTags := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CopyTags');
DeprecateRuleInterval := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.Interval');
DeprecateRuleIntervalUnit := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.IntervalUnit');
Encrypted := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Encrypted');
RetainRuleInterval := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.Interval');
RetainRuleIntervalUnit := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.IntervalUnit');
Target := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Target');
TargetRegion := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].TargetRegion');
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
strVal := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones[j]');
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'Policy.PolicyDetails.Schedules[i].ShareRules');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
UnshareInterval := CkJsonObject_IntOf(jResp,'Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareInterval');
UnshareIntervalUnit := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareIntervalUnit');
k := 0;
count_k := CkJsonObject_SizeOfArray(jResp,'Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts');
while k < count_k do
begin
CkJsonObject_putK(jResp,k);
strVal := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts[k]');
k := k + 1;
end;
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'Policy.PolicyDetails.Schedules[i].TagsToAdd');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
Key := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Key');
Value := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Value');
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'Policy.PolicyDetails.Schedules[i].VariableTags');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
Key := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].VariableTags[j].Key');
Value := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.Schedules[i].VariableTags[j].Value');
j := j + 1;
end;
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'Policy.PolicyDetails.TargetTags');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
Key := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.TargetTags[i].Key');
Value := CkJsonObject__stringOf(jResp,'Policy.PolicyDetails.TargetTags[i].Value');
i := i + 1;
end;
// 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_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);