GetLifecyclePolicy C Example
#include <C_CkRest.h>
#include <C_CkAuthAws.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
HCkRest rest;
BOOL success;
HCkAuthAws authAws;
HCkStringBuilder sbResponseBody;
int respStatusCode;
HCkJsonObject jResp;
const char *Name;
int j;
int count_j;
const char *CmkArn;
int Encrypted;
int Interval;
const char *IntervalUnit;
const char *Target;
const char *strVal;
int CopyTags;
const char *CronExpression;
int CreateRuleInterval;
const char *CreateRuleIntervalUnit;
const char *Location;
int Count;
int DeprecateRuleInterval;
const char *DeprecateRuleIntervalUnit;
int FastRestoreRuleCount;
int FastRestoreRuleInterval;
const char *FastRestoreRuleIntervalUnit;
int RetainRuleCount;
int RetainRuleInterval;
const char *RetainRuleIntervalUnit;
const char *TargetRegion;
int UnshareInterval;
const char *UnshareIntervalUnit;
int k;
int count_k;
const char *Key;
const char *Value;
int DateCreated;
int DateModified;
const char *Description;
const char *ExecutionRoleArn;
const char *PolicyArn;
const char *DescriptionRegex;
const char *EventType;
const char *v_Type;
int ExcludeBootVolume;
int NoReboot;
const char *PolicyType;
const char *PolicyId;
const char *State;
const char *StatusMessage;
const char *v_String;
int i;
int count_i;
// 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) {
printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
return;
}
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) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
respStatusCode = CkRest_getResponseStatusCode(rest);
printf("response status code = %d\n",respStatusCode);
if (respStatusCode != 200) {
printf("Response Header:\n");
printf("%s\n",CkRest_responseHeader(rest));
printf("Response Body:\n");
printf("%s\n",CkStringBuilder_getAsString(sbResponseBody));
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
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
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
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) {
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) {
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;
}
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"Policy.PolicyDetails.ResourceLocations");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"Policy.PolicyDetails.ResourceLocations[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"Policy.PolicyDetails.ResourceTypes");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"Policy.PolicyDetails.ResourceTypes[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"Policy.PolicyDetails.Schedules");
while (i < count_i) {
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) {
CkJsonObject_putJ(jResp,j);
strVal = CkJsonObject_stringOf(jResp,"Policy.PolicyDetails.Schedules[i].CreateRule.Times[j]");
j = j + 1;
}
j = 0;
count_j = CkJsonObject_SizeOfArray(jResp,"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules");
while (j < count_j) {
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;
}
j = 0;
count_j = CkJsonObject_SizeOfArray(jResp,"Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones");
while (j < count_j) {
CkJsonObject_putJ(jResp,j);
strVal = CkJsonObject_stringOf(jResp,"Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones[j]");
j = j + 1;
}
j = 0;
count_j = CkJsonObject_SizeOfArray(jResp,"Policy.PolicyDetails.Schedules[i].ShareRules");
while (j < count_j) {
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) {
CkJsonObject_putK(jResp,k);
strVal = CkJsonObject_stringOf(jResp,"Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts[k]");
k = k + 1;
}
j = j + 1;
}
j = 0;
count_j = CkJsonObject_SizeOfArray(jResp,"Policy.PolicyDetails.Schedules[i].TagsToAdd");
while (j < count_j) {
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;
}
j = 0;
count_j = CkJsonObject_SizeOfArray(jResp,"Policy.PolicyDetails.Schedules[i].VariableTags");
while (j < count_j) {
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;
}
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"Policy.PolicyDetails.TargetTags");
while (i < count_i) {
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;
}
// 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);
}