ListCertificateAuthorities Swift3 Example
func chilkatTest() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let rest = CkoRest()!
var success: Bool
let authAws = CkoAuthAws()!
authAws.accessKey = "AWS_ACCESS_KEY"
authAws.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.region = "us-west-2"
authAws.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", port: 443, tls: true, autoReconnect: true)
if success != true {
print("ConnectFailReason: \(rest.connectFailReason.intValue)")
print("\(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
let json = CkoJsonObject()!
json.updateInt("MaxResults", value: 123)
json.update("NextToken", value: "string")
json.update("ResourceOwner", value: "string")
// The JSON request body created by the above code:
// {
// "MaxResults": number,
// "NextToken": "string",
// "ResourceOwner": "string"
// }
rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
rest.addHeader("X-Amz-Target", value: "ACMPrivateCA.ListCertificateAuthorities")
let sbRequestBody = CkoStringBuilder()!
json.emitSb(sbRequestBody)
let sbResponseBody = CkoStringBuilder()!
success = rest.fullRequestSb("POST", uriPath: "/", requestBody: sbRequestBody, responseBody: sbResponseBody)
if success != true {
print("\(rest.lastErrorText!)")
return
}
var respStatusCode: Int = rest.responseStatusCode.intValue
print("response status code = \(respStatusCode)")
if respStatusCode != 200 {
print("Response Header:")
print("\(rest.responseHeader!)")
print("Response Body:")
print("\(sbResponseBody.getAsString()!)")
return
}
let jResp = CkoJsonObject()!
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
var Arn: String?
var CRLSign: Int
var DataEncipherment: Int
var DecipherOnly: Int
var DigitalSignature: Int
var EncipherOnly: Int
var KeyAgreement: Int
var KeyCertSign: Int
var KeyEncipherment: Int
var NonRepudiation: Int
var KeyAlgorithm: String?
var SigningAlgorithm: String?
var CommonName: String?
var Country: String?
var DistinguishedNameQualifier: String?
var GenerationQualifier: String?
var GivenName: String?
var Initials: String?
var Locality: String?
var Organization: String?
var OrganizationalUnit: String?
var Pseudonym: String?
var SerialNumber: String?
var State: String?
var Surname: String?
var Title: String?
var CreatedAt: Int
var FailureReason: String?
var KeyStorageSecurityStandard: String?
var LastStateChangeAt: Int
var NotAfter: Int
var NotBefore: Int
var OwnerAccount: String?
var RestorableUntil: Int
var CustomCname: String?
var Enabled: Int
var ExpirationInDays: Int
var S3BucketName: String?
var S3ObjectAcl: String?
var OcspConfigurationEnabled: Int
var OcspCustomCname: String?
var Serial: String?
var Status: String?
var v_Type: String?
var j: Int
var count_j: Int
var DirectoryNameCommonName: String?
var DirectoryNameCountry: String?
var DirectoryNameDistinguishedNameQualifier: String?
var DirectoryNameGenerationQualifier: String?
var DirectoryNameGivenName: String?
var DirectoryNameInitials: String?
var DirectoryNameLocality: String?
var DirectoryNameOrganization: String?
var DirectoryNameOrganizationalUnit: String?
var DirectoryNamePseudonym: String?
var DirectoryNameSerialNumber: String?
var DirectoryNameState: String?
var DirectoryNameSurname: String?
var DirectoryNameTitle: String?
var DnsName: String?
var NameAssigner: String?
var PartyName: String?
var IpAddress: String?
var TypeId: String?
var Value: String?
var RegisteredId: String?
var Rfc822Name: String?
var UniformResourceIdentifier: String?
var AccessMethodType: String?
var CustomObjectIdentifier: String?
var NextToken: String? = jResp.string(of: "NextToken")
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "CertificateAuthorities").intValue
while i < count_i {
jResp.i = i
Arn = jResp.string(of: "CertificateAuthorities[i].Arn")
CRLSign = jResp.int(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.CRLSign").intValue
DataEncipherment = jResp.int(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DataEncipherment").intValue
DecipherOnly = jResp.int(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DecipherOnly").intValue
DigitalSignature = jResp.int(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.DigitalSignature").intValue
EncipherOnly = jResp.int(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.EncipherOnly").intValue
KeyAgreement = jResp.int(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyAgreement").intValue
KeyCertSign = jResp.int(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyCertSign").intValue
KeyEncipherment = jResp.int(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.KeyEncipherment").intValue
NonRepudiation = jResp.int(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.KeyUsage.NonRepudiation").intValue
KeyAlgorithm = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.KeyAlgorithm")
SigningAlgorithm = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.SigningAlgorithm")
CommonName = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.CommonName")
Country = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.Country")
DistinguishedNameQualifier = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.DistinguishedNameQualifier")
GenerationQualifier = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.GenerationQualifier")
GivenName = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.GivenName")
Initials = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.Initials")
Locality = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.Locality")
Organization = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.Organization")
OrganizationalUnit = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.OrganizationalUnit")
Pseudonym = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.Pseudonym")
SerialNumber = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.SerialNumber")
State = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.State")
Surname = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.Surname")
Title = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.Subject.Title")
CreatedAt = jResp.int(of: "CertificateAuthorities[i].CreatedAt").intValue
FailureReason = jResp.string(of: "CertificateAuthorities[i].FailureReason")
KeyStorageSecurityStandard = jResp.string(of: "CertificateAuthorities[i].KeyStorageSecurityStandard")
LastStateChangeAt = jResp.int(of: "CertificateAuthorities[i].LastStateChangeAt").intValue
NotAfter = jResp.int(of: "CertificateAuthorities[i].NotAfter").intValue
NotBefore = jResp.int(of: "CertificateAuthorities[i].NotBefore").intValue
OwnerAccount = jResp.string(of: "CertificateAuthorities[i].OwnerAccount")
RestorableUntil = jResp.int(of: "CertificateAuthorities[i].RestorableUntil").intValue
CustomCname = jResp.string(of: "CertificateAuthorities[i].RevocationConfiguration.CrlConfiguration.CustomCname")
Enabled = jResp.int(of: "CertificateAuthorities[i].RevocationConfiguration.CrlConfiguration.Enabled").intValue
ExpirationInDays = jResp.int(of: "CertificateAuthorities[i].RevocationConfiguration.CrlConfiguration.ExpirationInDays").intValue
S3BucketName = jResp.string(of: "CertificateAuthorities[i].RevocationConfiguration.CrlConfiguration.S3BucketName")
S3ObjectAcl = jResp.string(of: "CertificateAuthorities[i].RevocationConfiguration.CrlConfiguration.S3ObjectAcl")
OcspConfigurationEnabled = jResp.int(of: "CertificateAuthorities[i].RevocationConfiguration.OcspConfiguration.Enabled").intValue
OcspCustomCname = jResp.string(of: "CertificateAuthorities[i].RevocationConfiguration.OcspConfiguration.OcspCustomCname")
Serial = jResp.string(of: "CertificateAuthorities[i].Serial")
Status = jResp.string(of: "CertificateAuthorities[i].Status")
v_Type = jResp.string(of: "CertificateAuthorities[i].Type")
j = 0
count_j = jResp.size(ofArray: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess").intValue
while j < count_j {
jResp.j = j
DirectoryNameCommonName = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.CommonName")
DirectoryNameCountry = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.Country")
DirectoryNameDistinguishedNameQualifier = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.DistinguishedNameQualifier")
DirectoryNameGenerationQualifier = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.GenerationQualifier")
DirectoryNameGivenName = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.GivenName")
DirectoryNameInitials = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.Initials")
DirectoryNameLocality = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.Locality")
DirectoryNameOrganization = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.Organization")
DirectoryNameOrganizationalUnit = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.OrganizationalUnit")
DirectoryNamePseudonym = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.Pseudonym")
DirectoryNameSerialNumber = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.SerialNumber")
DirectoryNameState = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.State")
DirectoryNameSurname = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.Surname")
DirectoryNameTitle = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DirectoryName.Title")
DnsName = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.DnsName")
NameAssigner = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.EdiPartyName.NameAssigner")
PartyName = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.EdiPartyName.PartyName")
IpAddress = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.IpAddress")
TypeId = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.OtherName.TypeId")
Value = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.OtherName.Value")
RegisteredId = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.RegisteredId")
Rfc822Name = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.Rfc822Name")
UniformResourceIdentifier = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessLocation.UniformResourceIdentifier")
AccessMethodType = jResp.string(of: "CertificateAuthorities[i].CertificateAuthorityConfiguration.CsrExtensions.SubjectInformationAccess[j].AccessMethod.AccessMethodType")
CustomObjectIdentifier = jResp.string(of: "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"
// }
}