CreateFirewall Swift 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 = "network-firewall"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.SetAuthAws(authAws)
// URL: https://network-firewall.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.Connect("network-firewall.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("DeleteProtection", value: 123)
json.UpdateString("Description", value: "string")
json.UpdateString("EncryptionConfiguration.KeyId", value: "string")
json.UpdateString("EncryptionConfiguration.Type", value: "string")
json.UpdateString("FirewallName", value: "string")
json.UpdateString("FirewallPolicyArn", value: "string")
json.UpdateInt("FirewallPolicyChangeProtection", value: 123)
json.UpdateInt("SubnetChangeProtection", value: 123)
json.UpdateString("SubnetMappings[0].SubnetId", value: "string")
json.UpdateString("Tags[0].Key", value: "string")
json.UpdateString("Tags[0].Value", value: "string")
json.UpdateString("VpcId", value: "string")
// The JSON request body created by the above code:
// {
// "DeleteProtection": boolean,
// "Description": "string",
// "EncryptionConfiguration": {
// "KeyId": "string",
// "Type": "string"
// },
// "FirewallName": "string",
// "FirewallPolicyArn": "string",
// "FirewallPolicyChangeProtection": boolean,
// "SubnetChangeProtection": boolean,
// "SubnetMappings": [
// {
// "SubnetId": "string"
// }
// ],
// "Tags": [
// {
// "Key": "string",
// "Value": "string"
// }
// ],
// "VpcId": "string"
// }
rest.AddHeader("Content-Type", value: "application/x-amz-json-1.0")
rest.AddHeader("X-Amz-Target", value: "NetworkFirewall_20201112.CreateFirewall")
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 Key: String?
var Value: String?
var DeleteProtection: Int = jResp.IntOf("Firewall.DeleteProtection").intValue
var Description: String? = jResp.StringOf("Firewall.Description")
var KeyId: String? = jResp.StringOf("Firewall.EncryptionConfiguration.KeyId")
var v_Type: String? = jResp.StringOf("Firewall.EncryptionConfiguration.Type")
var FirewallArn: String? = jResp.StringOf("Firewall.FirewallArn")
var FirewallId: String? = jResp.StringOf("Firewall.FirewallId")
var FirewallName: String? = jResp.StringOf("Firewall.FirewallName")
var FirewallPolicyArn: String? = jResp.StringOf("Firewall.FirewallPolicyArn")
var FirewallPolicyChangeProtection: Int = jResp.IntOf("Firewall.FirewallPolicyChangeProtection").intValue
var SubnetChangeProtection: Int = jResp.IntOf("Firewall.SubnetChangeProtection").intValue
var VpcId: String? = jResp.StringOf("Firewall.VpcId")
var ConfigurationSyncStateSummary: String? = jResp.StringOf("FirewallStatus.ConfigurationSyncStateSummary")
var Status: String? = jResp.StringOf("FirewallStatus.Status")
var EndpointId: String? = jResp.StringOf("FirewallStatus.SyncStates.string.Attachment.EndpointId")
var AttachmentStatus: String? = jResp.StringOf("FirewallStatus.SyncStates.string.Attachment.Status")
var SubnetId: String? = jResp.StringOf("FirewallStatus.SyncStates.string.Attachment.SubnetId")
var SyncStatus: String? = jResp.StringOf("FirewallStatus.SyncStates.string.Config.string.SyncStatus")
var UpdateToken: String? = jResp.StringOf("FirewallStatus.SyncStates.string.Config.string.UpdateToken")
var i: Int = 0
var count_i: Int = jResp.SizeOfArray("Firewall.SubnetMappings").intValue
while i < count_i {
jResp.I = i
SubnetId = jResp.StringOf("Firewall.SubnetMappings[i].SubnetId")
i = i + 1
}
i = 0
count_i = jResp.SizeOfArray("Firewall.Tags").intValue
while i < count_i {
jResp.I = i
Key = jResp.StringOf("Firewall.Tags[i].Key")
Value = jResp.StringOf("Firewall.Tags[i].Value")
i = i + 1
}
// A sample JSON response body parsed by the above code:
// {
// "Firewall": {
// "DeleteProtection": boolean,
// "Description": "string",
// "EncryptionConfiguration": {
// "KeyId": "string",
// "Type": "string"
// },
// "FirewallArn": "string",
// "FirewallId": "string",
// "FirewallName": "string",
// "FirewallPolicyArn": "string",
// "FirewallPolicyChangeProtection": boolean,
// "SubnetChangeProtection": boolean,
// "SubnetMappings": [
// {
// "SubnetId": "string"
// }
// ],
// "Tags": [
// {
// "Key": "string",
// "Value": "string"
// }
// ],
// "VpcId": "string"
// },
// "FirewallStatus": {
// "ConfigurationSyncStateSummary": "string",
// "Status": "string",
// "SyncStates": {
// "string": {
// "Attachment": {
// "EndpointId": "string",
// "Status": "string",
// "SubnetId": "string"
// },
// "Config": {
// "string": {
// "SyncStatus": "string",
// "UpdateToken": "string"
// }
// }
// }
// }
// }
// }
}