StopBuild C Example
#include <C_CkRest.h>
#include <C_CkAuthAws.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
HCkRest rest;
BOOL success;
HCkAuthAws authAws;
HCkJsonObject json;
HCkStringBuilder sbRequestBody;
HCkStringBuilder sbResponseBody;
int respStatusCode;
HCkJsonObject jResp;
const char *strVal;
const char *name;
const char *v_type;
const char *value;
const char *identifier;
const char *location;
const char *mountOptions;
const char *mountPoint;
int durationInSeconds;
int endTime;
const char *phaseStatus;
const char *phaseType;
int startTime;
int j;
int count_j;
const char *message;
const char *statusCode;
const char *artifactIdentifier;
const char *bucketOwnerAccess;
int encryptionDisabled;
const char *md5sum;
int overrideArtifactName;
const char *sha256sum;
const char *authResource;
const char *authType;
const char *buildspec;
const char *buildStatusConfigContext;
const char *buildStatusConfigTargetUrl;
int gitCloneDepth;
int gitSubmodulesConfigFetchSubmodules;
int insecureSsl;
int reportBuildStatus;
const char *sourceIdentifier;
const char *sourceVersion;
const char *Arn;
const char *ArtifactIdentifier;
const char *BucketOwnerAccess;
int EncryptionDisabled;
const char *Location;
const char *Md5sum;
int OverrideArtifactName;
const char *Sha256sum;
const char *BuildBatchArn;
int BuildComplete;
int BuildNumber;
const char *BuildStatus;
const char *CacheLocation;
const char *v_Type;
const char *CurrentPhase;
int SessionEnabled;
const char *SessionTarget;
const char *EncryptionKey;
int EndTime;
const char *Certificate;
const char *ComputeType;
const char *Image;
const char *ImagePullCredentialsType;
int PrivilegedMode;
const char *Credential;
const char *CredentialProvider;
const char *EnvironmentType;
const char *Id;
const char *Initiator;
const char *GroupName;
const char *Status;
const char *StreamName;
const char *CloudWatchLogsArn;
const char *DeepLink;
const char *LogsGroupName;
const char *S3DeepLink;
const char *S3LogsBucketOwnerAccess;
int S3LogsEncryptionDisabled;
const char *S3LogsLocation;
const char *S3LogsStatus;
const char *S3LogsArn;
const char *LogsStreamName;
const char *NetworkInterfaceId;
const char *SubnetId;
const char *ProjectName;
int QueuedTimeoutInMinutes;
const char *ResolvedSourceVersion;
const char *ServiceRole;
const char *Resource;
const char *AuthType;
const char *Buildspec;
const char *Context;
const char *TargetUrl;
int GitCloneDepth;
int FetchSubmodules;
int InsecureSsl;
const char *SourceLocation;
int ReportBuildStatus;
const char *SourceIdentifier;
const char *SourceType;
const char *SourceVersion;
int StartTime;
int TimeoutInMinutes;
const char *VpcId;
int i;
int count_i;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest = CkRest_Create();
authAws = CkAuthAws_Create();
CkAuthAws_putAccessKey(authAws,"AWS_ACCESS_KEY");
CkAuthAws_putSecretKey(authAws,"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.)
CkAuthAws_putRegion(authAws,"us-west-2");
CkAuthAws_putServiceName(authAws,"codebuild");
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws(rest,authAws);
// URL: https://codebuild.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = CkRest_Connect(rest,"codebuild.us-west-2.amazonaws.com",443,TRUE,TRUE);
if (success != TRUE) {
printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
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
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"id","string");
// The JSON request body created by the above code:
// {
// "id": "string"
// }
CkRest_AddHeader(rest,"Content-Type","application/x-amz-json-1.1");
CkRest_AddHeader(rest,"X-Amz-Target","CodeBuild_20161006.StopBuild");
sbRequestBody = CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
sbResponseBody = CkStringBuilder_Create();
success = CkRest_FullRequestSb(rest,"POST","/",sbRequestBody,sbResponseBody);
if (success != TRUE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
respStatusCode = CkRest_getResponseStatusCode(rest);
printf("response status code = %d\n",respStatusCode);
if (respStatusCode != 200) {
printf("Response Header:\n");
printf("%s\n",CkRest_responseHeader(rest));
printf("Response Body:\n");
printf("%s\n",CkStringBuilder_getAsString(sbResponseBody));
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,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.
Arn = CkJsonObject_stringOf(jResp,"build.arn");
ArtifactIdentifier = CkJsonObject_stringOf(jResp,"build.artifacts.artifactIdentifier");
BucketOwnerAccess = CkJsonObject_stringOf(jResp,"build.artifacts.bucketOwnerAccess");
EncryptionDisabled = CkJsonObject_IntOf(jResp,"build.artifacts.encryptionDisabled");
Location = CkJsonObject_stringOf(jResp,"build.artifacts.location");
Md5sum = CkJsonObject_stringOf(jResp,"build.artifacts.md5sum");
OverrideArtifactName = CkJsonObject_IntOf(jResp,"build.artifacts.overrideArtifactName");
Sha256sum = CkJsonObject_stringOf(jResp,"build.artifacts.sha256sum");
BuildBatchArn = CkJsonObject_stringOf(jResp,"build.buildBatchArn");
BuildComplete = CkJsonObject_IntOf(jResp,"build.buildComplete");
BuildNumber = CkJsonObject_IntOf(jResp,"build.buildNumber");
BuildStatus = CkJsonObject_stringOf(jResp,"build.buildStatus");
CacheLocation = CkJsonObject_stringOf(jResp,"build.cache.location");
v_Type = CkJsonObject_stringOf(jResp,"build.cache.type");
CurrentPhase = CkJsonObject_stringOf(jResp,"build.currentPhase");
SessionEnabled = CkJsonObject_IntOf(jResp,"build.debugSession.sessionEnabled");
SessionTarget = CkJsonObject_stringOf(jResp,"build.debugSession.sessionTarget");
EncryptionKey = CkJsonObject_stringOf(jResp,"build.encryptionKey");
EndTime = CkJsonObject_IntOf(jResp,"build.endTime");
Certificate = CkJsonObject_stringOf(jResp,"build.environment.certificate");
ComputeType = CkJsonObject_stringOf(jResp,"build.environment.computeType");
Image = CkJsonObject_stringOf(jResp,"build.environment.image");
ImagePullCredentialsType = CkJsonObject_stringOf(jResp,"build.environment.imagePullCredentialsType");
PrivilegedMode = CkJsonObject_IntOf(jResp,"build.environment.privilegedMode");
Credential = CkJsonObject_stringOf(jResp,"build.environment.registryCredential.credential");
CredentialProvider = CkJsonObject_stringOf(jResp,"build.environment.registryCredential.credentialProvider");
EnvironmentType = CkJsonObject_stringOf(jResp,"build.environment.type");
Id = CkJsonObject_stringOf(jResp,"build.id");
Initiator = CkJsonObject_stringOf(jResp,"build.initiator");
GroupName = CkJsonObject_stringOf(jResp,"build.logs.cloudWatchLogs.groupName");
Status = CkJsonObject_stringOf(jResp,"build.logs.cloudWatchLogs.status");
StreamName = CkJsonObject_stringOf(jResp,"build.logs.cloudWatchLogs.streamName");
CloudWatchLogsArn = CkJsonObject_stringOf(jResp,"build.logs.cloudWatchLogsArn");
DeepLink = CkJsonObject_stringOf(jResp,"build.logs.deepLink");
LogsGroupName = CkJsonObject_stringOf(jResp,"build.logs.groupName");
S3DeepLink = CkJsonObject_stringOf(jResp,"build.logs.s3DeepLink");
S3LogsBucketOwnerAccess = CkJsonObject_stringOf(jResp,"build.logs.s3Logs.bucketOwnerAccess");
S3LogsEncryptionDisabled = CkJsonObject_IntOf(jResp,"build.logs.s3Logs.encryptionDisabled");
S3LogsLocation = CkJsonObject_stringOf(jResp,"build.logs.s3Logs.location");
S3LogsStatus = CkJsonObject_stringOf(jResp,"build.logs.s3Logs.status");
S3LogsArn = CkJsonObject_stringOf(jResp,"build.logs.s3LogsArn");
LogsStreamName = CkJsonObject_stringOf(jResp,"build.logs.streamName");
NetworkInterfaceId = CkJsonObject_stringOf(jResp,"build.networkInterface.networkInterfaceId");
SubnetId = CkJsonObject_stringOf(jResp,"build.networkInterface.subnetId");
ProjectName = CkJsonObject_stringOf(jResp,"build.projectName");
QueuedTimeoutInMinutes = CkJsonObject_IntOf(jResp,"build.queuedTimeoutInMinutes");
ResolvedSourceVersion = CkJsonObject_stringOf(jResp,"build.resolvedSourceVersion");
ServiceRole = CkJsonObject_stringOf(jResp,"build.serviceRole");
Resource = CkJsonObject_stringOf(jResp,"build.source.auth.resource");
AuthType = CkJsonObject_stringOf(jResp,"build.source.auth.type");
Buildspec = CkJsonObject_stringOf(jResp,"build.source.buildspec");
Context = CkJsonObject_stringOf(jResp,"build.source.buildStatusConfig.context");
TargetUrl = CkJsonObject_stringOf(jResp,"build.source.buildStatusConfig.targetUrl");
GitCloneDepth = CkJsonObject_IntOf(jResp,"build.source.gitCloneDepth");
FetchSubmodules = CkJsonObject_IntOf(jResp,"build.source.gitSubmodulesConfig.fetchSubmodules");
InsecureSsl = CkJsonObject_IntOf(jResp,"build.source.insecureSsl");
SourceLocation = CkJsonObject_stringOf(jResp,"build.source.location");
ReportBuildStatus = CkJsonObject_IntOf(jResp,"build.source.reportBuildStatus");
SourceIdentifier = CkJsonObject_stringOf(jResp,"build.source.sourceIdentifier");
SourceType = CkJsonObject_stringOf(jResp,"build.source.type");
SourceVersion = CkJsonObject_stringOf(jResp,"build.sourceVersion");
StartTime = CkJsonObject_IntOf(jResp,"build.startTime");
TimeoutInMinutes = CkJsonObject_IntOf(jResp,"build.timeoutInMinutes");
VpcId = CkJsonObject_stringOf(jResp,"build.vpcConfig.vpcId");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"build.cache.modes");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"build.cache.modes[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"build.environment.environmentVariables");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
name = CkJsonObject_stringOf(jResp,"build.environment.environmentVariables[i].name");
v_type = CkJsonObject_stringOf(jResp,"build.environment.environmentVariables[i].type");
value = CkJsonObject_stringOf(jResp,"build.environment.environmentVariables[i].value");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"build.exportedEnvironmentVariables");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
name = CkJsonObject_stringOf(jResp,"build.exportedEnvironmentVariables[i].name");
value = CkJsonObject_stringOf(jResp,"build.exportedEnvironmentVariables[i].value");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"build.fileSystemLocations");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
identifier = CkJsonObject_stringOf(jResp,"build.fileSystemLocations[i].identifier");
location = CkJsonObject_stringOf(jResp,"build.fileSystemLocations[i].location");
mountOptions = CkJsonObject_stringOf(jResp,"build.fileSystemLocations[i].mountOptions");
mountPoint = CkJsonObject_stringOf(jResp,"build.fileSystemLocations[i].mountPoint");
v_type = CkJsonObject_stringOf(jResp,"build.fileSystemLocations[i].type");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"build.phases");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
durationInSeconds = CkJsonObject_IntOf(jResp,"build.phases[i].durationInSeconds");
endTime = CkJsonObject_IntOf(jResp,"build.phases[i].endTime");
phaseStatus = CkJsonObject_stringOf(jResp,"build.phases[i].phaseStatus");
phaseType = CkJsonObject_stringOf(jResp,"build.phases[i].phaseType");
startTime = CkJsonObject_IntOf(jResp,"build.phases[i].startTime");
j = 0;
count_j = CkJsonObject_SizeOfArray(jResp,"build.phases[i].contexts");
while (j < count_j) {
CkJsonObject_putJ(jResp,j);
message = CkJsonObject_stringOf(jResp,"build.phases[i].contexts[j].message");
statusCode = CkJsonObject_stringOf(jResp,"build.phases[i].contexts[j].statusCode");
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"build.reportArns");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"build.reportArns[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"build.secondaryArtifacts");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
artifactIdentifier = CkJsonObject_stringOf(jResp,"build.secondaryArtifacts[i].artifactIdentifier");
bucketOwnerAccess = CkJsonObject_stringOf(jResp,"build.secondaryArtifacts[i].bucketOwnerAccess");
encryptionDisabled = CkJsonObject_IntOf(jResp,"build.secondaryArtifacts[i].encryptionDisabled");
location = CkJsonObject_stringOf(jResp,"build.secondaryArtifacts[i].location");
md5sum = CkJsonObject_stringOf(jResp,"build.secondaryArtifacts[i].md5sum");
overrideArtifactName = CkJsonObject_IntOf(jResp,"build.secondaryArtifacts[i].overrideArtifactName");
sha256sum = CkJsonObject_stringOf(jResp,"build.secondaryArtifacts[i].sha256sum");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"build.secondarySources");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
authResource = CkJsonObject_stringOf(jResp,"build.secondarySources[i].auth.resource");
authType = CkJsonObject_stringOf(jResp,"build.secondarySources[i].auth.type");
buildspec = CkJsonObject_stringOf(jResp,"build.secondarySources[i].buildspec");
buildStatusConfigContext = CkJsonObject_stringOf(jResp,"build.secondarySources[i].buildStatusConfig.context");
buildStatusConfigTargetUrl = CkJsonObject_stringOf(jResp,"build.secondarySources[i].buildStatusConfig.targetUrl");
gitCloneDepth = CkJsonObject_IntOf(jResp,"build.secondarySources[i].gitCloneDepth");
gitSubmodulesConfigFetchSubmodules = CkJsonObject_IntOf(jResp,"build.secondarySources[i].gitSubmodulesConfig.fetchSubmodules");
insecureSsl = CkJsonObject_IntOf(jResp,"build.secondarySources[i].insecureSsl");
location = CkJsonObject_stringOf(jResp,"build.secondarySources[i].location");
reportBuildStatus = CkJsonObject_IntOf(jResp,"build.secondarySources[i].reportBuildStatus");
sourceIdentifier = CkJsonObject_stringOf(jResp,"build.secondarySources[i].sourceIdentifier");
v_type = CkJsonObject_stringOf(jResp,"build.secondarySources[i].type");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"build.secondarySourceVersions");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
sourceIdentifier = CkJsonObject_stringOf(jResp,"build.secondarySourceVersions[i].sourceIdentifier");
sourceVersion = CkJsonObject_stringOf(jResp,"build.secondarySourceVersions[i].sourceVersion");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"build.vpcConfig.securityGroupIds");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"build.vpcConfig.securityGroupIds[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"build.vpcConfig.subnets");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"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"
// }
// }
// }
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}