-
Notifications
You must be signed in to change notification settings - Fork 80
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
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
38ffb47
Reusable middleware for Route 53 TrimHostedZone
jbelkins 9ace770
Fix swiftlint
jbelkins f9e845b
Add Route53 TrimHostedZone middleware no matter the property name
jbelkins 3108dc5
Fix ktlint
jbelkins 3381dd0
Add Route 53 integration test, update generated Route 53 code
jbelkins ad88ccc
Package manifest regen & test cleanup
jbelkins 5d0e97b
Merge branch 'main' into jbe/reusable_trim_hosted_zone
jbelkins e0fe7b6
Merge branch 'main' into jbe/reusable_trim_hosted_zone
jbelkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
IntegrationTests/Services/AWSRoute53IntegrationTests/AWSRoute53Tests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
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) | ||
} | ||
} |
Empty file.
39 changes: 39 additions & 0 deletions
39
Sources/Core/AWSClientRuntime/Middlewares/Route53TrimHostedZoneMiddleware.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the same as the previously code-generated middleware, except:
|
||
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 | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
All operations used after creating the zone require the TrimHostedZone customization in order to succeed.