Chilkat Online Tools

GetLifecyclePolicy unicodeCpp Example

Amazon Data Lifecycle Manager

#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>

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

    CkRestW rest;
    bool success;

    CkAuthAwsW authAws;
    authAws.put_AccessKey(L"AWS_ACCESS_KEY");
    authAws.put_SecretKey(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.)
    authAws.put_Region(L"us-west-2");
    authAws.put_ServiceName(L"dlm");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://dlm.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect(L"dlm.us-west-2.amazonaws.com",443,true,true);
    if (success != true) {
        wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

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

    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestNoBodySb(L"GET",L"/policies/{policyId}/",sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    int respStatusCode = rest.get_ResponseStatusCode();
    wprintf(L"response status code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",rest.responseHeader());
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",sbResponseBody.getAsString());
        return;
    }

    CkJsonObjectW jResp;
    jResp.LoadSb(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.

    const wchar_t *Name = 0;
    int j;
    int count_j;
    const wchar_t *CmkArn = 0;
    int Encrypted;
    int Interval;
    const wchar_t *IntervalUnit = 0;
    const wchar_t *Target = 0;
    const wchar_t *strVal = 0;
    int CopyTags;
    const wchar_t *CronExpression = 0;
    int CreateRuleInterval;
    const wchar_t *CreateRuleIntervalUnit = 0;
    const wchar_t *Location = 0;
    int Count;
    int DeprecateRuleInterval;
    const wchar_t *DeprecateRuleIntervalUnit = 0;
    int FastRestoreRuleCount;
    int FastRestoreRuleInterval;
    const wchar_t *FastRestoreRuleIntervalUnit = 0;
    int RetainRuleCount;
    int RetainRuleInterval;
    const wchar_t *RetainRuleIntervalUnit = 0;
    const wchar_t *TargetRegion = 0;
    int UnshareInterval;
    const wchar_t *UnshareIntervalUnit = 0;
    int k;
    int count_k;
    const wchar_t *Key = 0;
    const wchar_t *Value = 0;

    int DateCreated = jResp.IntOf(L"Policy.DateCreated");
    int DateModified = jResp.IntOf(L"Policy.DateModified");
    const wchar_t *Description = jResp.stringOf(L"Policy.Description");
    const wchar_t *ExecutionRoleArn = jResp.stringOf(L"Policy.ExecutionRoleArn");
    const wchar_t *PolicyArn = jResp.stringOf(L"Policy.PolicyArn");
    const wchar_t *DescriptionRegex = jResp.stringOf(L"Policy.PolicyDetails.EventSource.Parameters.DescriptionRegex");
    const wchar_t *EventType = jResp.stringOf(L"Policy.PolicyDetails.EventSource.Parameters.EventType");
    const wchar_t *v_Type = jResp.stringOf(L"Policy.PolicyDetails.EventSource.Type");
    int ExcludeBootVolume = jResp.IntOf(L"Policy.PolicyDetails.Parameters.ExcludeBootVolume");
    int NoReboot = jResp.IntOf(L"Policy.PolicyDetails.Parameters.NoReboot");
    const wchar_t *PolicyType = jResp.stringOf(L"Policy.PolicyDetails.PolicyType");
    const wchar_t *PolicyId = jResp.stringOf(L"Policy.PolicyId");
    const wchar_t *State = jResp.stringOf(L"Policy.State");
    const wchar_t *StatusMessage = jResp.stringOf(L"Policy.StatusMessage");
    const wchar_t *v_String = jResp.stringOf(L"Policy.Tags.string");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"Policy.PolicyDetails.Actions");
    while (i < count_i) {
        jResp.put_I(i);
        Name = jResp.stringOf(L"Policy.PolicyDetails.Actions[i].Name");
        j = 0;
        count_j = jResp.SizeOfArray(L"Policy.PolicyDetails.Actions[i].CrossRegionCopy");
        while (j < count_j) {
            jResp.put_J(j);
            CmkArn = jResp.stringOf(L"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.CmkArn");
            Encrypted = jResp.IntOf(L"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.Encrypted");
            Interval = jResp.IntOf(L"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.Interval");
            IntervalUnit = jResp.stringOf(L"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.IntervalUnit");
            Target = jResp.stringOf(L"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].Target");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"Policy.PolicyDetails.ResourceLocations");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"Policy.PolicyDetails.ResourceLocations[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"Policy.PolicyDetails.ResourceTypes");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"Policy.PolicyDetails.ResourceTypes[i]");
        i = i + 1;
    }

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

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

        j = 0;
        count_j = jResp.SizeOfArray(L"Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(L"Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones[j]");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"Policy.PolicyDetails.Schedules[i].ShareRules");
        while (j < count_j) {
            jResp.put_J(j);
            UnshareInterval = jResp.IntOf(L"Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareInterval");
            UnshareIntervalUnit = jResp.stringOf(L"Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareIntervalUnit");
            k = 0;
            count_k = jResp.SizeOfArray(L"Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts");
            while (k < count_k) {
                jResp.put_K(k);
                strVal = jResp.stringOf(L"Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts[k]");
                k = k + 1;
            }

            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"Policy.PolicyDetails.Schedules[i].TagsToAdd");
        while (j < count_j) {
            jResp.put_J(j);
            Key = jResp.stringOf(L"Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Key");
            Value = jResp.stringOf(L"Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Value");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"Policy.PolicyDetails.Schedules[i].VariableTags");
        while (j < count_j) {
            jResp.put_J(j);
            Key = jResp.stringOf(L"Policy.PolicyDetails.Schedules[i].VariableTags[j].Key");
            Value = jResp.stringOf(L"Policy.PolicyDetails.Schedules[i].VariableTags[j].Value");
            j = j + 1;
        }

        i = i + 1;
    }

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