Chilkat Online Tools

GetDistributionConfiguration Swift3 Example

EC2 Image Builder

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

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

    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestNoBodySb("GET", uriPath: "/GetDistributionConfiguration", 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 AmiTagsString: String?
    var amiDistributionConfigurationDescription: String?
    var KmsKeyId: String?
    var amiDistributionConfigurationName: String?
    var containerDistributionConfigurationDescription: String?
    var RepositoryName: String?
    var Service: String?
    var region: String?
    var DiskImageFormat: String?
    var RoleName: String?
    var S3Bucket: String?
    var S3Prefix: String?
    var j: Int
    var count_j: Int
    var strVal: String?
    var accountId: String?
    var enabled: Int
    var LaunchTemplateId: String?
    var LaunchTemplateName: String?
    var LaunchTemplateVersion: String?
    var maxParallelLaunches: Int
    var TargetResourceCount: Int
    var launchTemplateId: String?
    var setDefaultVersion: Int

    var Arn: String? = jResp.string(of: "distributionConfiguration.arn")
    var DateCreated: String? = jResp.string(of: "distributionConfiguration.dateCreated")
    var DateUpdated: String? = jResp.string(of: "distributionConfiguration.dateUpdated")
    var Description: String? = jResp.string(of: "distributionConfiguration.description")
    var Name: String? = jResp.string(of: "distributionConfiguration.name")
    var v_String: String? = jResp.string(of: "distributionConfiguration.tags.string")
    var TimeoutMinutes: Int = jResp.int(of: "distributionConfiguration.timeoutMinutes").intValue
    var requestId: String? = jResp.string(of: "requestId")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "distributionConfiguration.distributions").intValue
    while i < count_i {
        jResp.i = i
        AmiTagsString = jResp.string(of: "distributionConfiguration.distributions[i].amiDistributionConfiguration.amiTags.string")
        amiDistributionConfigurationDescription = jResp.string(of: "distributionConfiguration.distributions[i].amiDistributionConfiguration.description")
        KmsKeyId = jResp.string(of: "distributionConfiguration.distributions[i].amiDistributionConfiguration.kmsKeyId")
        amiDistributionConfigurationName = jResp.string(of: "distributionConfiguration.distributions[i].amiDistributionConfiguration.name")
        containerDistributionConfigurationDescription = jResp.string(of: "distributionConfiguration.distributions[i].containerDistributionConfiguration.description")
        RepositoryName = jResp.string(of: "distributionConfiguration.distributions[i].containerDistributionConfiguration.targetRepository.repositoryName")
        Service = jResp.string(of: "distributionConfiguration.distributions[i].containerDistributionConfiguration.targetRepository.service")
        region = jResp.string(of: "distributionConfiguration.distributions[i].region")
        DiskImageFormat = jResp.string(of: "distributionConfiguration.distributions[i].s3ExportConfiguration.diskImageFormat")
        RoleName = jResp.string(of: "distributionConfiguration.distributions[i].s3ExportConfiguration.roleName")
        S3Bucket = jResp.string(of: "distributionConfiguration.distributions[i].s3ExportConfiguration.s3Bucket")
        S3Prefix = jResp.string(of: "distributionConfiguration.distributions[i].s3ExportConfiguration.s3Prefix")
        j = 0
        count_j = jResp.size(ofArray: "distributionConfiguration.distributions[i].amiDistributionConfiguration.launchPermission.organizationalUnitArns").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "distributionConfiguration.distributions[i].amiDistributionConfiguration.launchPermission.organizationalUnitArns[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "distributionConfiguration.distributions[i].amiDistributionConfiguration.launchPermission.organizationArns").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "distributionConfiguration.distributions[i].amiDistributionConfiguration.launchPermission.organizationArns[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "distributionConfiguration.distributions[i].amiDistributionConfiguration.launchPermission.userGroups").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "distributionConfiguration.distributions[i].amiDistributionConfiguration.launchPermission.userGroups[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "distributionConfiguration.distributions[i].amiDistributionConfiguration.launchPermission.userIds").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "distributionConfiguration.distributions[i].amiDistributionConfiguration.launchPermission.userIds[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "distributionConfiguration.distributions[i].amiDistributionConfiguration.targetAccountIds").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "distributionConfiguration.distributions[i].amiDistributionConfiguration.targetAccountIds[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "distributionConfiguration.distributions[i].containerDistributionConfiguration.containerTags").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "distributionConfiguration.distributions[i].containerDistributionConfiguration.containerTags[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "distributionConfiguration.distributions[i].fastLaunchConfigurations").intValue
        while j < count_j {
            jResp.j = j
            accountId = jResp.string(of: "distributionConfiguration.distributions[i].fastLaunchConfigurations[j].accountId")
            enabled = jResp.int(of: "distributionConfiguration.distributions[i].fastLaunchConfigurations[j].enabled").intValue
            LaunchTemplateId = jResp.string(of: "distributionConfiguration.distributions[i].fastLaunchConfigurations[j].launchTemplate.launchTemplateId")
            LaunchTemplateName = jResp.string(of: "distributionConfiguration.distributions[i].fastLaunchConfigurations[j].launchTemplate.launchTemplateName")
            LaunchTemplateVersion = jResp.string(of: "distributionConfiguration.distributions[i].fastLaunchConfigurations[j].launchTemplate.launchTemplateVersion")
            maxParallelLaunches = jResp.int(of: "distributionConfiguration.distributions[i].fastLaunchConfigurations[j].maxParallelLaunches").intValue
            TargetResourceCount = jResp.int(of: "distributionConfiguration.distributions[i].fastLaunchConfigurations[j].snapshotConfiguration.targetResourceCount").intValue
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "distributionConfiguration.distributions[i].launchTemplateConfigurations").intValue
        while j < count_j {
            jResp.j = j
            accountId = jResp.string(of: "distributionConfiguration.distributions[i].launchTemplateConfigurations[j].accountId")
            launchTemplateId = jResp.string(of: "distributionConfiguration.distributions[i].launchTemplateConfigurations[j].launchTemplateId")
            setDefaultVersion = jResp.int(of: "distributionConfiguration.distributions[i].launchTemplateConfigurations[j].setDefaultVersion").intValue
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "distributionConfiguration.distributions[i].licenseConfigurationArns").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "distributionConfiguration.distributions[i].licenseConfigurationArns[j]")
            j = j + 1
        }

        i = i + 1
    }

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

    // {
    //   "distributionConfiguration": {
    //     "arn": "string",
    //     "dateCreated": "string",
    //     "dateUpdated": "string",
    //     "description": "string",
    //     "distributions": [
    //       {
    //         "amiDistributionConfiguration": {
    //           "amiTags": {
    //             "string": "string"
    //           },
    //           "description": "string",
    //           "kmsKeyId": "string",
    //           "launchPermission": {
    //             "organizationalUnitArns": [
    //               "string"
    //             ],
    //             "organizationArns": [
    //               "string"
    //             ],
    //             "userGroups": [
    //               "string"
    //             ],
    //             "userIds": [
    //               "string"
    //             ]
    //           },
    //           "name": "string",
    //           "targetAccountIds": [
    //             "string"
    //           ]
    //         },
    //         "containerDistributionConfiguration": {
    //           "containerTags": [
    //             "string"
    //           ],
    //           "description": "string",
    //           "targetRepository": {
    //             "repositoryName": "string",
    //             "service": "string"
    //           }
    //         },
    //         "fastLaunchConfigurations": [
    //           {
    //             "accountId": "string",
    //             "enabled": boolean,
    //             "launchTemplate": {
    //               "launchTemplateId": "string",
    //               "launchTemplateName": "string",
    //               "launchTemplateVersion": "string"
    //             },
    //             "maxParallelLaunches": number,
    //             "snapshotConfiguration": {
    //               "targetResourceCount": number
    //             }
    //           }
    //         ],
    //         "launchTemplateConfigurations": [
    //           {
    //             "accountId": "string",
    //             "launchTemplateId": "string",
    //             "setDefaultVersion": boolean
    //           }
    //         ],
    //         "licenseConfigurationArns": [
    //           "string"
    //         ],
    //         "region": "string",
    //         "s3ExportConfiguration": {
    //           "diskImageFormat": "string",
    //           "roleName": "string",
    //           "s3Bucket": "string",
    //           "s3Prefix": "string"
    //         }
    //       }
    //     ],
    //     "name": "string",
    //     "tags": {
    //       "string": "string"
    //     },
    //     "timeoutMinutes": number
    //   },
    //   "requestId": "string"
    // }

}