GetContainerRecipe 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 = "imagebuilder"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.setAuthAws(authAws)
// URL: https://imagebuilder.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.connect("imagebuilder.us-west-2.amazonaws.com", port: 443, tls: true, autoReconnect: true)
if success != true {
print("ConnectFailReason: \(rest.connectFailReason.intValue)")
print("\(rest.lastErrorText!)")
return
}
rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
rest.addHeader("X-Amz-Target", value: "GetContainerRecipe")
let sbResponseBody = CkoStringBuilder()!
success = rest.fullRequestNoBodySb("GET", uriPath: "/GetContainerRecipe", sb: 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 componentArn: String?
var j: Int
var count_j: Int
var name: String?
var k: Int
var count_k: Int
var strVal: String?
var deviceName: String?
var DeleteOnTermination: Int
var ebsEncrypted: Int
var Iops: Int
var ebsKmsKeyId: String?
var SnapshotId: String?
var Throughput: Int
var VolumeSize: Int
var VolumeType: String?
var noDevice: String?
var virtualName: String?
var Arn: String? = jResp.string(of: "containerRecipe.arn")
var ContainerType: String? = jResp.string(of: "containerRecipe.containerType")
var DateCreated: String? = jResp.string(of: "containerRecipe.dateCreated")
var Description: String? = jResp.string(of: "containerRecipe.description")
var DockerfileTemplateData: String? = jResp.string(of: "containerRecipe.dockerfileTemplateData")
var Encrypted: Int = jResp.int(of: "containerRecipe.encrypted").intValue
var Image: String? = jResp.string(of: "containerRecipe.instanceConfiguration.image")
var KmsKeyId: String? = jResp.string(of: "containerRecipe.kmsKeyId")
var Name: String? = jResp.string(of: "containerRecipe.name")
var Owner: String? = jResp.string(of: "containerRecipe.owner")
var ParentImage: String? = jResp.string(of: "containerRecipe.parentImage")
var Platform: String? = jResp.string(of: "containerRecipe.platform")
var v_String: String? = jResp.string(of: "containerRecipe.tags.string")
var RepositoryName: String? = jResp.string(of: "containerRecipe.targetRepository.repositoryName")
var Service: String? = jResp.string(of: "containerRecipe.targetRepository.service")
var Version: String? = jResp.string(of: "containerRecipe.version")
var WorkingDirectory: String? = jResp.string(of: "containerRecipe.workingDirectory")
var requestId: String? = jResp.string(of: "requestId")
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "containerRecipe.components").intValue
while i < count_i {
jResp.i = i
componentArn = jResp.string(of: "containerRecipe.components[i].componentArn")
j = 0
count_j = jResp.size(ofArray: "containerRecipe.components[i].parameters").intValue
while j < count_j {
jResp.j = j
name = jResp.string(of: "containerRecipe.components[i].parameters[j].name")
k = 0
count_k = jResp.size(ofArray: "containerRecipe.components[i].parameters[j].value").intValue
while k < count_k {
jResp.k = k
strVal = jResp.string(of: "containerRecipe.components[i].parameters[j].value[k]")
k = k + 1
}
j = j + 1
}
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "containerRecipe.instanceConfiguration.blockDeviceMappings").intValue
while i < count_i {
jResp.i = i
deviceName = jResp.string(of: "containerRecipe.instanceConfiguration.blockDeviceMappings[i].deviceName")
DeleteOnTermination = jResp.int(of: "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.deleteOnTermination").intValue
ebsEncrypted = jResp.int(of: "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.encrypted").intValue
Iops = jResp.int(of: "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.iops").intValue
ebsKmsKeyId = jResp.string(of: "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.kmsKeyId")
SnapshotId = jResp.string(of: "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.snapshotId")
Throughput = jResp.int(of: "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.throughput").intValue
VolumeSize = jResp.int(of: "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.volumeSize").intValue
VolumeType = jResp.string(of: "containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.volumeType")
noDevice = jResp.string(of: "containerRecipe.instanceConfiguration.blockDeviceMappings[i].noDevice")
virtualName = jResp.string(of: "containerRecipe.instanceConfiguration.blockDeviceMappings[i].virtualName")
i = i + 1
}
// A sample JSON response body parsed by the above code:
// {
// "containerRecipe": {
// "arn": "string",
// "components": [
// {
// "componentArn": "string",
// "parameters": [
// {
// "name": "string",
// "value": [
// "string"
// ]
// }
// ]
// }
// ],
// "containerType": "string",
// "dateCreated": "string",
// "description": "string",
// "dockerfileTemplateData": "string",
// "encrypted": boolean,
// "instanceConfiguration": {
// "blockDeviceMappings": [
// {
// "deviceName": "string",
// "ebs": {
// "deleteOnTermination": boolean,
// "encrypted": boolean,
// "iops": number,
// "kmsKeyId": "string",
// "snapshotId": "string",
// "throughput": number,
// "volumeSize": number,
// "volumeType": "string"
// },
// "noDevice": "string",
// "virtualName": "string"
// }
// ],
// "image": "string"
// },
// "kmsKeyId": "string",
// "name": "string",
// "owner": "string",
// "parentImage": "string",
// "platform": "string",
// "tags": {
// "string": "string"
// },
// "targetRepository": {
// "repositoryName": "string",
// "service": "string"
// },
// "version": "string",
// "workingDirectory": "string"
// },
// "requestId": "string"
// }
}