Chilkat Online Tools

DescribeConfigRules unicodeCpp Example

AWS Config

#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.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"config");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://config.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect(L"config.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;
    }

    // The following code creates the JSON request body.
    // The JSON created by this code is shown below.

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    CkJsonObjectW json;
    json.UpdateString(L"ConfigRuleNames[0]",L"string");
    json.UpdateString(L"NextToken",L"string");

    // The JSON request body created by the above code:

    // {
    //   "ConfigRuleNames": [
    //     "string"
    //   ],
    //   "NextToken": "string"
    // }

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

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);
    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestSb(L"POST",L"/",sbRequestBody,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 *ConfigRuleArn = 0;
    const wchar_t *ConfigRuleId = 0;
    const wchar_t *ConfigRuleName = 0;
    const wchar_t *ConfigRuleState = 0;
    const wchar_t *CreatedBy = 0;
    const wchar_t *Description = 0;
    const wchar_t *InputParameters = 0;
    const wchar_t *MaximumExecutionFrequency = 0;
    const wchar_t *ComplianceResourceId = 0;
    const wchar_t *TagKey = 0;
    const wchar_t *TagValue = 0;
    int EnableDebugLogDelivery;
    const wchar_t *PolicyRuntime = 0;
    const wchar_t *PolicyText = 0;
    const wchar_t *Owner = 0;
    const wchar_t *SourceIdentifier = 0;
    int j;
    int count_j;
    const wchar_t *strVal = 0;
    const wchar_t *EventSource = 0;
    const wchar_t *MessageType = 0;

    const wchar_t *NextToken = jResp.stringOf(L"NextToken");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"ConfigRules");
    while (i < count_i) {
        jResp.put_I(i);
        ConfigRuleArn = jResp.stringOf(L"ConfigRules[i].ConfigRuleArn");
        ConfigRuleId = jResp.stringOf(L"ConfigRules[i].ConfigRuleId");
        ConfigRuleName = jResp.stringOf(L"ConfigRules[i].ConfigRuleName");
        ConfigRuleState = jResp.stringOf(L"ConfigRules[i].ConfigRuleState");
        CreatedBy = jResp.stringOf(L"ConfigRules[i].CreatedBy");
        Description = jResp.stringOf(L"ConfigRules[i].Description");
        InputParameters = jResp.stringOf(L"ConfigRules[i].InputParameters");
        MaximumExecutionFrequency = jResp.stringOf(L"ConfigRules[i].MaximumExecutionFrequency");
        ComplianceResourceId = jResp.stringOf(L"ConfigRules[i].Scope.ComplianceResourceId");
        TagKey = jResp.stringOf(L"ConfigRules[i].Scope.TagKey");
        TagValue = jResp.stringOf(L"ConfigRules[i].Scope.TagValue");
        EnableDebugLogDelivery = jResp.IntOf(L"ConfigRules[i].Source.CustomPolicyDetails.EnableDebugLogDelivery");
        PolicyRuntime = jResp.stringOf(L"ConfigRules[i].Source.CustomPolicyDetails.PolicyRuntime");
        PolicyText = jResp.stringOf(L"ConfigRules[i].Source.CustomPolicyDetails.PolicyText");
        Owner = jResp.stringOf(L"ConfigRules[i].Source.Owner");
        SourceIdentifier = jResp.stringOf(L"ConfigRules[i].Source.SourceIdentifier");
        j = 0;
        count_j = jResp.SizeOfArray(L"ConfigRules[i].Scope.ComplianceResourceTypes");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(L"ConfigRules[i].Scope.ComplianceResourceTypes[j]");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"ConfigRules[i].Source.SourceDetails");
        while (j < count_j) {
            jResp.put_J(j);
            EventSource = jResp.stringOf(L"ConfigRules[i].Source.SourceDetails[j].EventSource");
            MaximumExecutionFrequency = jResp.stringOf(L"ConfigRules[i].Source.SourceDetails[j].MaximumExecutionFrequency");
            MessageType = jResp.stringOf(L"ConfigRules[i].Source.SourceDetails[j].MessageType");
            j = j + 1;
        }

        i = i + 1;
    }

    // A sample JSON response body parsed by the above code:

    // {
    //   "ConfigRules": [
    //     {
    //       "ConfigRuleArn": "string",
    //       "ConfigRuleId": "string",
    //       "ConfigRuleName": "string",
    //       "ConfigRuleState": "string",
    //       "CreatedBy": "string",
    //       "Description": "string",
    //       "InputParameters": "string",
    //       "MaximumExecutionFrequency": "string",
    //       "Scope": {
    //         "ComplianceResourceId": "string",
    //         "ComplianceResourceTypes": [
    //           "string"
    //         ],
    //         "TagKey": "string",
    //         "TagValue": "string"
    //       },
    //       "Source": {
    //         "CustomPolicyDetails": {
    //           "EnableDebugLogDelivery": boolean,
    //           "PolicyRuntime": "string",
    //           "PolicyText": "string"
    //         },
    //         "Owner": "string",
    //         "SourceDetails": [
    //           {
    //             "EventSource": "string",
    //             "MaximumExecutionFrequency": "string",
    //             "MessageType": "string"
    //           }
    //         ],
    //         "SourceIdentifier": "string"
    //       }
    //     }
    //   ],
    //   "NextToken": "string"
    // }
    }