Chilkat Online Tools

DescribeCertificate unicodeCpp Example

AWS Certificate Manager

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

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

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

    // {
    //   "CertificateArn": "string"
    // }

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

    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 *Name = 0;
    const wchar_t *ResourceRecordType = 0;
    const wchar_t *Value = 0;
    const wchar_t *ValidationDomain = 0;
    const wchar_t *ValidationMethod = 0;
    const wchar_t *ValidationStatus = 0;
    int j;
    int count_j;
    const wchar_t *strVal = 0;
    const wchar_t *OID = 0;
    const wchar_t *ResourceRecordName = 0;
    const wchar_t *ResourceRecordValue = 0;

    const wchar_t *CertificateArn = jResp.stringOf(L"Certificate.CertificateArn");
    const wchar_t *CertificateAuthorityArn = jResp.stringOf(L"Certificate.CertificateAuthorityArn");
    int CreatedAt = jResp.IntOf(L"Certificate.CreatedAt");
    const wchar_t *DomainName = jResp.stringOf(L"Certificate.DomainName");
    const wchar_t *FailureReason = jResp.stringOf(L"Certificate.FailureReason");
    int ImportedAt = jResp.IntOf(L"Certificate.ImportedAt");
    int IssuedAt = jResp.IntOf(L"Certificate.IssuedAt");
    const wchar_t *Issuer = jResp.stringOf(L"Certificate.Issuer");
    const wchar_t *KeyAlgorithm = jResp.stringOf(L"Certificate.KeyAlgorithm");
    int NotAfter = jResp.IntOf(L"Certificate.NotAfter");
    int NotBefore = jResp.IntOf(L"Certificate.NotBefore");
    const wchar_t *CertificateTransparencyLoggingPreference = jResp.stringOf(L"Certificate.Options.CertificateTransparencyLoggingPreference");
    const wchar_t *RenewalEligibility = jResp.stringOf(L"Certificate.RenewalEligibility");
    const wchar_t *RenewalStatus = jResp.stringOf(L"Certificate.RenewalSummary.RenewalStatus");
    const wchar_t *RenewalStatusReason = jResp.stringOf(L"Certificate.RenewalSummary.RenewalStatusReason");
    int UpdatedAt = jResp.IntOf(L"Certificate.RenewalSummary.UpdatedAt");
    const wchar_t *RevocationReason = jResp.stringOf(L"Certificate.RevocationReason");
    int RevokedAt = jResp.IntOf(L"Certificate.RevokedAt");
    const wchar_t *Serial = jResp.stringOf(L"Certificate.Serial");
    const wchar_t *SignatureAlgorithm = jResp.stringOf(L"Certificate.SignatureAlgorithm");
    const wchar_t *Status = jResp.stringOf(L"Certificate.Status");
    const wchar_t *Subject = jResp.stringOf(L"Certificate.Subject");
    const wchar_t *v_Type = jResp.stringOf(L"Certificate.Type");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"Certificate.DomainValidationOptions");
    while (i < count_i) {
        jResp.put_I(i);
        DomainName = jResp.stringOf(L"Certificate.DomainValidationOptions[i].DomainName");
        Name = jResp.stringOf(L"Certificate.DomainValidationOptions[i].ResourceRecord.Name");
        ResourceRecordType = jResp.stringOf(L"Certificate.DomainValidationOptions[i].ResourceRecord.Type");
        Value = jResp.stringOf(L"Certificate.DomainValidationOptions[i].ResourceRecord.Value");
        ValidationDomain = jResp.stringOf(L"Certificate.DomainValidationOptions[i].ValidationDomain");
        ValidationMethod = jResp.stringOf(L"Certificate.DomainValidationOptions[i].ValidationMethod");
        ValidationStatus = jResp.stringOf(L"Certificate.DomainValidationOptions[i].ValidationStatus");
        j = 0;
        count_j = jResp.SizeOfArray(L"Certificate.DomainValidationOptions[i].ValidationEmails");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(L"Certificate.DomainValidationOptions[i].ValidationEmails[j]");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"Certificate.ExtendedKeyUsages");
    while (i < count_i) {
        jResp.put_I(i);
        Name = jResp.stringOf(L"Certificate.ExtendedKeyUsages[i].Name");
        OID = jResp.stringOf(L"Certificate.ExtendedKeyUsages[i].OID");
        i = i + 1;
    }

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

    i = 0;
    count_i = jResp.SizeOfArray(L"Certificate.KeyUsages");
    while (i < count_i) {
        jResp.put_I(i);
        Name = jResp.stringOf(L"Certificate.KeyUsages[i].Name");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"Certificate.RenewalSummary.DomainValidationOptions");
    while (i < count_i) {
        jResp.put_I(i);
        DomainName = jResp.stringOf(L"Certificate.RenewalSummary.DomainValidationOptions[i].DomainName");
        ResourceRecordName = jResp.stringOf(L"Certificate.RenewalSummary.DomainValidationOptions[i].ResourceRecord.Name");
        ResourceRecordType = jResp.stringOf(L"Certificate.RenewalSummary.DomainValidationOptions[i].ResourceRecord.Type");
        ResourceRecordValue = jResp.stringOf(L"Certificate.RenewalSummary.DomainValidationOptions[i].ResourceRecord.Value");
        ValidationDomain = jResp.stringOf(L"Certificate.RenewalSummary.DomainValidationOptions[i].ValidationDomain");
        ValidationMethod = jResp.stringOf(L"Certificate.RenewalSummary.DomainValidationOptions[i].ValidationMethod");
        ValidationStatus = jResp.stringOf(L"Certificate.RenewalSummary.DomainValidationOptions[i].ValidationStatus");
        j = 0;
        count_j = jResp.SizeOfArray(L"Certificate.RenewalSummary.DomainValidationOptions[i].ValidationEmails");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(L"Certificate.RenewalSummary.DomainValidationOptions[i].ValidationEmails[j]");
            j = j + 1;
        }

        i = i + 1;
    }

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

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

    // {
    //   "Certificate": {
    //     "CertificateArn": "string",
    //     "CertificateAuthorityArn": "string",
    //     "CreatedAt": number,
    //     "DomainName": "string",
    //     "DomainValidationOptions": [
    //       {
    //         "DomainName": "string",
    //         "ResourceRecord": {
    //           "Name": "string",
    //           "Type": "string",
    //           "Value": "string"
    //         },
    //         "ValidationDomain": "string",
    //         "ValidationEmails": [
    //           "string"
    //         ],
    //         "ValidationMethod": "string",
    //         "ValidationStatus": "string"
    //       }
    //     ],
    //     "ExtendedKeyUsages": [
    //       {
    //         "Name": "string",
    //         "OID": "string"
    //       }
    //     ],
    //     "FailureReason": "string",
    //     "ImportedAt": number,
    //     "InUseBy": [
    //       "string"
    //     ],
    //     "IssuedAt": number,
    //     "Issuer": "string",
    //     "KeyAlgorithm": "string",
    //     "KeyUsages": [
    //       {
    //         "Name": "string"
    //       }
    //     ],
    //     "NotAfter": number,
    //     "NotBefore": number,
    //     "Options": {
    //       "CertificateTransparencyLoggingPreference": "string"
    //     },
    //     "RenewalEligibility": "string",
    //     "RenewalSummary": {
    //       "DomainValidationOptions": [
    //         {
    //           "DomainName": "string",
    //           "ResourceRecord": {
    //             "Name": "string",
    //             "Type": "string",
    //             "Value": "string"
    //           },
    //           "ValidationDomain": "string",
    //           "ValidationEmails": [
    //             "string"
    //           ],
    //           "ValidationMethod": "string",
    //           "ValidationStatus": "string"
    //         }
    //       ],
    //       "RenewalStatus": "string",
    //       "RenewalStatusReason": "string",
    //       "UpdatedAt": number
    //     },
    //     "RevocationReason": "string",
    //     "RevokedAt": number,
    //     "Serial": "string",
    //     "SignatureAlgorithm": "string",
    //     "Status": "string",
    //     "Subject": "string",
    //     "SubjectAlternativeNames": [
    //       "string"
    //     ],
    //     "Type": "string"
    //   }
    // }
    }