Skip to content

Commit c8e18b2

Browse files
committed
refactor into 3 modules
1 parent 3dc7fdf commit c8e18b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+680
-427
lines changed

Package.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ let package = Package(
5454
.library(name: "SmithyWaitersAPI", targets: ["SmithyWaitersAPI"]),
5555
.library(name: "SmithyTestUtil", targets: ["SmithyTestUtil"]),
5656
.library(name: "SmithySwiftNIO", targets: ["SmithySwiftNIO"]),
57+
.library(name: "SmithyTelemetry", targets: ["SmithyTelemetry"]),
58+
.library(name: "SmithyHTTPClientAPI", targets: ["SmithyHTTPClientAPI"]),
5759
],
5860
dependencies: {
5961
var dependencies: [Package.Dependency] = [
@@ -76,10 +78,27 @@ let package = Package(
7678
.product(name: "Logging", package: "swift-log"),
7779
]
7880
),
81+
.target(
82+
name: "SmithyTelemetry",
83+
dependencies: [
84+
"Smithy",
85+
]
86+
),
87+
.target(
88+
name: "SmithyHTTPClientAPI",
89+
dependencies: [
90+
"Smithy",
91+
"SmithyHTTPAPI",
92+
"SmithyTelemetry",
93+
.product(name: "AwsCommonRuntimeKit", package: "aws-crt-swift"),
94+
]
95+
),
7996
.target(
8097
name: "ClientRuntime",
8198
dependencies: [
8299
"Smithy",
100+
"SmithyTelemetry",
101+
"SmithyHTTPClientAPI",
83102
"SmithyRetriesAPI",
84103
"SmithyRetries",
85104
"SmithyXML",
@@ -132,6 +151,7 @@ let package = Package(
132151
"SmithyHTTPAPI",
133152
"SmithyHTTPClient",
134153
"SmithyStreams",
154+
"SmithyHTTPClientAPI",
135155
"ClientRuntime",
136156
.product(name: "AsyncHTTPClient", package: "async-http-client"),
137157
],

Sources/ClientRuntime/Config/DefaultSDKRuntimeConfiguration.swift

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import struct SmithyRetries.ExponentialBackoffStrategy
1616
import protocol SmithyRetriesAPI.RetryErrorInfoProvider
1717
import protocol SmithyRetriesAPI.RetryStrategy
1818
import struct SmithyRetriesAPI.RetryStrategyOptions
19+
import class SmithySwiftNIO.SwiftNIOHTTPClient
1920

2021
public struct DefaultSDKRuntimeConfiguration<DefaultSDKRuntimeRetryStrategy: RetryStrategy,
2122
DefaultSDKRuntimeRetryErrorInfoProvider: RetryErrorInfoProvider> {
@@ -91,20 +92,21 @@ public extension DefaultSDKRuntimeConfiguration {
9192
static func makeClient(
9293
httpClientConfiguration: HttpClientConfiguration = defaultHttpClientConfiguration
9394
) -> HTTPClient {
94-
#if os(iOS) || os(tvOS) || os(watchOS) || os(visionOS) || os(macOS)
95-
return URLSessionHTTPClient(httpClientConfiguration: httpClientConfiguration)
96-
#else
97-
let connectTimeoutMs = httpClientConfiguration.connectTimeout.map { UInt32($0 * 1000) }
98-
let socketTimeout = UInt32(httpClientConfiguration.socketTimeout)
99-
let config = CRTClientEngineConfig(
100-
maxConnectionsPerEndpoint: httpClientConfiguration.maxConnections,
101-
telemetry: httpClientConfiguration.telemetry ?? CRTClientEngine.noOpCrtClientEngineTelemetry,
102-
connectTimeoutMs: connectTimeoutMs,
103-
crtTlsOptions: httpClientConfiguration.tlsConfiguration as? CRTClientTLSOptions,
104-
socketTimeout: socketTimeout
105-
)
106-
return CRTClientEngine(config: config)
107-
#endif
95+
return SwiftNIOHTTPClient(httpClientConfiguration: httpClientConfiguration)
96+
// #if os(iOS) || os(tvOS) || os(watchOS) || os(visionOS) || os(macOS)
97+
// return URLSessionHTTPClient(httpClientConfiguration: httpClientConfiguration)
98+
// #else
99+
// let connectTimeoutMs = httpClientConfiguration.connectTimeout.map { UInt32($0 * 1000) }
100+
// let socketTimeout = UInt32(httpClientConfiguration.socketTimeout)
101+
// let config = CRTClientEngineConfig(
102+
// maxConnectionsPerEndpoint: httpClientConfiguration.maxConnections,
103+
// telemetry: httpClientConfiguration.telemetry ?? CRTClientEngine.noOpCrtClientEngineTelemetry,
104+
// connectTimeoutMs: connectTimeoutMs,
105+
// crtTlsOptions: httpClientConfiguration.tlsConfiguration as? CRTClientTLSOptions,
106+
// socketTimeout: socketTimeout
107+
// )
108+
// return CRTClientEngine(config: config)
109+
// #endif
108110
}
109111

110112
/// The default HTTP client configuration to use.

Sources/ClientRuntime/Networking/Http/HttpClientConfiguration.swift

Lines changed: 4 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -5,87 +5,8 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8-
import AwsCommonRuntimeKit
9-
import struct Foundation.TimeInterval
10-
import enum Smithy.URIScheme
11-
import struct SmithyHTTPAPI.Headers
8+
import SmithyHTTPClientAPI
129

13-
public class HttpClientConfiguration {
14-
15-
/// The timeout for establishing a connection, in seconds.
16-
///
17-
/// If none is provided, the client will use default values based on the platform.
18-
public var connectTimeout: TimeInterval?
19-
20-
/// The timeout for socket, in seconds.
21-
/// Sets maximum time to wait between two data packets.
22-
/// Used to close stale connections that have no activity.
23-
///
24-
/// Defaults to 60 seconds if no value is provided.
25-
public var socketTimeout: TimeInterval
26-
27-
/// HTTP headers to be submitted with every HTTP request.
28-
///
29-
/// If none is provided, defaults to no extra headers.
30-
public var defaultHeaders: Headers
31-
32-
/// The maximum connections the HTTP client makes per host or per endpoint depending on the OS.
33-
///
34-
/// For Apple platforms, it will be per host.
35-
/// For Linux, it will be per endpoint (protocol + host + port).
36-
public var maxConnections: Int
37-
38-
// add any other properties here you want to give the service operations
39-
// control over to be mapped to the Http Client
40-
41-
/// The URL scheme to be used for HTTP requests. Supported values are `http` and `https`.
42-
///
43-
/// If none is provided, the default protocol for the operation will be used
44-
public var protocolType: URIScheme?
45-
46-
/// Custom TLS configuration for HTTPS connections.
47-
///
48-
/// Enables specifying client certificates and trust stores for secure communication.
49-
/// Defaults to system's TLS settings if `nil`.
50-
public var tlsConfiguration: (any TLSConfiguration)?
51-
52-
/// HTTP Client Telemetry
53-
public var telemetry: HttpTelemetry?
54-
55-
/// Creates a configuration object for a SDK HTTP client.
56-
///
57-
/// Not all configuration settings may be followed by all clients.
58-
/// - Parameters:
59-
/// - connectTimeout: The maximum time to wait for a connection to be established.
60-
/// - socketTimeout: The maximum time to wait between data packets.
61-
/// - defaultHeaders: HTTP headers to be included with every HTTP request.
62-
/// Note that certain headers may cause your API request to fail. Defaults to no headers.
63-
/// - protocolType: The HTTP scheme (`http` or `https`) to be used for API requests. Defaults to the operation's standard configuration.
64-
/// - tlsConfiguration: Optional custom TLS configuration for HTTPS requests. If `nil`, defaults to a standard configuration.
65-
/// - maxConnections: The maximum number of connections the HTTP client makes per host (for Apple platforms) or per endpoint (for Linux). For non-mac Apple platforms, defaults to 6. For macOS and Linux, defaults to 50.
66-
public init(
67-
connectTimeout: TimeInterval? = nil,
68-
socketTimeout: TimeInterval = 60.0,
69-
protocolType: URIScheme = .https,
70-
defaultHeaders: Headers = Headers(),
71-
tlsConfiguration: (any TLSConfiguration)? = nil,
72-
telemetry: HttpTelemetry? = nil,
73-
maxConnections: Int? = nil
74-
) {
75-
self.socketTimeout = socketTimeout
76-
self.protocolType = protocolType
77-
self.defaultHeaders = defaultHeaders
78-
self.connectTimeout = connectTimeout
79-
self.tlsConfiguration = tlsConfiguration
80-
self.telemetry = telemetry
81-
if let maxConnections {
82-
self.maxConnections = maxConnections
83-
} else {
84-
#if os(macOS) || os(Linux)
85-
self.maxConnections = 50
86-
#else // iOS, ipadOS, watchOS, tvOS.
87-
self.maxConnections = 6 // URLSession default.
88-
#endif
89-
}
90-
}
91-
}
10+
/// Typealias for backward compatibility.
11+
/// The actual implementation is now in SmithyHTTPClientAPI.
12+
public typealias HttpClientConfiguration = SmithyHTTPClientAPI.HttpClientConfiguration

Sources/ClientRuntime/Networking/Http/HttpTelemetry.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import class Foundation.NSRecursiveLock
77
import struct Smithy.AttributeKey
88
import struct Smithy.Attributes
99
import protocol SmithyHTTPAPI.HTTPClient
10+
import SmithyTelemetry
1011

1112
/// Container for HTTPClient telemetry, including configurable attributes and names.
1213
///

Sources/ClientRuntime/Networking/Http/TLSConfiguration.swift

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,8 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8-
/**
9-
* Configuration settings about TLS set up.
10-
* All settings are optional.
11-
* Not specifying them will use the SDK defaults
12-
*/
13-
public protocol TLSConfiguration {
8+
import SmithyHTTPClientAPI
149

15-
// Optional path to a PEM certificate
16-
var certificate: String? { get set }
17-
18-
// Optional path to certificate directory
19-
var certificateDir: String? { get set }
20-
21-
// Optional path to a PEM format private key
22-
var privateKey: String? { get set }
23-
24-
// Optional path to PKCS #12 certificate , in PEM format
25-
var pkcs12Path: String? { get set }
26-
27-
// Optional PKCS#12 password
28-
var pkcs12Password: String? { get set }
29-
}
10+
/// Typealias for backward compatibility.
11+
/// The actual implementation is now in SmithyHTTPClientAPI.
12+
public typealias TLSConfiguration = SmithyHTTPClientAPI.TLSConfiguration

Sources/ClientRuntime/Telemetry/Context/TelemetryContext.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8-
/// A Telemetry Context is a container that can be associated with Tracers and Metrics.
9-
///
10-
/// Context implementations may be containers for execution-scoped values across API boundaries (both in-process and
11-
/// distributed).
12-
public protocol TelemetryContext: Sendable {
8+
import SmithyTelemetry
139

14-
/// Make this context the currently active context.
15-
///
16-
/// - Returns: the scope of the current context
17-
func makeCurrent() -> TelemetryScope
18-
}
10+
/// Typealias for backward compatibility.
11+
/// The actual implementation is now in SmithyTelemetry.
12+
public typealias TelemetryContext = SmithyTelemetry.TelemetryContext

Sources/ClientRuntime/Telemetry/Context/TelemetryContextManager.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8-
/// A Telemetry Context Manager manages the Telemetry Contexts in a client.
9-
///
10-
/// Implementations should be able to manage contexts in a thread-safe way.
11-
public protocol TelemetryContextManager: Sendable {
8+
import SmithyTelemetry
129

13-
/// - Returns: the current Telemetry Context
14-
func current() -> TelemetryContext
15-
}
10+
/// Typealias for backward compatibility.
11+
/// The actual implementation is now in SmithyTelemetry.
12+
public typealias TelemetryContextManager = SmithyTelemetry.TelemetryContextManager

Sources/ClientRuntime/Telemetry/Context/TelemetryScope.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8-
/// Delineates a Telemetry Scope that has a beginning and end, particularly for Telemetry Contexts.
9-
public protocol TelemetryScope: Sendable {
8+
import SmithyTelemetry
109

11-
/// Ends the scope.
12-
func end()
13-
}
10+
/// Typealias for backward compatibility.
11+
/// The actual implementation is now in SmithyTelemetry.
12+
public typealias TelemetryScope = SmithyTelemetry.TelemetryScope

Sources/ClientRuntime/Telemetry/DefaultTelemetry.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import struct Smithy.AttributeKey
99
import struct Smithy.Attributes
1010
import protocol Smithy.LogAgent
1111
import struct Smithy.SwiftLogger
12+
import SmithyTelemetry
1213

1314
/// Namespace for the Default SDK Telemetry implementations.
1415
public enum DefaultTelemetry: Sendable {

Sources/ClientRuntime/Telemetry/Logging/LoggerProvider.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8-
import protocol Smithy.LogAgent
8+
import SmithyTelemetry
99

10-
/// A Logger Provider provides implementations of LogAgents.
11-
public protocol LoggerProvider: Sendable {
12-
/// Provides a LogAgent.
13-
///
14-
/// - Parameter name: the name associated with the LogAgent
15-
/// - Returns: a LogAgent
16-
func getLogger(name: String) -> LogAgent
17-
}
10+
/// Typealias for backward compatibility.
11+
/// The actual implementation is now in SmithyTelemetry.
12+
public typealias LoggerProvider = SmithyTelemetry.LoggerProvider

0 commit comments

Comments
 (0)