Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Route 53 TrimHostedZone customization is incomplete #1445

Merged
merged 8 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import XCTest
import AWSRoute53
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple integration test for Route 53:

  • creates a hosted zone,
  • creates an A record in that zone,
  • deletes the A record,
  • deletes the hosted zone.

All operations used after creating the zone require the TrimHostedZone customization in order to succeed.


class AWSRoute53Tests: XCTestCase {
var client: Route53Client!
var id: String?

override func setUp() async throws {
try await super.setUp()
client = try Route53Client(region: "us-east-1")
}
override func tearDown() async throws {
let input = DeleteHostedZoneInput(id: id)
_ = try await client.deleteHostedZone(input: input)
}

func test_route53_createsAndDeletesZoneAndRecords() async throws {
let ref = UUID().uuidString
let hostedZoneName = "\(ref).com."

let input0 = CreateHostedZoneInput(callerReference: ref, name: hostedZoneName)
let output0 = try await client.createHostedZone(input: input0)
id = output0.hostedZone?.id

let createBatch = Route53ClientTypes.ChangeBatch(changes:
[
Route53ClientTypes.Change(
action: .create,
resourceRecordSet: Route53ClientTypes.ResourceRecordSet(
name: "abc.\(hostedZoneName)", resourceRecords: [Route53ClientTypes.ResourceRecord(value: "1.1.1.1")], ttl: 3600, type: .a
)
),
]
)
let input1 = ChangeResourceRecordSetsInput(changeBatch: createBatch, hostedZoneId: id)
let output1 = try await client.changeResourceRecordSets(input: input1)

let deleteBatch = Route53ClientTypes.ChangeBatch(changes:
[
Route53ClientTypes.Change(
action: .delete,
resourceRecordSet: Route53ClientTypes.ResourceRecordSet(
name: "abc.\(hostedZoneName)", resourceRecords: [Route53ClientTypes.ResourceRecord(value: "1.1.1.1")], ttl: 3600, type: .a
)
),
]
)
let input2 = ChangeResourceRecordSetsInput(changeBatch: deleteBatch, hostedZoneId: id)
let output2 = try await client.changeResourceRecordSets(input: input2)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import ClientRuntime

public struct Route53TrimHostedZoneMiddleware<Input, Output>: ClientRuntime.Middleware {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as the previously code-generated middleware, except:

  • The input & output are generics that get substituted for each operation at compile time.
  • The hosted zone ID on the input model is accessed via a key path that is passed in at initialization.

public let id: Swift.String = "Route53TrimHostedZoneMiddleware"
private let prefixes = ["/hostedzone/", "hostedzone/", "/hostedzone", "hostedzone"]

private let hostedZoneIDKeyPath: WritableKeyPath<Input, String?>

public init(_ hostedZoneIDKeyPath: WritableKeyPath<Input, String?>) {
self.hostedZoneIDKeyPath = hostedZoneIDKeyPath
}

public func handle<H>(context: Context,
input: Input,
next: H) async throws -> ClientRuntime.OperationOutput<Output>
where H: Handler,
Self.MInput == H.Input,
Self.MOutput == H.Output,
Self.Context == H.Context {
guard let hostedZoneId = input[keyPath: hostedZoneIDKeyPath] else {
return try await next.handle(context: context, input: input)
}
var copiedInput = input
let stripped = hostedZoneId.stripFirstMatching(prefixes: prefixes)
copiedInput[keyPath: hostedZoneIDKeyPath] = stripped
return try await next.handle(context: context, input: copiedInput)
}

public typealias MInput = Input
public typealias MOutput = ClientRuntime.OperationOutput<Output>
public typealias Context = ClientRuntime.HttpContext
}
104 changes: 90 additions & 14 deletions Sources/Services/AWSRoute53/Route53Client.swift

Large diffs are not rendered by default.

Loading
Loading