Chilkat Online Tools

StopBuild Swift3 Example

AWS CodeBuild

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 = "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", 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.update("id", value: "string")

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

    // {
    //   "id": "string"
    // }

    rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
    rest.addHeader("X-Amz-Target", value: "CodeBuild_20161006.StopBuild")

    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 strVal: String?
    var name: String?
    var v_type: String?
    var value: String?
    var identifier: String?
    var location: String?
    var mountOptions: String?
    var mountPoint: String?
    var durationInSeconds: Int
    var endTime: Int
    var phaseStatus: String?
    var phaseType: String?
    var startTime: Int
    var j: Int
    var count_j: Int
    var message: String?
    var statusCode: String?
    var artifactIdentifier: String?
    var bucketOwnerAccess: String?
    var encryptionDisabled: Int
    var md5sum: String?
    var overrideArtifactName: Int
    var sha256sum: String?
    var authResource: String?
    var authType: String?
    var buildspec: String?
    var buildStatusConfigContext: String?
    var buildStatusConfigTargetUrl: String?
    var gitCloneDepth: Int
    var gitSubmodulesConfigFetchSubmodules: Int
    var insecureSsl: Int
    var reportBuildStatus: Int
    var sourceIdentifier: String?
    var sourceVersion: String?

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

    i = 0
    count_i = jResp.size(ofArray: "build.environment.environmentVariables").intValue
    while i < count_i {
        jResp.i = i
        name = jResp.string(of: "build.environment.environmentVariables[i].name")
        v_type = jResp.string(of: "build.environment.environmentVariables[i].type")
        value = jResp.string(of: "build.environment.environmentVariables[i].value")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "build.exportedEnvironmentVariables").intValue
    while i < count_i {
        jResp.i = i
        name = jResp.string(of: "build.exportedEnvironmentVariables[i].name")
        value = jResp.string(of: "build.exportedEnvironmentVariables[i].value")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "build.fileSystemLocations").intValue
    while i < count_i {
        jResp.i = i
        identifier = jResp.string(of: "build.fileSystemLocations[i].identifier")
        location = jResp.string(of: "build.fileSystemLocations[i].location")
        mountOptions = jResp.string(of: "build.fileSystemLocations[i].mountOptions")
        mountPoint = jResp.string(of: "build.fileSystemLocations[i].mountPoint")
        v_type = jResp.string(of: "build.fileSystemLocations[i].type")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "build.phases").intValue
    while i < count_i {
        jResp.i = i
        durationInSeconds = jResp.int(of: "build.phases[i].durationInSeconds").intValue
        endTime = jResp.int(of: "build.phases[i].endTime").intValue
        phaseStatus = jResp.string(of: "build.phases[i].phaseStatus")
        phaseType = jResp.string(of: "build.phases[i].phaseType")
        startTime = jResp.int(of: "build.phases[i].startTime").intValue
        j = 0
        count_j = jResp.size(ofArray: "build.phases[i].contexts").intValue
        while j < count_j {
            jResp.j = j
            message = jResp.string(of: "build.phases[i].contexts[j].message")
            statusCode = jResp.string(of: "build.phases[i].contexts[j].statusCode")
            j = j + 1
        }

        i = i + 1
    }

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

    i = 0
    count_i = jResp.size(ofArray: "build.secondaryArtifacts").intValue
    while i < count_i {
        jResp.i = i
        artifactIdentifier = jResp.string(of: "build.secondaryArtifacts[i].artifactIdentifier")
        bucketOwnerAccess = jResp.string(of: "build.secondaryArtifacts[i].bucketOwnerAccess")
        encryptionDisabled = jResp.int(of: "build.secondaryArtifacts[i].encryptionDisabled").intValue
        location = jResp.string(of: "build.secondaryArtifacts[i].location")
        md5sum = jResp.string(of: "build.secondaryArtifacts[i].md5sum")
        overrideArtifactName = jResp.int(of: "build.secondaryArtifacts[i].overrideArtifactName").intValue
        sha256sum = jResp.string(of: "build.secondaryArtifacts[i].sha256sum")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "build.secondarySources").intValue
    while i < count_i {
        jResp.i = i
        authResource = jResp.string(of: "build.secondarySources[i].auth.resource")
        authType = jResp.string(of: "build.secondarySources[i].auth.type")
        buildspec = jResp.string(of: "build.secondarySources[i].buildspec")
        buildStatusConfigContext = jResp.string(of: "build.secondarySources[i].buildStatusConfig.context")
        buildStatusConfigTargetUrl = jResp.string(of: "build.secondarySources[i].buildStatusConfig.targetUrl")
        gitCloneDepth = jResp.int(of: "build.secondarySources[i].gitCloneDepth").intValue
        gitSubmodulesConfigFetchSubmodules = jResp.int(of: "build.secondarySources[i].gitSubmodulesConfig.fetchSubmodules").intValue
        insecureSsl = jResp.int(of: "build.secondarySources[i].insecureSsl").intValue
        location = jResp.string(of: "build.secondarySources[i].location")
        reportBuildStatus = jResp.int(of: "build.secondarySources[i].reportBuildStatus").intValue
        sourceIdentifier = jResp.string(of: "build.secondarySources[i].sourceIdentifier")
        v_type = jResp.string(of: "build.secondarySources[i].type")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "build.secondarySourceVersions").intValue
    while i < count_i {
        jResp.i = i
        sourceIdentifier = jResp.string(of: "build.secondarySourceVersions[i].sourceIdentifier")
        sourceVersion = jResp.string(of: "build.secondarySourceVersions[i].sourceVersion")
        i = i + 1
    }

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

    i = 0
    count_i = jResp.size(ofArray: "build.vpcConfig.subnets").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "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"
    //     }
    //   }
    // }

}