Chilkat Online Tools

GetLifecyclePolicy unicodeC Example

Amazon Data Lifecycle Manager

#include <C_CkRestW.h>
#include <C_CkAuthAwsW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    HCkAuthAwsW authAws;
    HCkStringBuilderW sbResponseBody;
    int respStatusCode;
    HCkJsonObjectW jResp;
    const wchar_t *Name;
    int j;
    int count_j;
    const wchar_t *CmkArn;
    int Encrypted;
    int Interval;
    const wchar_t *IntervalUnit;
    const wchar_t *Target;
    const wchar_t *strVal;
    int CopyTags;
    const wchar_t *CronExpression;
    int CreateRuleInterval;
    const wchar_t *CreateRuleIntervalUnit;
    const wchar_t *Location;
    int Count;
    int DeprecateRuleInterval;
    const wchar_t *DeprecateRuleIntervalUnit;
    int FastRestoreRuleCount;
    int FastRestoreRuleInterval;
    const wchar_t *FastRestoreRuleIntervalUnit;
    int RetainRuleCount;
    int RetainRuleInterval;
    const wchar_t *RetainRuleIntervalUnit;
    const wchar_t *TargetRegion;
    int UnshareInterval;
    const wchar_t *UnshareIntervalUnit;
    int k;
    int count_k;
    const wchar_t *Key;
    const wchar_t *Value;
    int DateCreated;
    int DateModified;
    const wchar_t *Description;
    const wchar_t *ExecutionRoleArn;
    const wchar_t *PolicyArn;
    const wchar_t *DescriptionRegex;
    const wchar_t *EventType;
    const wchar_t *v_Type;
    int ExcludeBootVolume;
    int NoReboot;
    const wchar_t *PolicyType;
    const wchar_t *PolicyId;
    const wchar_t *State;
    const wchar_t *StatusMessage;
    const wchar_t *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 = CkRestW_Create();

    authAws = CkAuthAwsW_Create();
    CkAuthAwsW_putAccessKey(authAws,L"AWS_ACCESS_KEY");
    CkAuthAwsW_putSecretKey(authAws,L"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.)
    CkAuthAwsW_putRegion(authAws,L"us-west-2");
    CkAuthAwsW_putServiceName(authAws,L"dlm");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    CkRestW_SetAuthAws(rest,authAws);

    // URL: https://dlm.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = CkRestW_Connect(rest,L"dlm.us-west-2.amazonaws.com",443,TRUE,TRUE);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkAuthAwsW_Dispose(authAws);
        return;
    }

    CkRestW_AddHeader(rest,L"Content-Type",L"application/x-amz-json-1.1");
    CkRestW_AddHeader(rest,L"X-Amz-Target",L"GetLifecyclePolicy");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/policies/{policyId}/",sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkAuthAwsW_Dispose(authAws);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    respStatusCode = CkRestW_getResponseStatusCode(rest);
    wprintf(L"response status code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkRestW_responseHeader(rest));
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
        CkRestW_Dispose(rest);
        CkAuthAwsW_Dispose(authAws);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_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 = CkJsonObjectW_IntOf(jResp,L"Policy.DateCreated");
    DateModified = CkJsonObjectW_IntOf(jResp,L"Policy.DateModified");
    Description = CkJsonObjectW_stringOf(jResp,L"Policy.Description");
    ExecutionRoleArn = CkJsonObjectW_stringOf(jResp,L"Policy.ExecutionRoleArn");
    PolicyArn = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyArn");
    DescriptionRegex = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.EventSource.Parameters.DescriptionRegex");
    EventType = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.EventSource.Parameters.EventType");
    v_Type = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.EventSource.Type");
    ExcludeBootVolume = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Parameters.ExcludeBootVolume");
    NoReboot = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Parameters.NoReboot");
    PolicyType = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.PolicyType");
    PolicyId = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyId");
    State = CkJsonObjectW_stringOf(jResp,L"Policy.State");
    StatusMessage = CkJsonObjectW_stringOf(jResp,L"Policy.StatusMessage");
    v_String = CkJsonObjectW_stringOf(jResp,L"Policy.Tags.string");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"Policy.PolicyDetails.Actions");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        Name = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Actions[i].Name");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"Policy.PolicyDetails.Actions[i].CrossRegionCopy");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            CmkArn = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.CmkArn");
            Encrypted = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.Encrypted");
            Interval = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.Interval");
            IntervalUnit = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.IntervalUnit");
            Target = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].Target");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        strVal = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner[i]");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"Policy.PolicyDetails.ResourceLocations");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        strVal = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.ResourceLocations[i]");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"Policy.PolicyDetails.ResourceTypes");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        strVal = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.ResourceTypes[i]");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"Policy.PolicyDetails.Schedules");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        CopyTags = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Schedules[i].CopyTags");
        CronExpression = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].CreateRule.CronExpression");
        CreateRuleInterval = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Schedules[i].CreateRule.Interval");
        CreateRuleIntervalUnit = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].CreateRule.IntervalUnit");
        Location = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].CreateRule.Location");
        Count = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Schedules[i].DeprecateRule.Count");
        DeprecateRuleInterval = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Schedules[i].DeprecateRule.Interval");
        DeprecateRuleIntervalUnit = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].DeprecateRule.IntervalUnit");
        FastRestoreRuleCount = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Schedules[i].FastRestoreRule.Count");
        FastRestoreRuleInterval = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Schedules[i].FastRestoreRule.Interval");
        FastRestoreRuleIntervalUnit = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].FastRestoreRule.IntervalUnit");
        Name = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].Name");
        RetainRuleCount = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Schedules[i].RetainRule.Count");
        RetainRuleInterval = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Schedules[i].RetainRule.Interval");
        RetainRuleIntervalUnit = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].RetainRule.IntervalUnit");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"Policy.PolicyDetails.Schedules[i].CreateRule.Times");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].CreateRule.Times[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            CmkArn = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CmkArn");
            CopyTags = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CopyTags");
            DeprecateRuleInterval = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.Interval");
            DeprecateRuleIntervalUnit = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.IntervalUnit");
            Encrypted = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Encrypted");
            RetainRuleInterval = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.Interval");
            RetainRuleIntervalUnit = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.IntervalUnit");
            Target = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Target");
            TargetRegion = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].TargetRegion");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"Policy.PolicyDetails.Schedules[i].ShareRules");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            UnshareInterval = CkJsonObjectW_IntOf(jResp,L"Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareInterval");
            UnshareIntervalUnit = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareIntervalUnit");
            k = 0;
            count_k = CkJsonObjectW_SizeOfArray(jResp,L"Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts");
            while (k < count_k) {
                CkJsonObjectW_putK(jResp,k);
                strVal = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts[k]");
                k = k + 1;
            }

            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"Policy.PolicyDetails.Schedules[i].TagsToAdd");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            Key = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Key");
            Value = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Value");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"Policy.PolicyDetails.Schedules[i].VariableTags");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            Key = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].VariableTags[j].Key");
            Value = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.Schedules[i].VariableTags[j].Value");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"Policy.PolicyDetails.TargetTags");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        Key = CkJsonObjectW_stringOf(jResp,L"Policy.PolicyDetails.TargetTags[i].Key");
        Value = CkJsonObjectW_stringOf(jResp,L"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"
    //     }
    //   }
    // }


    CkRestW_Dispose(rest);
    CkAuthAwsW_Dispose(authAws);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }