Skip to content

Commit

Permalink
Remove SotoCrypto (#546)
Browse files Browse the repository at this point in the history
* Remove SotoCrypto

* Remove @available/format
  • Loading branch information
adam-fowler committed Jul 5, 2023
1 parent 0018274 commit a4aea4e
Show file tree
Hide file tree
Showing 41 changed files with 43 additions and 609 deletions.
26 changes: 8 additions & 18 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ import PackageDescription

let package = Package(
name: "soto-core",
platforms: [
.macOS(.v10_15),
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v6),
],
products: [
.library(name: "SotoCore", targets: ["SotoCore"]),
.library(name: "SotoTestUtils", targets: ["SotoTestUtils"]),
.library(name: "SotoSignerV4", targets: ["SotoSignerV4"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.1.0"),
.package(url: "https://github.com/apple/swift-crypto.git", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.0"),
.package(url: "https://github.com/apple/swift-metrics.git", "1.0.0"..<"3.0.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.42.0"),
Expand Down Expand Up @@ -52,9 +59,8 @@ let package = Package(
.product(name: "JMESPath", package: "jmespath.swift"),
]
),
.target(name: "SotoCrypto", dependencies: []),
.target(name: "SotoSignerV4", dependencies: [
.byName(name: "SotoCrypto"),
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOHTTP1", package: "swift-nio"),
]),
Expand All @@ -74,9 +80,6 @@ let package = Package(
.target(name: "CSotoExpat", dependencies: []),
.target(name: "INIParser", dependencies: []),

.testTarget(name: "SotoCryptoTests", dependencies: [
.byName(name: "SotoCrypto"),
]),
.testTarget(
name: "SotoCoreTests",
dependencies: [
Expand All @@ -97,16 +100,3 @@ let package = Package(
]),
]
)

// switch for whether to use swift crypto. Swift crypto requires macOS10.15 or iOS13.I'd rather not pass this requirement on
#if os(Linux)
let useSwiftCrypto = true
#else
let useSwiftCrypto = false
#endif

// Use Swift cypto on Linux.
if useSwiftCrypto {
package.dependencies.append(.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0"..<"3.0.0"))
package.targets.first { $0.name == "SotoCrypto" }?.dependencies.append(.product(name: "Crypto", package: "swift-crypto"))
}
1 change: 0 additions & 1 deletion Sources/SotoCore/AWSClient+EndpointDiscovery+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import Logging
import NIOCore

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension AWSClient {
/// Execute an empty request
/// - parameters:
Expand Down
1 change: 0 additions & 1 deletion Sources/SotoCore/AWSClient+Paginate+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import Logging
import NIOCore

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension AWSClient {
/// Used to access paginated results.
public struct PaginatorSequence<Input: AWSPaginateToken, Output: AWSShape>: AsyncSequence where Input.Token: Equatable {
Expand Down
6 changes: 3 additions & 3 deletions Sources/SotoCore/AWSClient+Paginate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension AWSClient {
let responseFuture = command(input, logger, eventLoop)
.flatMap { response in
return onPage(currentValue, response, eventLoop)
.map { continuePaginate, result -> Void in
.map { continuePaginate, result in
guard continuePaginate == true else { return promise.succeed(result) }
// get next block token and construct a new input with this token
guard let outputToken = response[keyPath: outputKey] else { return promise.succeed(result) }
Expand Down Expand Up @@ -140,7 +140,7 @@ extension AWSClient {
let responseFuture = command(input, logger, eventLoop)
.flatMap { response in
return onPage(currentValue, response, eventLoop)
.map { continuePaginate, result -> Void in
.map { continuePaginate, result in
guard continuePaginate == true else { return promise.succeed(result) }
// get next block token and construct a new input with this token
guard let token = response[keyPath: tokenKey] else { return promise.succeed(result) }
Expand Down Expand Up @@ -219,7 +219,7 @@ extension AWSClient {
let responseFuture = command(input, logger, eventLoop)
.flatMap { response in
return onPage(currentValue, response, eventLoop)
.map { continuePaginate, result -> Void in
.map { continuePaginate, result in
guard continuePaginate == true else { return promise.succeed(result) }
// get next block token and construct a new input with this token
guard let token = response[keyPath: tokenKey],
Expand Down
1 change: 0 additions & 1 deletion Sources/SotoCore/AWSClient+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Metrics
import NIOCore
import SotoSignerV4

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension AWSClient {
/// Shutdown AWSClient asynchronously.
///
Expand Down
4 changes: 2 additions & 2 deletions Sources/SotoCore/AWSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -637,15 +637,15 @@ extension AWSClient {
func execute(attempt: Int) {
// execute HTTP request
_ = request(eventLoop)
.flatMapThrowing { response throws -> Void in
.flatMapThrowing { response throws in
// if it returns an HTTP status code outside 2xx then throw an error
guard (200..<300).contains(response.status.code) else {
throw self.createError(for: response, serviceConfig: serviceConfig, logger: logger)
}
let output = try processResponse(response)
promise.succeed(output)
}
.flatMapErrorThrowing { error -> Void in
.flatMapErrorThrowing { error in
// if streaming and the error returned is an AWS error fail immediately. Do not attempt
// to retry as the streaming function will not know you are retrying
if streaming,
Expand Down
1 change: 0 additions & 1 deletion Sources/SotoCore/AWSService+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import struct Foundation.URL
import NIOCore

/// Protocol for services objects. Contains a client to communicate with AWS and config for defining how to communicate
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension AWSService {
/// Generate a signed URL
/// - parameters:
Expand Down
1 change: 0 additions & 1 deletion Sources/SotoCore/AWSShapes/Payload+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import NIOCore

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension AWSPayload {
/// Construct a stream payload from an `AsynSequence` of `ByteBuffers`
/// - Parameters:
Expand Down
2 changes: 1 addition & 1 deletion Sources/SotoCore/AWSShapes/Payload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public struct AWSPayload {
// use chunked reader buffer size to avoid allocating additional buffers when streaming data
let blockSize = S3ChunkedStreamReader.bufferSize
var leftToRead = size
var readSoFar: Int = 0
var readSoFar = 0
let stream: StreamReadFunction = { eventLoop in
// calculate how much data is left to read, if a file size was indicated
var downloadSize = blockSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import NIOCore

/// An AsyncSequence that returns fixed size ByteBuffers from an AsyncSequence of ByteBuffers
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public struct FixedSizeByteBufferAsyncSequence<Base: AsyncSequence>: AsyncSequence where Base.Element == ByteBuffer {
public typealias Element = ByteBuffer

Expand Down Expand Up @@ -76,10 +75,8 @@ public struct FixedSizeByteBufferAsyncSequence<Base: AsyncSequence>: AsyncSequen
}
}

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension FixedSizeByteBufferAsyncSequence: Sendable where Base: Sendable {}

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension AsyncSequence where Element == ByteBuffer {
/// Return an AsyncSequence that returns ByteBuffers of a fixed size
/// - Parameter chunkSize: Size of each chunk
Expand Down
1 change: 0 additions & 1 deletion Sources/SotoCore/Concurrency/Sequence+concurrentMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension Sequence where Element: Sendable {
/// Returns an array containing the results of mapping the given async closure over
/// the sequence’s elements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class ConfigFileCredentialProvider: CredentialProviderSelector {
context: context
)
.flatMapThrowing { sharedCredentials in
return try credentialProvider(from: sharedCredentials, context: context, endpoint: endpoint)
return try self.credentialProvider(from: sharedCredentials, context: context, endpoint: endpoint)
}
}

Expand Down
4 changes: 1 addition & 3 deletions Sources/SotoCore/Credential/CredentialProvider+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import NIOCore
import SotoSignerV4

/// Async Protocol for providing AWS credentials
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public protocol AsyncCredentialProvider: CredentialProvider {
/// Return credential
/// - Parameters:
Expand All @@ -26,11 +25,10 @@ public protocol AsyncCredentialProvider: CredentialProvider {
func getCredential(on eventLoop: EventLoop, logger: Logger) async throws -> Credential
}

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension AsyncCredentialProvider {
public func getCredential(on eventLoop: EventLoop, logger: Logger) -> EventLoopFuture<Credential> {
let promise = eventLoop.makePromise(of: Credential.self)
promise.completeWithTask { try await getCredential(on: eventLoop, logger: logger) }
promise.completeWithTask { try await self.getCredential(on: eventLoop, logger: logger) }
return promise.futureResult
}
}
4 changes: 2 additions & 2 deletions Sources/SotoCore/Credential/DeferredCredentialProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public class DeferredCredentialProvider: CredentialProvider {
var credential: Credential? {
get {
self.lock.withLock {
internalCredential
self.internalCredential
}
}
set {
self.lock.withLock {
internalCredential = newValue
self.internalCredential = newValue
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension ArrayCoder: CustomDecoder where Element: Decodable {

var container = try topLevelContainer.nestedUnkeyedContainer(forKey: memberKey)
while !container.isAtEnd {
values.append(try container.decode(Element.self))
try values.append(container.decode(Element.self))
}
return values
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension EC2ArrayCoder: CustomDecoder where Element: Decodable {

var container = try topLevelContainer.nestedUnkeyedContainer(forKey: memberKey)
while !container.isAtEnd {
values.append(try container.decode(Element.self))
try values.append(container.decode(Element.self))
}
return values
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SotoCore/HTTP/S3StreamReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ final class S3ChunkedStreamReader: StreamReader {
}
let promise: EventLoopPromise<ByteBuffer> = eventLoop.makePromise()
func _fillBuffer() {
self.read(eventLoop).map { result -> Void in
self.read(eventLoop).map { result in
// check if a byte buffer was returned. If not then it must have been `.end`
guard case .byteBuffer(var buffer) = result else {
if self.bytesLeftToRead == self.workingBuffer.readableBytes {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SotoCore/HTTP/StreamWriter+write.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension AsyncHTTPClient.HTTPClient.Body.StreamWriter {
// get byte buffer from closure, write to StreamWriter, if there are still bytes to write then call
// _writeToStreamWriter again.
reader.streamChunks(on: eventLoop)
.map { byteBuffers -> Void in
.map { byteBuffers in
// if no amount was set and no byte buffers are supppied then this is assumed to mean
// there will be no more data
if amountLeft == nil, byteBuffers.count == 0 {
Expand Down
10 changes: 5 additions & 5 deletions Sources/SotoCore/Message/AWSRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
//
//===----------------------------------------------------------------------===//

import Crypto
import struct Foundation.CharacterSet
import struct Foundation.Data
import struct Foundation.Date
import struct Foundation.URL
import struct Foundation.URLComponents
import NIOCore
import NIOHTTP1
import SotoCrypto
import SotoSignerV4

/// Object encapsulating all the information needed to generate a raw HTTP request to AWS
Expand Down Expand Up @@ -211,7 +211,7 @@ extension AWSRequest {
Self.verifyStream(operation: operationName, payload: awsPayload, input: shapeWithPayload)
body = .raw(awsPayload)
case let shape as AWSEncodableShape:
body = .json(try shape.encodeAsJSON(byteBufferAllocator: configuration.byteBufferAllocator))
body = try .json(shape.encodeAsJSON(byteBufferAllocator: configuration.byteBufferAllocator))
default:
preconditionFailure("Cannot add this as a payload")
}
Expand All @@ -221,7 +221,7 @@ extension AWSRequest {
} else {
// only include the body if there are members that are output in the body.
if memberVariablesCount > 0 {
body = .json(try input.encodeAsJSON(byteBufferAllocator: configuration.byteBufferAllocator))
body = try .json(input.encodeAsJSON(byteBufferAllocator: configuration.byteBufferAllocator))
} else if httpMethod == .PUT || httpMethod == .POST {
// PUT and POST requests require a body even if it is empty. This is not the case with XML
body = .json(configuration.byteBufferAllocator.buffer(string: "{}"))
Expand All @@ -242,7 +242,7 @@ extension AWSRequest {
if let encoding = Input.getEncoding(for: payload), case .body(let locationName) = encoding.location {
rootName = locationName
}
body = .xml(try shape.encodeAsXML(rootName: rootName, namespace: configuration.xmlNamespace))
body = try .xml(shape.encodeAsXML(rootName: rootName, namespace: configuration.xmlNamespace))
default:
preconditionFailure("Cannot add this as a payload")
}
Expand All @@ -252,7 +252,7 @@ extension AWSRequest {
} else {
// only include the body if there are members that are output in the body.
if memberVariablesCount > 0 {
body = .xml(try input.encodeAsXML(namespace: configuration.xmlNamespace))
body = try .xml(input.encodeAsXML(namespace: configuration.xmlNamespace))
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SotoCore/Message/Middleware/S3Middleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
//
//===----------------------------------------------------------------------===//

import Crypto
import Foundation
import SotoCrypto
import SotoXML

/// Middleware applied to S3 service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//

import SotoCrypto
import Crypto

let MEGA_BYTE = 1024 * 1024

Expand Down
1 change: 0 additions & 1 deletion Sources/SotoCore/Waiters/AWSClient+Waiter+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import Logging
import NIOCore

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension AWSClient {
/// Returns when waiter polling returns a success state
/// or returns an error if the polling returns an error or timesout
Expand Down
4 changes: 2 additions & 2 deletions Sources/SotoCore/Waiters/Matcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public struct JMESAnyPathMatcher<Value: CustomStringConvertible>: AWSWaiterMatch
case .success(let output):
do {
if let searchResult = try expression.search(object: output, as: [CustomStringConvertible].self) {
return searchResult.first { expected == $0.description } != nil
return searchResult.first { self.expected == $0.description } != nil
} else {
return false
}
Expand Down Expand Up @@ -94,7 +94,7 @@ public struct JMESAllPathMatcher<Value: CustomStringConvertible>: AWSWaiterMatch
case .success(let output):
do {
if let searchResult = try expression.search(object: output, as: [CustomStringConvertible].self) {
return searchResult.first { expected != $0.description } == nil
return searchResult.first { self.expected != $0.description } == nil
} else {
return false
}
Expand Down
40 changes: 0 additions & 40 deletions Sources/SotoCrypto/ByteArray.swift

This file was deleted.

Loading

0 comments on commit a4aea4e

Please sign in to comment.