Skip to content

Commit 423400f

Browse files
Adam EriVladislavFitz
andauthored
feat: Server side swift (#680)
* Add linux target specific import of FoundationNetworking. * Add Dockerfile for building the library in a container. * Add SwiftCrypto as dependency for the Linux target. * Operation related fixes for Linux. * Import FoundationNetworking for the Linux target * Add optional SwiftCrypto dependency for Linux targets to keep the compatibility with older macOS versions * Implement integration tests skipping in case of missing environment variables Co-authored-by: Vladislav Fitc <[email protected]>
1 parent 82d2fc5 commit 423400f

File tree

57 files changed

+1263
-192
lines changed

Some content is hidden

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

57 files changed

+1263
-192
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.build
2+
.swiftpm

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# You can set the Swift version to what you need for your app.
2+
# Versions can be found here: https://hub.docker.com/_/swift
3+
FROM swift as builder
4+
5+
WORKDIR /app
6+
7+
COPY ./Package.* ./
8+
9+
RUN swift package resolve
10+
11+
COPY . .
12+
13+
RUN swift build \
14+
--enable-test-discovery \
15+
-c release \
16+
-Xswiftc -g \
17+
-j 4
18+
19+
# RUN swift test --enable-test-discovery

Package.swift

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,55 @@
33

44
import PackageDescription
55

6+
#if os(Linux)
7+
let macOSVersion: SupportedPlatform.MacOSVersion = .v10_15
8+
#else
9+
let macOSVersion: SupportedPlatform.MacOSVersion = .v10_10
10+
#endif
11+
12+
#if os(Linux)
13+
let extraPackageDependencies: [Package.Dependency] = [
14+
.package(url: "https://github.com/apple/swift-crypto.git", from: "1.1.2"),
15+
]
16+
#else
17+
let extraPackageDependencies: [Package.Dependency] = []
18+
#endif
19+
20+
#if os(Linux)
21+
let extraTargetDependencies: [Target.Dependency] = [
22+
.product(name: "Crypto", package: "swift-crypto")
23+
]
24+
#else
25+
let extraTargetDependencies: [Target.Dependency] = []
26+
#endif
27+
628
let package = Package(
7-
name: "AlgoliaSearchClient",
8-
platforms: [
9-
.iOS(.v9),
10-
.macOS(.v10_10),
11-
.watchOS(.v2),
12-
.tvOS(.v9)
13-
],
14-
products: [
15-
.library(
16-
name: "AlgoliaSearchClient",
17-
targets: ["AlgoliaSearchClient"])
18-
],
19-
dependencies: [
20-
.package(url:"https://github.com/apple/swift-log.git", from: "1.4.0")
21-
],
22-
targets: [
23-
.target(
24-
name: "AlgoliaSearchClient",
25-
dependencies: ["Logging"]),
26-
.testTarget(
27-
name: "AlgoliaSearchClientTests",
28-
dependencies: ["AlgoliaSearchClient", "Logging"])
29-
]
29+
name: "AlgoliaSearchClient",
30+
platforms: [
31+
.iOS(.v9),
32+
.macOS(macOSVersion),
33+
.watchOS(.v2),
34+
.tvOS(.v9)
35+
],
36+
products: [
37+
.library(
38+
name: "AlgoliaSearchClient",
39+
targets: ["AlgoliaSearchClient"])
40+
],
41+
dependencies: [
42+
.package(url:"https://github.com/apple/swift-log.git", from: "1.4.0"),
43+
] + extraPackageDependencies,
44+
targets: [
45+
.target(
46+
name: "AlgoliaSearchClient",
47+
dependencies: [
48+
.product(name: "Logging", package: "swift-log"),
49+
] + extraTargetDependencies),
50+
.testTarget(
51+
name: "AlgoliaSearchClientTests",
52+
dependencies: [
53+
.target(name: "AlgoliaSearchClient"),
54+
.product(name: "Logging", package: "swift-log"),
55+
] + extraTargetDependencies)
56+
]
3057
)

Sources/AlgoliaSearchClient/Async/AsyncOperation.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ open class AsyncOperation: Operation {
2828
}
2929
}
3030

31-
}
32-
33-
extension AsyncOperation {
3431
// NSOperation Overrides
3532
override open var isReady: Bool {
3633
return super.isReady && state == .ready

Sources/AlgoliaSearchClient/Client/AnalyticsClient.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//
77

88
import Foundation
9+
#if canImport(FoundationNetworking)
10+
import FoundationNetworking
11+
#endif
912

1013
public struct AnalyticsClient: Credentials {
1114

Sources/AlgoliaSearchClient/Client/InsightsClient.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//
77

88
import Foundation
9+
#if canImport(FoundationNetworking)
10+
import FoundationNetworking
11+
#endif
912

1013
public struct InsightsClient: Credentials {
1114

Sources/AlgoliaSearchClient/Client/PlacesClient.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//
77

88
import Foundation
9+
#if canImport(FoundationNetworking)
10+
import FoundationNetworking
11+
#endif
912

1013
public struct PlacesClient: Credentials {
1114

Sources/AlgoliaSearchClient/Client/RecommendationClient.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//
77

88
import Foundation
9+
#if canImport(FoundationNetworking)
10+
import FoundationNetworking
11+
#endif
912

1013
public struct RecommendationClient: Credentials {
1114

Sources/AlgoliaSearchClient/Client/Search/SearchClient+SecuredAPIKey.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public extension SearchClient {
1212
func generateSecuredApiKey(parentApiKey: APIKey,
1313
with restriction: SecuredAPIKeyRestriction) -> APIKey {
1414
let queryParams = restriction.urlEncodedString
15-
let hash = queryParams.hmac(algorithm: .sha256, key: parentApiKey.rawValue)
15+
let hash = queryParams.hmac256(withKey: parentApiKey.rawValue)
1616
return APIKey(rawValue: "\(hash)\(queryParams)".toBase64())
1717
}
1818

@@ -25,5 +25,4 @@ public extension SearchClient {
2525
let timestampDate = Date(timeIntervalSince1970: timestamp)
2626
return timestampDate.timeIntervalSince1970 - Date().timeIntervalSince1970
2727
}
28-
2928
}

Sources/AlgoliaSearchClient/Client/Search/SearchClient.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
import Foundation
99

10+
#if canImport(FoundationNetworking)
11+
import FoundationNetworking
12+
#endif
13+
1014
typealias Client = SearchClient
1115

1216
/// Client to perform operations on indices.

0 commit comments

Comments
 (0)