Chilkat Online Tools

DeregisterCluster unicodeCpp Example

Amazon Elastic Kubernetes Service

#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkRestW rest;
    bool success;

    CkAuthAwsW authAws;
    authAws.put_AccessKey(L"AWS_ACCESS_KEY");
    authAws.put_SecretKey(L"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.put_Region(L"us-west-2");
    authAws.put_ServiceName(L"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(L"eks.us-west-2.amazonaws.com",443,true,true);
    if (success != true) {
        wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    rest.AddHeader(L"Content-Type",L"application/x-amz-json-1.1");
    rest.AddHeader(L"X-Amz-Target",L"DeregisterCluster");

    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestNoBodySb(L"DELETE",L"/cluster-registrations/{name}",sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    int respStatusCode = rest.get_ResponseStatusCode();
    wprintf(L"response status code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",rest.responseHeader());
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",sbResponseBody.getAsString());
        return;
    }

    CkJsonObjectW jResp;
    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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

    const wchar_t *KeyArn = 0;
    int j;
    int count_j;
    const wchar_t *strVal = 0;
    int enabled;

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

        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"cluster.logging.clusterLogging");
    while (i < count_i) {
        jResp.put_I(i);
        enabled = jResp.IntOf(L"cluster.logging.clusterLogging[i].enabled");
        j = 0;
        count_j = jResp.SizeOfArray(L"cluster.logging.clusterLogging[i].types");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(L"cluster.logging.clusterLogging[i].types[j]");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"cluster.resourcesVpcConfig.publicAccessCidrs");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"cluster.resourcesVpcConfig.publicAccessCidrs[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"cluster.resourcesVpcConfig.securityGroupIds");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"cluster.resourcesVpcConfig.securityGroupIds[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"cluster.resourcesVpcConfig.subnetIds");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"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"
    //   }
    // }
    }