Chilkat Online Tools

DeleteCluster Swift3 Example

Amazon Elastic Kubernetes Service

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 = "eks"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.setAuthAws(authAws)

    // URL: https://eks.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.connect("eks.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: "DeleteCluster")

    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestNoBodySb("DELETE", uriPath: "/clusters/{name}", 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 KeyArn: String?
    var j: Int
    var count_j: Int
    var strVal: String?
    var enabled: Int

    var Arn: String? = jResp.string(of: "cluster.arn")
    var Data: String? = jResp.string(of: "cluster.certificateAuthority.data")
    var ClientRequestToken: String? = jResp.string(of: "cluster.clientRequestToken")
    var ActivationCode: String? = jResp.string(of: "cluster.connectorConfig.activationCode")
    var ActivationExpiry: Int = jResp.int(of: "cluster.connectorConfig.activationExpiry").intValue
    var ActivationId: String? = jResp.string(of: "cluster.connectorConfig.activationId")
    var Provider: String? = jResp.string(of: "cluster.connectorConfig.provider")
    var RoleArn: String? = jResp.string(of: "cluster.connectorConfig.roleArn")
    var CreatedAt: Int = jResp.int(of: "cluster.createdAt").intValue
    var Endpoint: String? = jResp.string(of: "cluster.endpoint")
    var Issuer: String? = jResp.string(of: "cluster.identity.oidc.issuer")
    var IpFamily: String? = jResp.string(of: "cluster.kubernetesNetworkConfig.ipFamily")
    var ServiceIpv4Cidr: String? = jResp.string(of: "cluster.kubernetesNetworkConfig.serviceIpv4Cidr")
    var ServiceIpv6Cidr: String? = jResp.string(of: "cluster.kubernetesNetworkConfig.serviceIpv6Cidr")
    var Name: String? = jResp.string(of: "cluster.name")
    var PlatformVersion: String? = jResp.string(of: "cluster.platformVersion")
    var ClusterSecurityGroupId: String? = jResp.string(of: "cluster.resourcesVpcConfig.clusterSecurityGroupId")
    var EndpointPrivateAccess: Int = jResp.int(of: "cluster.resourcesVpcConfig.endpointPrivateAccess").intValue
    var EndpointPublicAccess: Int = jResp.int(of: "cluster.resourcesVpcConfig.endpointPublicAccess").intValue
    var VpcId: String? = jResp.string(of: "cluster.resourcesVpcConfig.vpcId")
    var clusterRoleArn: String? = jResp.string(of: "cluster.roleArn")
    var Status: String? = jResp.string(of: "cluster.status")
    var v_String: String? = jResp.string(of: "cluster.tags.string")
    var Version: String? = jResp.string(of: "cluster.version")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "cluster.encryptionConfig").intValue
    while i < count_i {
        jResp.i = i
        KeyArn = jResp.string(of: "cluster.encryptionConfig[i].provider.keyArn")
        j = 0
        count_j = jResp.size(ofArray: "cluster.encryptionConfig[i].resources").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "cluster.encryptionConfig[i].resources[j]")
            j = j + 1
        }

        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "cluster.logging.clusterLogging").intValue
    while i < count_i {
        jResp.i = i
        enabled = jResp.int(of: "cluster.logging.clusterLogging[i].enabled").intValue
        j = 0
        count_j = jResp.size(ofArray: "cluster.logging.clusterLogging[i].types").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "cluster.logging.clusterLogging[i].types[j]")
            j = j + 1
        }

        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "cluster.resourcesVpcConfig.publicAccessCidrs").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "cluster.resourcesVpcConfig.publicAccessCidrs[i]")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "cluster.resourcesVpcConfig.securityGroupIds").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "cluster.resourcesVpcConfig.securityGroupIds[i]")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "cluster.resourcesVpcConfig.subnetIds").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "cluster.resourcesVpcConfig.subnetIds[i]")
        i = i + 1
    }

    // A sample JSON response body parsed by the above code:

    // {
    //   "cluster": {
    //     "arn": "string",
    //     "certificateAuthority": {
    //       "data": "string"
    //     },
    //     "clientRequestToken": "string",
    //     "connectorConfig": {
    //       "activationCode": "string",
    //       "activationExpiry": number,
    //       "activationId": "string",
    //       "provider": "string",
    //       "roleArn": "string"
    //     },
    //     "createdAt": number,
    //     "encryptionConfig": [
    //       {
    //         "provider": {
    //           "keyArn": "string"
    //         },
    //         "resources": [
    //           "string"
    //         ]
    //       }
    //     ],
    //     "endpoint": "string",
    //     "identity": {
    //       "oidc": {
    //         "issuer": "string"
    //       }
    //     },
    //     "kubernetesNetworkConfig": {
    //       "ipFamily": "string",
    //       "serviceIpv4Cidr": "string",
    //       "serviceIpv6Cidr": "string"
    //     },
    //     "logging": {
    //       "clusterLogging": [
    //         {
    //           "enabled": boolean,
    //           "types": [
    //             "string"
    //           ]
    //         }
    //       ]
    //     },
    //     "name": "string",
    //     "platformVersion": "string",
    //     "resourcesVpcConfig": {
    //       "clusterSecurityGroupId": "string",
    //       "endpointPrivateAccess": boolean,
    //       "endpointPublicAccess": boolean,
    //       "publicAccessCidrs": [
    //         "string"
    //       ],
    //       "securityGroupIds": [
    //         "string"
    //       ],
    //       "subnetIds": [
    //         "string"
    //       ],
    //       "vpcId": "string"
    //     },
    //     "roleArn": "string",
    //     "status": "string",
    //     "tags": {
    //       "string": "string"
    //     },
    //     "version": "string"
    //   }
    // }

}