Chilkat Online Tools

GetLifecyclePolicy Swift3 Example

Amazon Data Lifecycle Manager

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

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

    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestNoBodySb("GET", uriPath: "/policies/{policyId}/", 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 Name: String?
    var j: Int
    var count_j: Int
    var CmkArn: String?
    var Encrypted: Int
    var Interval: Int
    var IntervalUnit: String?
    var Target: String?
    var strVal: String?
    var CopyTags: Int
    var CronExpression: String?
    var CreateRuleInterval: Int
    var CreateRuleIntervalUnit: String?
    var Location: String?
    var Count: Int
    var DeprecateRuleInterval: Int
    var DeprecateRuleIntervalUnit: String?
    var FastRestoreRuleCount: Int
    var FastRestoreRuleInterval: Int
    var FastRestoreRuleIntervalUnit: String?
    var RetainRuleCount: Int
    var RetainRuleInterval: Int
    var RetainRuleIntervalUnit: String?
    var TargetRegion: String?
    var UnshareInterval: Int
    var UnshareIntervalUnit: String?
    var k: Int
    var count_k: Int
    var Key: String?
    var Value: String?

    var DateCreated: Int = jResp.int(of: "Policy.DateCreated").intValue
    var DateModified: Int = jResp.int(of: "Policy.DateModified").intValue
    var Description: String? = jResp.string(of: "Policy.Description")
    var ExecutionRoleArn: String? = jResp.string(of: "Policy.ExecutionRoleArn")
    var PolicyArn: String? = jResp.string(of: "Policy.PolicyArn")
    var DescriptionRegex: String? = jResp.string(of: "Policy.PolicyDetails.EventSource.Parameters.DescriptionRegex")
    var EventType: String? = jResp.string(of: "Policy.PolicyDetails.EventSource.Parameters.EventType")
    var v_Type: String? = jResp.string(of: "Policy.PolicyDetails.EventSource.Type")
    var ExcludeBootVolume: Int = jResp.int(of: "Policy.PolicyDetails.Parameters.ExcludeBootVolume").intValue
    var NoReboot: Int = jResp.int(of: "Policy.PolicyDetails.Parameters.NoReboot").intValue
    var PolicyType: String? = jResp.string(of: "Policy.PolicyDetails.PolicyType")
    var PolicyId: String? = jResp.string(of: "Policy.PolicyId")
    var State: String? = jResp.string(of: "Policy.State")
    var StatusMessage: String? = jResp.string(of: "Policy.StatusMessage")
    var v_String: String? = jResp.string(of: "Policy.Tags.string")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "Policy.PolicyDetails.Actions").intValue
    while i < count_i {
        jResp.i = i
        Name = jResp.string(of: "Policy.PolicyDetails.Actions[i].Name")
        j = 0
        count_j = jResp.size(ofArray: "Policy.PolicyDetails.Actions[i].CrossRegionCopy").intValue
        while j < count_j {
            jResp.j = j
            CmkArn = jResp.string(of: "Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.CmkArn")
            Encrypted = jResp.int(of: "Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.Encrypted").intValue
            Interval = jResp.int(of: "Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.Interval").intValue
            IntervalUnit = jResp.string(of: "Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.IntervalUnit")
            Target = jResp.string(of: "Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].Target")
            j = j + 1
        }

        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner[i]")
        i = i + 1
    }

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

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

    i = 0
    count_i = jResp.size(ofArray: "Policy.PolicyDetails.Schedules").intValue
    while i < count_i {
        jResp.i = i
        CopyTags = jResp.int(of: "Policy.PolicyDetails.Schedules[i].CopyTags").intValue
        CronExpression = jResp.string(of: "Policy.PolicyDetails.Schedules[i].CreateRule.CronExpression")
        CreateRuleInterval = jResp.int(of: "Policy.PolicyDetails.Schedules[i].CreateRule.Interval").intValue
        CreateRuleIntervalUnit = jResp.string(of: "Policy.PolicyDetails.Schedules[i].CreateRule.IntervalUnit")
        Location = jResp.string(of: "Policy.PolicyDetails.Schedules[i].CreateRule.Location")
        Count = jResp.int(of: "Policy.PolicyDetails.Schedules[i].DeprecateRule.Count").intValue
        DeprecateRuleInterval = jResp.int(of: "Policy.PolicyDetails.Schedules[i].DeprecateRule.Interval").intValue
        DeprecateRuleIntervalUnit = jResp.string(of: "Policy.PolicyDetails.Schedules[i].DeprecateRule.IntervalUnit")
        FastRestoreRuleCount = jResp.int(of: "Policy.PolicyDetails.Schedules[i].FastRestoreRule.Count").intValue
        FastRestoreRuleInterval = jResp.int(of: "Policy.PolicyDetails.Schedules[i].FastRestoreRule.Interval").intValue
        FastRestoreRuleIntervalUnit = jResp.string(of: "Policy.PolicyDetails.Schedules[i].FastRestoreRule.IntervalUnit")
        Name = jResp.string(of: "Policy.PolicyDetails.Schedules[i].Name")
        RetainRuleCount = jResp.int(of: "Policy.PolicyDetails.Schedules[i].RetainRule.Count").intValue
        RetainRuleInterval = jResp.int(of: "Policy.PolicyDetails.Schedules[i].RetainRule.Interval").intValue
        RetainRuleIntervalUnit = jResp.string(of: "Policy.PolicyDetails.Schedules[i].RetainRule.IntervalUnit")
        j = 0
        count_j = jResp.size(ofArray: "Policy.PolicyDetails.Schedules[i].CreateRule.Times").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "Policy.PolicyDetails.Schedules[i].CreateRule.Times[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules").intValue
        while j < count_j {
            jResp.j = j
            CmkArn = jResp.string(of: "Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CmkArn")
            CopyTags = jResp.int(of: "Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CopyTags").intValue
            DeprecateRuleInterval = jResp.int(of: "Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.Interval").intValue
            DeprecateRuleIntervalUnit = jResp.string(of: "Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.IntervalUnit")
            Encrypted = jResp.int(of: "Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Encrypted").intValue
            RetainRuleInterval = jResp.int(of: "Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.Interval").intValue
            RetainRuleIntervalUnit = jResp.string(of: "Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.IntervalUnit")
            Target = jResp.string(of: "Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Target")
            TargetRegion = jResp.string(of: "Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].TargetRegion")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "Policy.PolicyDetails.Schedules[i].ShareRules").intValue
        while j < count_j {
            jResp.j = j
            UnshareInterval = jResp.int(of: "Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareInterval").intValue
            UnshareIntervalUnit = jResp.string(of: "Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareIntervalUnit")
            k = 0
            count_k = jResp.size(ofArray: "Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts").intValue
            while k < count_k {
                jResp.k = k
                strVal = jResp.string(of: "Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts[k]")
                k = k + 1
            }

            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "Policy.PolicyDetails.Schedules[i].TagsToAdd").intValue
        while j < count_j {
            jResp.j = j
            Key = jResp.string(of: "Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Key")
            Value = jResp.string(of: "Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Value")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "Policy.PolicyDetails.Schedules[i].VariableTags").intValue
        while j < count_j {
            jResp.j = j
            Key = jResp.string(of: "Policy.PolicyDetails.Schedules[i].VariableTags[j].Key")
            Value = jResp.string(of: "Policy.PolicyDetails.Schedules[i].VariableTags[j].Value")
            j = j + 1
        }

        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "Policy.PolicyDetails.TargetTags").intValue
    while i < count_i {
        jResp.i = i
        Key = jResp.string(of: "Policy.PolicyDetails.TargetTags[i].Key")
        Value = jResp.string(of: "Policy.PolicyDetails.TargetTags[i].Value")
        i = i + 1
    }

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

    // {
    //   "Policy": {
    //     "DateCreated": number,
    //     "DateModified": number,
    //     "Description": "string",
    //     "ExecutionRoleArn": "string",
    //     "PolicyArn": "string",
    //     "PolicyDetails": {
    //       "Actions": [
    //         {
    //           "CrossRegionCopy": [
    //             {
    //               "EncryptionConfiguration": {
    //                 "CmkArn": "string",
    //                 "Encrypted": boolean
    //               },
    //               "RetainRule": {
    //                 "Interval": number,
    //                 "IntervalUnit": "string"
    //               },
    //               "Target": "string"
    //             }
    //           ],
    //           "Name": "string"
    //         }
    //       ],
    //       "EventSource": {
    //         "Parameters": {
    //           "DescriptionRegex": "string",
    //           "EventType": "string",
    //           "SnapshotOwner": [
    //             "string"
    //           ]
    //         },
    //         "Type": "string"
    //       },
    //       "Parameters": {
    //         "ExcludeBootVolume": boolean,
    //         "NoReboot": boolean
    //       },
    //       "PolicyType": "string",
    //       "ResourceLocations": [
    //         "string"
    //       ],
    //       "ResourceTypes": [
    //         "string"
    //       ],
    //       "Schedules": [
    //         {
    //           "CopyTags": boolean,
    //           "CreateRule": {
    //             "CronExpression": "string",
    //             "Interval": number,
    //             "IntervalUnit": "string",
    //             "Location": "string",
    //             "Times": [
    //               "string"
    //             ]
    //           },
    //           "CrossRegionCopyRules": [
    //             {
    //               "CmkArn": "string",
    //               "CopyTags": boolean,
    //               "DeprecateRule": {
    //                 "Interval": number,
    //                 "IntervalUnit": "string"
    //               },
    //               "Encrypted": boolean,
    //               "RetainRule": {
    //                 "Interval": number,
    //                 "IntervalUnit": "string"
    //               },
    //               "Target": "string",
    //               "TargetRegion": "string"
    //             }
    //           ],
    //           "DeprecateRule": {
    //             "Count": number,
    //             "Interval": number,
    //             "IntervalUnit": "string"
    //           },
    //           "FastRestoreRule": {
    //             "AvailabilityZones": [
    //               "string"
    //             ],
    //             "Count": number,
    //             "Interval": number,
    //             "IntervalUnit": "string"
    //           },
    //           "Name": "string",
    //           "RetainRule": {
    //             "Count": number,
    //             "Interval": number,
    //             "IntervalUnit": "string"
    //           },
    //           "ShareRules": [
    //             {
    //               "TargetAccounts": [
    //                 "string"
    //               ],
    //               "UnshareInterval": number,
    //               "UnshareIntervalUnit": "string"
    //             }
    //           ],
    //           "TagsToAdd": [
    //             {
    //               "Key": "string",
    //               "Value": "string"
    //             }
    //           ],
    //           "VariableTags": [
    //             {
    //               "Key": "string",
    //               "Value": "string"
    //             }
    //           ]
    //         }
    //       ],
    //       "TargetTags": [
    //         {
    //           "Key": "string",
    //           "Value": "string"
    //         }
    //       ]
    //     },
    //     "PolicyId": "string",
    //     "State": "string",
    //     "StatusMessage": "string",
    //     "Tags": {
    //       "string": "string"
    //     }
    //   }
    // }

}