ListCertificateAuthorities C++ Example
#include <CkRest.h>
#include <CkAuthAws.h>
#include <CkJsonObject.h>
#include <CkStringBuilder.h>
void ChilkatSample(void)
{
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkRest rest;
bool success;
CkAuthAws authAws;
authAws.put_AccessKey("AWS_ACCESS_KEY");
authAws.put_SecretKey("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("us-west-2");
authAws.put_ServiceName("acm-pca");
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.SetAuthAws(authAws);
// URL: https://acm-pca.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.Connect("acm-pca.us-west-2.amazonaws.com",443,true,true);
if (success != true) {
std::cout << "ConnectFailReason: " << rest.get_ConnectFailReason() << "\r\n";
std::cout << rest.lastErrorText() << "\r\n";
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
CkJsonObject json;
json.UpdateInt("MaxResults",123);
json.UpdateString("NextToken","string");
json.UpdateString("ResourceOwner","string");
// The JSON request body created by the above code:
// {
// "MaxResults": number,
// "NextToken": "string",
// "ResourceOwner": "string"
// }
rest.AddHeader("Content-Type","application/x-amz-json-1.1");
rest.AddHeader("X-Amz-Target","ACMPrivateCA.ListCertificateAuthorities");
CkStringBuilder sbRequestBody;
json.EmitSb(sbRequestBody);
CkStringBuilder sbResponseBody;
success = rest.FullRequestSb("POST","/",sbRequestBody,sbResponseBody);
if (success != true) {
std::cout << rest.lastErrorText() << "\r\n";
return;
}
int respStatusCode = rest.get_ResponseStatusCode();
std::cout << "response status code = " << respStatusCode << "\r\n";
if (respStatusCode != 200) {
std::cout << "Response Header:" << "\r\n";
std::cout << rest.responseHeader() << "\r\n";
std::cout << "Response Body:" << "\r\n";
std::cout << sbResponseBody.getAsString() << "\r\n";
return;
}
CkJsonObject 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 char *Arn = 0;
int CRLSign;
int DataEncipherment;
int DecipherOnly;
int DigitalSignature;
int EncipherOnly;
int KeyAgreement;
int KeyCertSign;
int KeyEncipherment;
int NonRepudiation;
const char *KeyAlgorithm = 0;
const char *SigningAlgorithm = 0;
const char *CommonName = 0;
const char *Country = 0;
const char *DistinguishedNameQualifier = 0;
const char *GenerationQualifier = 0;
const char *GivenName = 0;
const char *Initials = 0;
const char *Locality = 0;
const char *Organization = 0;
const char *OrganizationalUnit = 0;
const char *Pseudonym = 0;
const char *SerialNumber = 0;
const char *State = 0;
const char *Surname = 0;
const char *Title = 0;
int CreatedAt;
const char *FailureReason = 0;
const char *KeyStorageSecurityStandard = 0;
int LastStateChangeAt;
int NotAfter;
int NotBefore;
const char *OwnerAccount = 0;
int RestorableUntil;
const char *CustomCname = 0;
int Enabled;
int ExpirationInDays;
const char *S3BucketName = 0;
const char *S3ObjectAcl = 0;
int OcspConfigurationEnabled;
const char *OcspCustomCname = 0;
const char *Serial = 0;
const char *Status = 0;
const char *v_Type = 0;
int j;
int count_j;
const char *DirectoryNameCommonName = 0;
const char *DirectoryNameCountry = 0;
const char *DirectoryNameDistinguishedNameQualifier = 0;
const char *DirectoryNameGenerationQualifier = 0;
const char *DirectoryNameGivenName = 0;
const char *DirectoryNameInitials = 0;
const char *DirectoryNameLocality = 0;
const char *DirectoryNameOrganization = 0;
const char *DirectoryNameOrganizationalUnit = 0;
const char *DirectoryNamePseudonym = 0;
const char *DirectoryNameSerialNumber = 0;
const char *DirectoryNameState = 0;
const char *DirectoryNameSurname = 0;
const char *DirectoryNameTitle = 0;
const char *DnsName = 0;
const char *NameAssigner = 0;
const char *PartyName = 0;
const char *IpAddress = 0;
const char *TypeId = 0;
const char *Value = 0;
const char *RegisteredId = 0;
const char *Rfc822Name = 0;
const char *UniformResourceIdentifier = 0;
const char *AccessMethodType = 0;
const char *CustomObjectIdentifier = 0;
const char *NextToken = jResp.stringOf("NextToken");
int i = 0;
int count_i = jResp.SizeOfArray("CertificateAuthorities");
while (i < count_i) {
jResp.put_I(i);
Arn = jResp.stringOf("CertificateAuthorities[i].Arn");
CRLSign = jResp.IntOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.CRLSign");
DataEncipherment = jResp.IntOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DataEncipherment");
DecipherOnly = jResp.IntOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DecipherOnly");
DigitalSignature = jResp.IntOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DigitalSignature");
EncipherOnly = jResp.IntOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.EncipherOnly");
KeyAgreement = jResp.IntOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyAgreement");
KeyCertSign = jResp.IntOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyCertSign");
KeyEncipherment = jResp.IntOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyEncipherment");
NonRepudiation = jResp.IntOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.NonRepudiation");
KeyAlgorithm = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.KeyAlgorithm");
SigningAlgorithm = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.SigningAlgorithm");
CommonName = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.CommonName");
Country = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.Country");
DistinguishedNameQualifier = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.DistinguishedNameQualifier");
GenerationQualifier = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.GenerationQualifier");
GivenName = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.GivenName");
Initials = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.Initials");
Locality = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.Locality");
Organization = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.Organization");
OrganizationalUnit = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.OrganizationalUnit");
Pseudonym = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.Pseudonym");
SerialNumber = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.SerialNumber");
State = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.State");
Surname = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.Surname");
Title = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.Title");
CreatedAt = jResp.IntOf("CertificateAuthorities[i].CreatedAt");
FailureReason = jResp.stringOf("CertificateAuthorities[i].FailureReason");
KeyStorageSecurityStandard = jResp.stringOf("CertificateAuthorities[i].KeyStorageSecurityStandard");
LastStateChangeAt = jResp.IntOf("CertificateAuthorities[i].LastStateChangeAt");
NotAfter = jResp.IntOf("CertificateAuthorities[i].NotAfter");
NotBefore = jResp.IntOf("CertificateAuthorities[i].NotBefore");
OwnerAccount = jResp.stringOf("CertificateAuthorities[i].OwnerAccount");
RestorableUntil = jResp.IntOf("CertificateAuthorities[i].RestorableUntil");
CustomCname = jResp.stringOf("CertificateAuthorities[i].RevocationConfiguration.CrlConfiguration.CustomCname");
Enabled = jResp.IntOf("CertificateAuthorities[i].RevocationConfiguration.CrlConfiguration.Enabled");
ExpirationInDays = jResp.IntOf("CertificateAuthorities[i].RevocationConfiguration.CrlConfiguration.ExpirationInDays");
S3BucketName = jResp.stringOf("CertificateAuthorities[i].RevocationConfiguration.CrlConfiguration.S3BucketName");
S3ObjectAcl = jResp.stringOf("CertificateAuthorities[i].RevocationConfiguration.CrlConfiguration.S3ObjectAcl");
OcspConfigurationEnabled = jResp.IntOf("CertificateAuthorities[i].RevocationConfiguration.OcspConfiguration.Enabled");
OcspCustomCname = jResp.stringOf("CertificateAuthorities[i].RevocationConfiguration.OcspConfiguration.OcspCustomCname");
Serial = jResp.stringOf("CertificateAuthorities[i].Serial");
Status = jResp.stringOf("CertificateAuthorities[i].Status");
v_Type = jResp.stringOf("CertificateAuthorities[i].Type");
j = 0;
count_j = jResp.SizeOfArray("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess");
while (j < count_j) {
jResp.put_J(j);
DirectoryNameCommonName = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.CommonName");
DirectoryNameCountry = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.Country");
DirectoryNameDistinguishedNameQualifier = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.DistinguishedNameQualifier");
DirectoryNameGenerationQualifier = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.GenerationQualifier");
DirectoryNameGivenName = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.GivenName");
DirectoryNameInitials = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.Initials");
DirectoryNameLocality = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.Locality");
DirectoryNameOrganization = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.Organization");
DirectoryNameOrganizationalUnit = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.OrganizationalUnit");
DirectoryNamePseudonym = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.Pseudonym");
DirectoryNameSerialNumber = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.SerialNumber");
DirectoryNameState = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.State");
DirectoryNameSurname = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.Surname");
DirectoryNameTitle = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.Title");
DnsName = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DnsName");
NameAssigner = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.EdiPartyName.NameAssigner");
PartyName = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.EdiPartyName.PartyName");
IpAddress = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.IpAddress");
TypeId = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.OtherName.TypeId");
Value = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.OtherName.Value");
RegisteredId = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.RegisteredId");
Rfc822Name = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.Rfc822Name");
UniformResourceIdentifier = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.UniformResourceIdentifier");
AccessMethodType = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessMethod.AccessMethodType");
CustomObjectIdentifier = jResp.stringOf("CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessMethod.CustomObjectIdentifier");
j = j + 1;
}
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "CertificateAuthorities": [
// {
// "Arn": "string",
// "CertificateAuthorityConfiguration": {
// "CsrExtensions": {
// "KeyUsage": {
// "CRLSign": boolean,
// "DataEncipherment": boolean,
// "DecipherOnly": boolean,
// "DigitalSignature": boolean,
// "EncipherOnly": boolean,
// "KeyAgreement": boolean,
// "KeyCertSign": boolean,
// "KeyEncipherment": boolean,
// "NonRepudiation": boolean
// },
// "SubjectInformationAccess": [
// {
// "AccessLocation": {
// "DirectoryName": {
// "CommonName": "string",
// "Country": "string",
// "DistinguishedNameQualifier": "string",
// "GenerationQualifier": "string",
// "GivenName": "string",
// "Initials": "string",
// "Locality": "string",
// "Organization": "string",
// "OrganizationalUnit": "string",
// "Pseudonym": "string",
// "SerialNumber": "string",
// "State": "string",
// "Surname": "string",
// "Title": "string"
// },
// "DnsName": "string",
// "EdiPartyName": {
// "NameAssigner": "string",
// "PartyName": "string"
// },
// "IpAddress": "string",
// "OtherName": {
// "TypeId": "string",
// "Value": "string"
// },
// "RegisteredId": "string",
// "Rfc822Name": "string",
// "UniformResourceIdentifier": "string"
// },
// "AccessMethod": {
// "AccessMethodType": "string",
// "CustomObjectIdentifier": "string"
// }
// }
// ]
// },
// "KeyAlgorithm": "string",
// "SigningAlgorithm": "string",
// "Subject": {
// "CommonName": "string",
// "Country": "string",
// "DistinguishedNameQualifier": "string",
// "GenerationQualifier": "string",
// "GivenName": "string",
// "Initials": "string",
// "Locality": "string",
// "Organization": "string",
// "OrganizationalUnit": "string",
// "Pseudonym": "string",
// "SerialNumber": "string",
// "State": "string",
// "Surname": "string",
// "Title": "string"
// }
// },
// "CreatedAt": number,
// "FailureReason": "string",
// "KeyStorageSecurityStandard": "string",
// "LastStateChangeAt": number,
// "NotAfter": number,
// "NotBefore": number,
// "OwnerAccount": "string",
// "RestorableUntil": number,
// "RevocationConfiguration": {
// "CrlConfiguration": {
// "CustomCname": "string",
// "Enabled": boolean,
// "ExpirationInDays": number,
// "S3BucketName": "string",
// "S3ObjectAcl": "string"
// },
// "OcspConfiguration": {
// "Enabled": boolean,
// "OcspCustomCname": "string"
// }
// },
// "Serial": "string",
// "Status": "string",
// "Type": "string"
// }
// ],
// "NextToken": "string"
// }
}