Chilkat Online Tools

RetryBuild C++ Example

AWS CodeBuild

#include <CkRest.h>
#include <CkAuthAws.h>
#include <CkJsonObject.h>
#include <CkStringBuilder.h>

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

    CkRest rest;
    bool success;

    CkAuthAws authAws;
    authAws.put_AccessKey("AWS_ACCESS_KEY");
    authAws.put_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.put_Region("us-west-2");
    authAws.put_ServiceName("codebuild");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://codebuild.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect("codebuild.us-west-2.amazonaws.com",443,true,true);
    if (success != true) {
        std::cout << "ConnectFailReason: " << rest.get_ConnectFailReason() << "\r\n";
        std::cout << rest.lastErrorText() << "\r\n";
        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

    CkJsonObject json;
    json.UpdateString("id","string");
    json.UpdateString("idempotencyToken","string");

    // The JSON request body created by the above code:

    // {
    //   "id": "string",
    //   "idempotencyToken": "string"
    // }

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

    CkStringBuilder sbRequestBody;
    json.EmitSb(sbRequestBody);
    CkStringBuilder sbResponseBody;
    success = rest.FullRequestSb("POST","/",sbRequestBody,sbResponseBody);
    if (success != true) {
        std::cout << rest.lastErrorText() << "\r\n";
        return;
    }

    int respStatusCode = rest.get_ResponseStatusCode();
    std::cout << "response status code = " << respStatusCode << "\r\n";
    if (respStatusCode != 200) {
        std::cout << "Response Header:" << "\r\n";
        std::cout << rest.responseHeader() << "\r\n";
        std::cout << "Response Body:" << "\r\n";
        std::cout << sbResponseBody.getAsString() << "\r\n";
        return;
    }

    CkJsonObject 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 char *strVal = 0;
    const char *name = 0;
    const char *v_type = 0;
    const char *value = 0;
    const char *identifier = 0;
    const char *location = 0;
    const char *mountOptions = 0;
    const char *mountPoint = 0;
    int durationInSeconds;
    int endTime;
    const char *phaseStatus = 0;
    const char *phaseType = 0;
    int startTime;
    int j;
    int count_j;
    const char *message = 0;
    const char *statusCode = 0;
    const char *artifactIdentifier = 0;
    const char *bucketOwnerAccess = 0;
    int encryptionDisabled;
    const char *md5sum = 0;
    int overrideArtifactName;
    const char *sha256sum = 0;
    const char *authResource = 0;
    const char *authType = 0;
    const char *buildspec = 0;
    const char *buildStatusConfigContext = 0;
    const char *buildStatusConfigTargetUrl = 0;
    int gitCloneDepth;
    int gitSubmodulesConfigFetchSubmodules;
    int insecureSsl;
    int reportBuildStatus;
    const char *sourceIdentifier = 0;
    const char *sourceVersion = 0;

    const char *Arn = jResp.stringOf("build.arn");
    const char *ArtifactIdentifier = jResp.stringOf("build.artifacts.artifactIdentifier");
    const char *BucketOwnerAccess = jResp.stringOf("build.artifacts.bucketOwnerAccess");
    int EncryptionDisabled = jResp.IntOf("build.artifacts.encryptionDisabled");
    const char *Location = jResp.stringOf("build.artifacts.location");
    const char *Md5sum = jResp.stringOf("build.artifacts.md5sum");
    int OverrideArtifactName = jResp.IntOf("build.artifacts.overrideArtifactName");
    const char *Sha256sum = jResp.stringOf("build.artifacts.sha256sum");
    const char *BuildBatchArn = jResp.stringOf("build.buildBatchArn");
    int BuildComplete = jResp.IntOf("build.buildComplete");
    int BuildNumber = jResp.IntOf("build.buildNumber");
    const char *BuildStatus = jResp.stringOf("build.buildStatus");
    const char *CacheLocation = jResp.stringOf("build.cache.location");
    const char *v_Type = jResp.stringOf("build.cache.type");
    const char *CurrentPhase = jResp.stringOf("build.currentPhase");
    int SessionEnabled = jResp.IntOf("build.debugSession.sessionEnabled");
    const char *SessionTarget = jResp.stringOf("build.debugSession.sessionTarget");
    const char *EncryptionKey = jResp.stringOf("build.encryptionKey");
    int EndTime = jResp.IntOf("build.endTime");
    const char *Certificate = jResp.stringOf("build.environment.certificate");
    const char *ComputeType = jResp.stringOf("build.environment.computeType");
    const char *Image = jResp.stringOf("build.environment.image");
    const char *ImagePullCredentialsType = jResp.stringOf("build.environment.imagePullCredentialsType");
    int PrivilegedMode = jResp.IntOf("build.environment.privilegedMode");
    const char *Credential = jResp.stringOf("build.environment.registryCredential.credential");
    const char *CredentialProvider = jResp.stringOf("build.environment.registryCredential.credentialProvider");
    const char *EnvironmentType = jResp.stringOf("build.environment.type");
    const char *Id = jResp.stringOf("build.id");
    const char *Initiator = jResp.stringOf("build.initiator");
    const char *GroupName = jResp.stringOf("build.logs.cloudWatchLogs.groupName");
    const char *Status = jResp.stringOf("build.logs.cloudWatchLogs.status");
    const char *StreamName = jResp.stringOf("build.logs.cloudWatchLogs.streamName");
    const char *CloudWatchLogsArn = jResp.stringOf("build.logs.cloudWatchLogsArn");
    const char *DeepLink = jResp.stringOf("build.logs.deepLink");
    const char *LogsGroupName = jResp.stringOf("build.logs.groupName");
    const char *S3DeepLink = jResp.stringOf("build.logs.s3DeepLink");
    const char *S3LogsBucketOwnerAccess = jResp.stringOf("build.logs.s3Logs.bucketOwnerAccess");
    int S3LogsEncryptionDisabled = jResp.IntOf("build.logs.s3Logs.encryptionDisabled");
    const char *S3LogsLocation = jResp.stringOf("build.logs.s3Logs.location");
    const char *S3LogsStatus = jResp.stringOf("build.logs.s3Logs.status");
    const char *S3LogsArn = jResp.stringOf("build.logs.s3LogsArn");
    const char *LogsStreamName = jResp.stringOf("build.logs.streamName");
    const char *NetworkInterfaceId = jResp.stringOf("build.networkInterface.networkInterfaceId");
    const char *SubnetId = jResp.stringOf("build.networkInterface.subnetId");
    const char *ProjectName = jResp.stringOf("build.projectName");
    int QueuedTimeoutInMinutes = jResp.IntOf("build.queuedTimeoutInMinutes");
    const char *ResolvedSourceVersion = jResp.stringOf("build.resolvedSourceVersion");
    const char *ServiceRole = jResp.stringOf("build.serviceRole");
    const char *Resource = jResp.stringOf("build.source.auth.resource");
    const char *AuthType = jResp.stringOf("build.source.auth.type");
    const char *Buildspec = jResp.stringOf("build.source.buildspec");
    const char *Context = jResp.stringOf("build.source.buildStatusConfig.context");
    const char *TargetUrl = jResp.stringOf("build.source.buildStatusConfig.targetUrl");
    int GitCloneDepth = jResp.IntOf("build.source.gitCloneDepth");
    int FetchSubmodules = jResp.IntOf("build.source.gitSubmodulesConfig.fetchSubmodules");
    int InsecureSsl = jResp.IntOf("build.source.insecureSsl");
    const char *SourceLocation = jResp.stringOf("build.source.location");
    int ReportBuildStatus = jResp.IntOf("build.source.reportBuildStatus");
    const char *SourceIdentifier = jResp.stringOf("build.source.sourceIdentifier");
    const char *SourceType = jResp.stringOf("build.source.type");
    const char *SourceVersion = jResp.stringOf("build.sourceVersion");
    int StartTime = jResp.IntOf("build.startTime");
    int TimeoutInMinutes = jResp.IntOf("build.timeoutInMinutes");
    const char *VpcId = jResp.stringOf("build.vpcConfig.vpcId");
    int i = 0;
    int count_i = jResp.SizeOfArray("build.cache.modes");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("build.cache.modes[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray("build.environment.environmentVariables");
    while (i < count_i) {
        jResp.put_I(i);
        name = jResp.stringOf("build.environment.environmentVariables[i].name");
        v_type = jResp.stringOf("build.environment.environmentVariables[i].type");
        value = jResp.stringOf("build.environment.environmentVariables[i].value");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray("build.exportedEnvironmentVariables");
    while (i < count_i) {
        jResp.put_I(i);
        name = jResp.stringOf("build.exportedEnvironmentVariables[i].name");
        value = jResp.stringOf("build.exportedEnvironmentVariables[i].value");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray("build.fileSystemLocations");
    while (i < count_i) {
        jResp.put_I(i);
        identifier = jResp.stringOf("build.fileSystemLocations[i].identifier");
        location = jResp.stringOf("build.fileSystemLocations[i].location");
        mountOptions = jResp.stringOf("build.fileSystemLocations[i].mountOptions");
        mountPoint = jResp.stringOf("build.fileSystemLocations[i].mountPoint");
        v_type = jResp.stringOf("build.fileSystemLocations[i].type");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray("build.phases");
    while (i < count_i) {
        jResp.put_I(i);
        durationInSeconds = jResp.IntOf("build.phases[i].durationInSeconds");
        endTime = jResp.IntOf("build.phases[i].endTime");
        phaseStatus = jResp.stringOf("build.phases[i].phaseStatus");
        phaseType = jResp.stringOf("build.phases[i].phaseType");
        startTime = jResp.IntOf("build.phases[i].startTime");
        j = 0;
        count_j = jResp.SizeOfArray("build.phases[i].contexts");
        while (j < count_j) {
            jResp.put_J(j);
            message = jResp.stringOf("build.phases[i].contexts[j].message");
            statusCode = jResp.stringOf("build.phases[i].contexts[j].statusCode");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray("build.reportArns");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("build.reportArns[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray("build.secondaryArtifacts");
    while (i < count_i) {
        jResp.put_I(i);
        artifactIdentifier = jResp.stringOf("build.secondaryArtifacts[i].artifactIdentifier");
        bucketOwnerAccess = jResp.stringOf("build.secondaryArtifacts[i].bucketOwnerAccess");
        encryptionDisabled = jResp.IntOf("build.secondaryArtifacts[i].encryptionDisabled");
        location = jResp.stringOf("build.secondaryArtifacts[i].location");
        md5sum = jResp.stringOf("build.secondaryArtifacts[i].md5sum");
        overrideArtifactName = jResp.IntOf("build.secondaryArtifacts[i].overrideArtifactName");
        sha256sum = jResp.stringOf("build.secondaryArtifacts[i].sha256sum");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray("build.secondarySources");
    while (i < count_i) {
        jResp.put_I(i);
        authResource = jResp.stringOf("build.secondarySources[i].auth.resource");
        authType = jResp.stringOf("build.secondarySources[i].auth.type");
        buildspec = jResp.stringOf("build.secondarySources[i].buildspec");
        buildStatusConfigContext = jResp.stringOf("build.secondarySources[i].buildStatusConfig.context");
        buildStatusConfigTargetUrl = jResp.stringOf("build.secondarySources[i].buildStatusConfig.targetUrl");
        gitCloneDepth = jResp.IntOf("build.secondarySources[i].gitCloneDepth");
        gitSubmodulesConfigFetchSubmodules = jResp.IntOf("build.secondarySources[i].gitSubmodulesConfig.fetchSubmodules");
        insecureSsl = jResp.IntOf("build.secondarySources[i].insecureSsl");
        location = jResp.stringOf("build.secondarySources[i].location");
        reportBuildStatus = jResp.IntOf("build.secondarySources[i].reportBuildStatus");
        sourceIdentifier = jResp.stringOf("build.secondarySources[i].sourceIdentifier");
        v_type = jResp.stringOf("build.secondarySources[i].type");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray("build.secondarySourceVersions");
    while (i < count_i) {
        jResp.put_I(i);
        sourceIdentifier = jResp.stringOf("build.secondarySourceVersions[i].sourceIdentifier");
        sourceVersion = jResp.stringOf("build.secondarySourceVersions[i].sourceVersion");
        i = i + 1;
    }

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

    i = 0;
    count_i = jResp.SizeOfArray("build.vpcConfig.subnets");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("build.vpcConfig.subnets[i]");
        i = i + 1;
    }

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

    // {
    //   "build": {
    //     "arn": "string",
    //     "artifacts": {
    //       "artifactIdentifier": "string",
    //       "bucketOwnerAccess": "string",
    //       "encryptionDisabled": boolean,
    //       "location": "string",
    //       "md5sum": "string",
    //       "overrideArtifactName": boolean,
    //       "sha256sum": "string"
    //     },
    //     "buildBatchArn": "string",
    //     "buildComplete": boolean,
    //     "buildNumber": number,
    //     "buildStatus": "string",
    //     "cache": {
    //       "location": "string",
    //       "modes": [
    //         "string"
    //       ],
    //       "type": "string"
    //     },
    //     "currentPhase": "string",
    //     "debugSession": {
    //       "sessionEnabled": boolean,
    //       "sessionTarget": "string"
    //     },
    //     "encryptionKey": "string",
    //     "endTime": number,
    //     "environment": {
    //       "certificate": "string",
    //       "computeType": "string",
    //       "environmentVariables": [
    //         {
    //           "name": "string",
    //           "type": "string",
    //           "value": "string"
    //         }
    //       ],
    //       "image": "string",
    //       "imagePullCredentialsType": "string",
    //       "privilegedMode": boolean,
    //       "registryCredential": {
    //         "credential": "string",
    //         "credentialProvider": "string"
    //       },
    //       "type": "string"
    //     },
    //     "exportedEnvironmentVariables": [
    //       {
    //         "name": "string",
    //         "value": "string"
    //       }
    //     ],
    //     "fileSystemLocations": [
    //       {
    //         "identifier": "string",
    //         "location": "string",
    //         "mountOptions": "string",
    //         "mountPoint": "string",
    //         "type": "string"
    //       }
    //     ],
    //     "id": "string",
    //     "initiator": "string",
    //     "logs": {
    //       "cloudWatchLogs": {
    //         "groupName": "string",
    //         "status": "string",
    //         "streamName": "string"
    //       },
    //       "cloudWatchLogsArn": "string",
    //       "deepLink": "string",
    //       "groupName": "string",
    //       "s3DeepLink": "string",
    //       "s3Logs": {
    //         "bucketOwnerAccess": "string",
    //         "encryptionDisabled": boolean,
    //         "location": "string",
    //         "status": "string"
    //       },
    //       "s3LogsArn": "string",
    //       "streamName": "string"
    //     },
    //     "networkInterface": {
    //       "networkInterfaceId": "string",
    //       "subnetId": "string"
    //     },
    //     "phases": [
    //       {
    //         "contexts": [
    //           {
    //             "message": "string",
    //             "statusCode": "string"
    //           }
    //         ],
    //         "durationInSeconds": number,
    //         "endTime": number,
    //         "phaseStatus": "string",
    //         "phaseType": "string",
    //         "startTime": number
    //       }
    //     ],
    //     "projectName": "string",
    //     "queuedTimeoutInMinutes": number,
    //     "reportArns": [
    //       "string"
    //     ],
    //     "resolvedSourceVersion": "string",
    //     "secondaryArtifacts": [
    //       {
    //         "artifactIdentifier": "string",
    //         "bucketOwnerAccess": "string",
    //         "encryptionDisabled": boolean,
    //         "location": "string",
    //         "md5sum": "string",
    //         "overrideArtifactName": boolean,
    //         "sha256sum": "string"
    //       }
    //     ],
    //     "secondarySources": [
    //       {
    //         "auth": {
    //           "resource": "string",
    //           "type": "string"
    //         },
    //         "buildspec": "string",
    //         "buildStatusConfig": {
    //           "context": "string",
    //           "targetUrl": "string"
    //         },
    //         "gitCloneDepth": number,
    //         "gitSubmodulesConfig": {
    //           "fetchSubmodules": boolean
    //         },
    //         "insecureSsl": boolean,
    //         "location": "string",
    //         "reportBuildStatus": boolean,
    //         "sourceIdentifier": "string",
    //         "type": "string"
    //       }
    //     ],
    //     "secondarySourceVersions": [
    //       {
    //         "sourceIdentifier": "string",
    //         "sourceVersion": "string"
    //       }
    //     ],
    //     "serviceRole": "string",
    //     "source": {
    //       "auth": {
    //         "resource": "string",
    //         "type": "string"
    //       },
    //       "buildspec": "string",
    //       "buildStatusConfig": {
    //         "context": "string",
    //         "targetUrl": "string"
    //       },
    //       "gitCloneDepth": number,
    //       "gitSubmodulesConfig": {
    //         "fetchSubmodules": boolean
    //       },
    //       "insecureSsl": boolean,
    //       "location": "string",
    //       "reportBuildStatus": boolean,
    //       "sourceIdentifier": "string",
    //       "type": "string"
    //     },
    //     "sourceVersion": "string",
    //     "startTime": number,
    //     "timeoutInMinutes": number,
    //     "vpcConfig": {
    //       "securityGroupIds": [
    //         "string"
    //       ],
    //       "subnets": [
    //         "string"
    //       ],
    //       "vpcId": "string"
    //     }
    //   }
    // }
    }