Skip to content

Commit

Permalink
swift format
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Oct 16, 2024
1 parent 6760b13 commit f2c05b0
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct IdentityProviderFactory: Sendable {
self.cb = cb
}

internal func createProvider(context: Context) -> IdentityProvider {
func createProvider(context: Context) -> IdentityProvider {
self.cb(context)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Soto/Extensions/DynamoDB/DynamoDB+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ extension DynamoDB {
var item = try DynamoDBEncoder().encode(self.updateItem)
// extract key from input object
var key: [String: AttributeValue] = [:]
self.key.forEach {
key[$0] = item[$0]!
item[$0] = nil
for element in self.key {
key[element] = item[element]!
item[element] = nil
}
// construct expression attribute name and value arrays from name attribute value map.
// if names already provided along with a custom update expression then use the provided names
Expand Down
2 changes: 1 addition & 1 deletion Sources/Soto/Extensions/DynamoDB/DynamoDBDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private class _DynamoDBDecoder: Decoder {
var attribute: DynamoDB.AttributeValue
let decoder: _DynamoDBDecoder

internal init(attribute: DynamoDB.AttributeValue, decoder: _DynamoDBDecoder) {
init(attribute: DynamoDB.AttributeValue, decoder: _DynamoDBDecoder) {
self.attribute = attribute
self.decoder = decoder
self.codingPath = decoder.codingPath
Expand Down
4 changes: 2 additions & 2 deletions Sources/Soto/Extensions/DynamoDB/DynamoDBEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class _DynamoDBEncoder: Encoder {
let container: _EncoderKeyedContainer
let encoder: _DynamoDBEncoder

internal init(container: _EncoderKeyedContainer, encoder: _DynamoDBEncoder) {
init(container: _EncoderKeyedContainer, encoder: _DynamoDBEncoder) {
self.container = container
self.encoder = encoder
self.codingPath = encoder.codingPath
Expand Down Expand Up @@ -274,7 +274,7 @@ class _DynamoDBEncoder: Encoder {
let container: _EncoderUnkeyedContainer
let encoder: _DynamoDBEncoder

internal init(container: _EncoderUnkeyedContainer, encoder: _DynamoDBEncoder) {
init(container: _EncoderUnkeyedContainer, encoder: _DynamoDBEncoder) {
self.container = container
self.encoder = encoder
self.codingPath = encoder.codingPath
Expand Down
23 changes: 11 additions & 12 deletions Sources/Soto/Extensions/S3/S3+multipart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,10 @@ extension S3 {

// create array of upload part requests.
let uploadPartRequests: [UploadPartCopyRequest] = (1...numParts).map { part in
let copyRange: String
if part != numParts {
copyRange = "bytes=\((part - 1) * partSize)-\(part * partSize - 1)"
let copyRange = if part != numParts {
"bytes=\((part - 1) * partSize)-\(part * partSize - 1)"
} else {
copyRange = "bytes=\((part - 1) * partSize)-\((part - 1) * partSize + finalPartSize - 1)"
"bytes=\((part - 1) * partSize)-\((part - 1) * partSize + finalPartSize - 1)"
}
return .init(bucket: input.bucket, copySource: input.copySource, copySourceRange: copyRange, copySourceSSECustomerAlgorithm: input.copySourceSSECustomerAlgorithm, copySourceSSECustomerKey: input.copySourceSSECustomerKey, copySourceSSECustomerKeyMD5: input.copySourceSSECustomerKeyMD5, expectedBucketOwner: input.expectedBucketOwner, expectedSourceBucketOwner: input.expectedSourceBucketOwner, key: input.key, partNumber: part, requestPayer: input.requestPayer, sseCustomerAlgorithm: input.sseCustomerAlgorithm, sseCustomerKey: input.sseCustomerKey, sseCustomerKeyMD5: input.sseCustomerKeyMD5, uploadId: uploadId)
}
Expand Down Expand Up @@ -687,11 +686,10 @@ extension S3 {
results.append(element)
}
}
let body: AWSHTTPBody
if let progress = newProgress {
body = .init(asyncSequence: buffer.asyncSequence(chunkSize: 64 * 1024).reportProgress(reportFn: progress), length: buffer.readableBytes)
let body: AWSHTTPBody = if let progress = newProgress {
.init(asyncSequence: buffer.asyncSequence(chunkSize: 64 * 1024).reportProgress(reportFn: progress), length: buffer.readableBytes)
} else {
body = .init(asyncSequence: buffer.asyncSequence(chunkSize: 64 * 1024), length: buffer.readableBytes)
.init(asyncSequence: buffer.asyncSequence(chunkSize: 64 * 1024), length: buffer.readableBytes)
}
group.addTask {
// Multipart uploads part numbers start at 1 not 0
Expand Down Expand Up @@ -748,11 +746,12 @@ extension S3 {
// from bucket, key and version id from a copySource string
func getBucketKeyVersion(from copySource: String) -> (bucket: String, key: String, versionId: String?)? {
let path: Substring
// drop first slash if it exists
if copySource.first == "/" {
path = copySource.dropFirst()
// drop first slash if it exists
= if copySource.first == "/"
{
copySource.dropFirst()
} else {
path = Substring(copySource)
Substring(copySource)
}
// find first slash
guard let slashIndex = path.firstIndex(of: "/") else { return nil }
Expand Down
4 changes: 2 additions & 2 deletions Sources/Soto/Extensions/STS/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import Glibc
import Darwin.C
#endif

internal enum Environment {
internal static subscript(_ name: String) -> String? {
enum Environment {
static subscript(_ name: String) -> String? {
guard let value = getenv(name) else {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/SotoTests/Services/APIGateway/APIGatewayTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class APIGatewayTests: XCTestCase {
static var restApiId: String!

override class func setUp() {
Self.client = AWSClient(
self.client = AWSClient(
credentialProvider: TestEnvironment.credentialProvider,
middleware: TestEnvironment.middlewares,
logger: TestEnvironment.logger
)
Self.apiGateway = APIGateway(
self.apiGateway = APIGateway(
client: APIGatewayTests.client,
region: .euwest1,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
Expand Down
6 changes: 3 additions & 3 deletions Tests/SotoTests/Services/ApiGatewayV2/APIGatewayV2Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class APIGatewayV2Tests: XCTestCase {

override class func setUp() {
guard !TestEnvironment.isUsingLocalstack else { return }
Self.client = AWSClient(
self.client = AWSClient(
credentialProvider: TestEnvironment.credentialProvider,
middleware: TestEnvironment.middlewares,
logger: TestEnvironment.logger
)
Self.apiGatewayV2 = ApiGatewayV2(
client: Self.client,
self.apiGatewayV2 = ApiGatewayV2(
client: self.client,
region: .euwest1,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
)
Expand Down
4 changes: 2 additions & 2 deletions Tests/SotoTests/Services/CloudTrail/CloudTrailTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class CloudTrailTests: XCTestCase {
static var cloudTrail: CloudTrail!

override class func setUp() {
Self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
Self.cloudTrail = CloudTrail(
self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
self.cloudTrail = CloudTrail(
client: CloudTrailTests.client,
region: .euwest1,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
Expand Down
4 changes: 2 additions & 2 deletions Tests/SotoTests/Services/DynamoDB/DynamoDBTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class DynamoDBTests: XCTestCase {
print("Connecting to AWS")
}

Self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
Self.dynamoDB = DynamoDB(
self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
self.dynamoDB = DynamoDB(
client: DynamoDBTests.client,
region: .useast1,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
Expand Down
4 changes: 2 additions & 2 deletions Tests/SotoTests/Services/Glacier/GlacierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class GlacierTests: XCTestCase {
static var glacier: Glacier!

override class func setUp() {
Self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
Self.glacier = Glacier(
self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
self.glacier = Glacier(
client: GlacierTests.client,
region: .euwest1,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
Expand Down
6 changes: 3 additions & 3 deletions Tests/SotoTests/Services/IAM/IAMTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class IAMTests: XCTestCase {
print("Connecting to AWS")
}

Self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
Self.iam = IAM(
self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
self.iam = IAM(
client: IAMTests.client,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
)
}

override class func tearDown() {
XCTAssertNoThrow(try Self.client.syncShutdown())
XCTAssertNoThrow(try self.client.syncShutdown())
}

/// create SNS topic with supplied name and run supplied closure
Expand Down
8 changes: 4 additions & 4 deletions Tests/SotoTests/Services/Lambda/LambdaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ class LambdaTests: XCTestCase {
print("Connecting to AWS")
}

Self.client = AWSClient(
self.client = AWSClient(
credentialProvider: TestEnvironment.credentialProvider,
middleware: TestEnvironment.middlewares
)
Self.lambda = Lambda(
self.lambda = Lambda(
client: LambdaTests.client,
region: .euwest1,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
).with(middleware: TestEnvironment.middlewares)
Self.iam = IAM(
client: Self.client,
self.iam = IAM(
client: self.client,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
).with(middleware: TestEnvironment.middlewares)

Expand Down
17 changes: 8 additions & 9 deletions Tests/SotoTests/Services/S3/S3Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ class S3Tests: XCTestCase {
print("Connecting to AWS")
}

Self.client = AWSClient(
self.client = AWSClient(
credentialProvider: TestEnvironment.credentialProvider,
middleware: TestEnvironment.middlewares
)
Self.s3 = S3(
client: Self.client,
self.s3 = S3(
client: self.client,
region: .useast1,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
)
Self.randomBytes = self.createRandomBuffer(size: 11 * 1024 * 1024)
self.randomBytes = self.createRandomBuffer(size: 11 * 1024 * 1024)
}

override class func tearDown() {
XCTAssertNoThrow(try Self.client.syncShutdown())
XCTAssertNoThrow(try self.client.syncShutdown())
}

static func createRandomBuffer(size: Int) -> ByteBuffer {
Expand Down Expand Up @@ -124,11 +124,10 @@ class S3Tests: XCTestCase {

func testPutGetObjectWithSpecialName() async throws {
let name = TestEnvironment.generateResourceName()
let filename: String
if TestEnvironment.isUsingLocalstack {
filename = "test $filé+!@£$%^&*()_=-[]{}\\|';:\",./?><~`.txt"
let filename = if TestEnvironment.isUsingLocalstack {
"test $filé+!@£$%^&*()_=-[]{}\\|';:\",./?><~`.txt"
} else {
filename = "test $filé+!@£$%2F%^&*()_=-[]{}\\|';:\",./?><~`.txt"
"test $filé+!@£$%2F%^&*()_=-[]{}\\|';:\",./?><~`.txt"
}
try await self.testPutGetObject(
bucket: name,
Expand Down
8 changes: 4 additions & 4 deletions Tests/SotoTests/Services/SES/SESTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ class SESTests: XCTestCase {
print("Connecting to AWS")
}

Self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
Self.ses = SES(
client: Self.client,
self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
self.ses = SES(
client: self.client,
region: .useast1,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
)
}

override class func tearDown() {
XCTAssertNoThrow(try Self.client.syncShutdown())
XCTAssertNoThrow(try self.client.syncShutdown())
}

// Tests query protocol requests with no body
Expand Down
6 changes: 3 additions & 3 deletions Tests/SotoTests/Services/SNS/SNSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ class SNSTests: XCTestCase {
print("Connecting to AWS")
}

Self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
Self.sns = SNS(
self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
self.sns = SNS(
client: SNSTests.client,
region: .useast1,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
)
}

override class func tearDown() {
XCTAssertNoThrow(try Self.client.syncShutdown())
XCTAssertNoThrow(try self.client.syncShutdown())
}

/// create SNS topic with supplied name and run supplied closure
Expand Down
6 changes: 3 additions & 3 deletions Tests/SotoTests/Services/SQS/SQSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ class SQSTests: XCTestCase {
print("Connecting to AWS")
}

Self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
Self.sqs = SQS(
self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
self.sqs = SQS(
client: SQSTests.client,
region: .useast1,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
)
}

override class func tearDown() {
XCTAssertNoThrow(try Self.client.syncShutdown())
XCTAssertNoThrow(try self.client.syncShutdown())
}

/// create SQS queue with supplied name and run supplied closure
Expand Down
6 changes: 3 additions & 3 deletions Tests/SotoTests/Services/SSM/SSMTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ class SSMTests: XCTestCase {
print("Connecting to AWS")
}

Self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
Self.ssm = SSM(
self.client = AWSClient(credentialProvider: TestEnvironment.credentialProvider, middleware: TestEnvironment.middlewares)
self.ssm = SSM(
client: SSMTests.client,
region: .useast1,
endpoint: TestEnvironment.getEndPoint(environment: "LOCALSTACK_ENDPOINT")
)
}

override class func tearDown() {
XCTAssertNoThrow(try Self.client.syncShutdown())
XCTAssertNoThrow(try self.client.syncShutdown())
}

/// put parameter, test it, delete it
Expand Down
4 changes: 2 additions & 2 deletions Tests/SotoTests/test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension Task where Failure == Error {
///
/// - Note: This function blocks the thread until the given operation is finished. The caller is responsible for managing multithreading.
@available(*, noasync, message: "synchronous() can block indefinitely")
internal func syncAwait() throws -> Success {
func syncAwait() throws -> Success {
let semaphore = DispatchSemaphore(value: 0)
let resultBox = SendableBox<Result<Success, Failure>>()

Expand All @@ -56,7 +56,7 @@ extension Task where Failure == Never {
///
/// - Note: This function blocks the thread until the given operation is finished. The caller is responsible for managing multithreading.
@available(*, noasync, message: "synchronous() can block indefinitely")
internal func syncAwait() -> Success {
func syncAwait() -> Success {
let semaphore = DispatchSemaphore(value: 0)
let resultBox = SendableBox<Success>()

Expand Down

0 comments on commit f2c05b0

Please sign in to comment.