ModifyCluster 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 = "cloudhsm"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.setAuthAws(authAws)
// URL: https://cloudhsmv2.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.connect("cloudhsmv2.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.update("BackupRetentionPolicy.Type", value: "string")
json.update("BackupRetentionPolicy.Value", value: "string")
json.update("ClusterId", value: "string")
// The JSON request body created by the above code:
// {
// "BackupRetentionPolicy": {
// "Type": "string",
// "Value": "string"
// },
// "ClusterId": "string"
// }
rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
rest.addHeader("X-Amz-Target", value: "BaldrApiService.ModifyCluster")
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 AvailabilityZone: String?
var EniId: String?
var EniIp: String?
var HsmId: String?
var SubnetId: String?
var Key: String?
var BackupPolicy: String? = jResp.string(of: "Cluster.BackupPolicy")
var v_Type: String? = jResp.string(of: "Cluster.BackupRetentionPolicy.Type")
var Value: String? = jResp.string(of: "Cluster.BackupRetentionPolicy.Value")
var AwsHardwareCertificate: String? = jResp.string(of: "Cluster.Certificates.AwsHardwareCertificate")
var ClusterCertificate: String? = jResp.string(of: "Cluster.Certificates.ClusterCertificate")
var ClusterCsr: String? = jResp.string(of: "Cluster.Certificates.ClusterCsr")
var HsmCertificate: String? = jResp.string(of: "Cluster.Certificates.HsmCertificate")
var ManufacturerHardwareCertificate: String? = jResp.string(of: "Cluster.Certificates.ManufacturerHardwareCertificate")
var ClusterId: String? = jResp.string(of: "Cluster.ClusterId")
var CreateTimestamp: Int = jResp.int(of: "Cluster.CreateTimestamp").intValue
var HsmType: String? = jResp.string(of: "Cluster.HsmType")
var PreCoPassword: String? = jResp.string(of: "Cluster.PreCoPassword")
var SecurityGroup: String? = jResp.string(of: "Cluster.SecurityGroup")
var SourceBackupId: String? = jResp.string(of: "Cluster.SourceBackupId")
var State: String? = jResp.string(of: "Cluster.State")
var StateMessage: String? = jResp.string(of: "Cluster.StateMessage")
var v_String: String? = jResp.string(of: "Cluster.SubnetMapping.string")
var VpcId: String? = jResp.string(of: "Cluster.VpcId")
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "Cluster.Hsms").intValue
while i < count_i {
jResp.i = i
AvailabilityZone = jResp.string(of: "Cluster.Hsms[i].AvailabilityZone")
ClusterId = jResp.string(of: "Cluster.Hsms[i].ClusterId")
EniId = jResp.string(of: "Cluster.Hsms[i].EniId")
EniIp = jResp.string(of: "Cluster.Hsms[i].EniIp")
HsmId = jResp.string(of: "Cluster.Hsms[i].HsmId")
State = jResp.string(of: "Cluster.Hsms[i].State")
StateMessage = jResp.string(of: "Cluster.Hsms[i].StateMessage")
SubnetId = jResp.string(of: "Cluster.Hsms[i].SubnetId")
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "Cluster.TagList").intValue
while i < count_i {
jResp.i = i
Key = jResp.string(of: "Cluster.TagList[i].Key")
Value = jResp.string(of: "Cluster.TagList[i].Value")
i = i + 1
}
// A sample JSON response body parsed by the above code:
// {
// "Cluster": {
// "BackupPolicy": "string",
// "BackupRetentionPolicy": {
// "Type": "string",
// "Value": "string"
// },
// "Certificates": {
// "AwsHardwareCertificate": "string",
// "ClusterCertificate": "string",
// "ClusterCsr": "string",
// "HsmCertificate": "string",
// "ManufacturerHardwareCertificate": "string"
// },
// "ClusterId": "string",
// "CreateTimestamp": number,
// "Hsms": [
// {
// "AvailabilityZone": "string",
// "ClusterId": "string",
// "EniId": "string",
// "EniIp": "string",
// "HsmId": "string",
// "State": "string",
// "StateMessage": "string",
// "SubnetId": "string"
// }
// ],
// "HsmType": "string",
// "PreCoPassword": "string",
// "SecurityGroup": "string",
// "SourceBackupId": "string",
// "State": "string",
// "StateMessage": "string",
// "SubnetMapping": {
// "string": "string"
// },
// "TagList": [
// {
// "Key": "string",
// "Value": "string"
// }
// ],
// "VpcId": "string"
// }
// }
}