Skip to content

Commit

Permalink
STITCH-1818 Expose StitchServiceClient and add AWSServiceClient (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchel authored Aug 2, 2018
1 parent a15b13f commit 6f0e519
Show file tree
Hide file tree
Showing 74 changed files with 1,710 additions and 297 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ Core/StitchCoreTestUtils/Package.resolved
Core/StitchCoreTestUtils/.build/
Core/StitchCoreTestUtils/*.xcodeproj/

Core/Services/StitchCoreAWSService/Packages/
Core/Services/StitchCoreAWSService/Package.pins
Core/Services/StitchCoreAWSService/Package.resolved
Core/Services/StitchCoreAWSService/.build/
Core/Services/StitchCoreAWSService/StitchCoreAWSService.xcodeproj/

Core/Services/StitchCoreAWSS3Service/Packages/
Core/Services/StitchCoreAWSS3Service/Package.pins
Core/Services/StitchCoreAWSS3Service/Package.resolved
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Foundation

/**
* The result of an AWS S3 put object request.
* The result of an AWS S3 put object request. (Deprecated)
*/
@available(*, deprecated, message: "Use the generic AWS service instead")
public struct AWSS3PutObjectResult: Decodable {
/**
* The location of the object.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Foundation

/**
* The result of an AWS S3 sign policy request.
* The result of an AWS S3 sign policy request. (Deprecated)
*/
@available(*, deprecated, message: "Use the generic AWS service instead")
public struct AWSS3SignPolicyResult: Decodable {
/**
* The description of the policy that has been signed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import MongoSwift
import StitchCoreSDK


@available(*, deprecated, message: "Use AWSServiceClient instead")
public final class CoreAWSS3ServiceClient {
private let service: CoreStitchServiceClient

Expand Down Expand Up @@ -41,7 +41,7 @@ public final class CoreAWSS3ServiceClient {
args[bodyKey] = Binary.init(data: dataVal, subtype: .binary)
}

return try self.service.callFunctionInternal(
return try self.service.callFunction(
withName: "put",
withArgs: [args],
withRequestTimeout: timeout
Expand Down Expand Up @@ -107,7 +107,7 @@ public final class CoreAWSS3ServiceClient {
"contentType": contentType
]

return try service.callFunctionInternal(
return try service.callFunction(
withName: "signPolicy", withArgs: [args], withRequestTimeout: nil)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class CoreAWSS3ServiceClientUnitTests: XCTestCase {

let expectedLocation = "awsLocation"

service.callFunctionInternalWithDecodingMock.doReturn(
service.callFunctionWithDecodingMock.doReturn(
result: AWSS3PutObjectResult.init(location: expectedLocation),
forArg1: .any,
forArg2: .any,
Expand All @@ -35,7 +35,7 @@ final class CoreAWSS3ServiceClientUnitTests: XCTestCase {

XCTAssertEqual(expectedLocation, result.location)

let (funcNameArg, funcArgsArg, _) = service.callFunctionInternalWithDecodingMock.capturedInvocations.last!
let (funcNameArg, funcArgsArg, _) = service.callFunctionWithDecodingMock.capturedInvocations.last!

XCTAssertEqual("put", funcNameArg)
XCTAssertEqual(1, funcArgsArg.count)
Expand All @@ -51,7 +51,7 @@ final class CoreAWSS3ServiceClientUnitTests: XCTestCase {
XCTAssertEqual(expectedArgs, funcArgsArg[0] as? Document)

// should pass along errors
service.callFunctionInternalWithDecodingMock.doThrow(
service.callFunctionWithDecodingMock.doThrow(
error: StitchError.serviceError(withMessage: "", withServiceErrorCode: .unknown),
forArg1: .any,
forArg2: .any,
Expand Down Expand Up @@ -84,7 +84,7 @@ final class CoreAWSS3ServiceClientUnitTests: XCTestCase {

let expectedLocation = "awsLocation"

service.callFunctionInternalWithDecodingMock.doReturn(
service.callFunctionWithDecodingMock.doReturn(
result: AWSS3PutObjectResult.init(location: expectedLocation),
forArg1: .any,
forArg2: .any,
Expand All @@ -101,7 +101,7 @@ final class CoreAWSS3ServiceClientUnitTests: XCTestCase {

XCTAssertEqual(expectedLocation, result.location)

let (funcNameArg, funcArgsArg, _) = service.callFunctionInternalWithDecodingMock.capturedInvocations.last!
let (funcNameArg, funcArgsArg, _) = service.callFunctionWithDecodingMock.capturedInvocations.last!

XCTAssertEqual("put", funcNameArg)
XCTAssertEqual(1, funcArgsArg.count)
Expand All @@ -117,7 +117,7 @@ final class CoreAWSS3ServiceClientUnitTests: XCTestCase {
XCTAssertEqual(expectedArgs, funcArgsArg[0] as? Document)

// should pass along errors
service.callFunctionInternalWithDecodingMock.doThrow(
service.callFunctionWithDecodingMock.doThrow(
error: StitchError.serviceError(withMessage: "", withServiceErrorCode: .unknown),
forArg1: .any,
forArg2: .any,
Expand Down Expand Up @@ -150,7 +150,7 @@ final class CoreAWSS3ServiceClientUnitTests: XCTestCase {

let expectedLocation = "awsLocation"

service.callFunctionInternalWithDecodingMock.doReturn(
service.callFunctionWithDecodingMock.doReturn(
result: AWSS3PutObjectResult.init(location: expectedLocation),
forArg1: .any,
forArg2: .any,
Expand All @@ -167,7 +167,7 @@ final class CoreAWSS3ServiceClientUnitTests: XCTestCase {

XCTAssertEqual(expectedLocation, result.location)

let (funcNameArg, funcArgsArg, _) = service.callFunctionInternalWithDecodingMock.capturedInvocations.last!
let (funcNameArg, funcArgsArg, _) = service.callFunctionWithDecodingMock.capturedInvocations.last!

XCTAssertEqual("put", funcNameArg)
XCTAssertEqual(1, funcArgsArg.count)
Expand All @@ -183,7 +183,7 @@ final class CoreAWSS3ServiceClientUnitTests: XCTestCase {
XCTAssertEqual(expectedArgs, funcArgsArg[0] as? Document)

// should pass along errors
service.callFunctionInternalWithDecodingMock.doThrow(
service.callFunctionWithDecodingMock.doThrow(
error: StitchError.serviceError(withMessage: "", withServiceErrorCode: .unknown),
forArg1: .any,
forArg2: .any,
Expand Down Expand Up @@ -219,7 +219,7 @@ final class CoreAWSS3ServiceClientUnitTests: XCTestCase {
let expectedDate = "01-101-2012"
let expectedCredential = "someCredential"

service.callFunctionInternalWithDecodingMock.doReturn(
service.callFunctionWithDecodingMock.doReturn(
result: AWSS3SignPolicyResult.init(policy: expectedPolicy,
signature: expectedSignature,
algorithm: expectedAlgorithm,
Expand All @@ -236,7 +236,7 @@ final class CoreAWSS3ServiceClientUnitTests: XCTestCase {
XCTAssertEqual(expectedDate, result.date)
XCTAssertEqual(expectedCredential, result.credential)

let (funcNameArg, funcArgsArg, _) = service.callFunctionInternalWithDecodingMock.capturedInvocations.last!
let (funcNameArg, funcArgsArg, _) = service.callFunctionWithDecodingMock.capturedInvocations.last!

XCTAssertEqual("signPolicy", funcNameArg)
XCTAssertEqual(1, funcArgsArg.count)
Expand All @@ -251,7 +251,7 @@ final class CoreAWSS3ServiceClientUnitTests: XCTestCase {
XCTAssertEqual(expectedArgs, funcArgsArg[0] as? Document)

// should pass along errors
service.callFunctionInternalWithDecodingMock.doThrow(
service.callFunctionWithDecodingMock.doThrow(
error: StitchError.serviceError(withMessage: "", withServiceErrorCode: .unknown),
forArg1: .any,
forArg2: .any,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Foundation

/**
* The result of an AWS SES send request.
* The result of an AWS SES send request. (Deprecated)
*/
@available(*, deprecated, message: "Use the generic AWS service instead")
public struct AWSSESSendResult: Decodable {
/**
* The id of the sent message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Foundation
import MongoSwift
import StitchCoreSDK

@available(*, deprecated, message: "Use AWSServiceClient instead")
public final class CoreAWSSESServiceClient {
private let service: CoreStitchServiceClient

Expand All @@ -20,6 +21,6 @@ public final class CoreAWSSESServiceClient {
"body": body
]

return try self.service.callFunctionInternal(withName: "send", withArgs: [args], withRequestTimeout: nil)
return try self.service.callFunction(withName: "send", withArgs: [args], withRequestTimeout: nil)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class CoreAWSSESServiceClientUnitTests: XCTestCase {

let expectedMessageID = "yourMessageID"

service.callFunctionInternalWithDecodingMock.doReturn(
service.callFunctionWithDecodingMock.doReturn(
result: AWSSESSendResult.init(messageID: expectedMessageID),
forArg1: .any,
forArg2: .any,
Expand All @@ -27,7 +27,7 @@ final class CoreAWSSESServiceClientUnitTests: XCTestCase {

XCTAssertEqual(expectedMessageID, result.messageID)

let (funcNameArg, funcArgsArg, _) = service.callFunctionInternalWithDecodingMock.capturedInvocations.last!
let (funcNameArg, funcArgsArg, _) = service.callFunctionWithDecodingMock.capturedInvocations.last!

XCTAssertEqual("send", funcNameArg)
XCTAssertEqual(1, funcArgsArg.count)
Expand All @@ -42,7 +42,7 @@ final class CoreAWSSESServiceClientUnitTests: XCTestCase {
XCTAssertEqual(expectedArgs, funcArgsArg[0] as? Document)

// should pass along errors
service.callFunctionInternalWithDecodingMock.doThrow(
service.callFunctionWithDecodingMock.doThrow(
error: StitchError.serviceError(withMessage: "", withServiceErrorCode: .unknown),
forArg1: .any,
forArg2: .any,
Expand Down
6 changes: 6 additions & 0 deletions Core/Services/StitchCoreAWSService/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
vendor
dist
21 changes: 21 additions & 0 deletions Core/Services/StitchCoreAWSService/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
all: prepare build
git:
git init
git add .
git commit --allow-empty -m "init"
lint:
swiftlint
clean:
swift package --build-path ../../../.build clean
build:
swift build --build-path ../../../.build -Xcc -I../../../vendor/MobileSDKs/include/libbson-1.0/ -Xcc -I../../../vendor/MobileSDKs/include/libmongoc-1.0
resolve:
swift package --build-path ../../../.build resolve
update:
swift package --build-path ../../../.build update
test:
# temporary until a fix is in for .brew dependency for libmongoc
xcodebuild test -workspace ../../../Stitch.xcworkspace/ -scheme StitchCoreAWSService-Package -configuration Debug -destination "platform=iOS Simulator,name=iPhone 7,OS=11.2"
project:
swift package generate-xcodeproj --xcconfig-overrides StitchCoreAWSService.xcconfig
prepare: git resolve project
22 changes: 22 additions & 0 deletions Core/Services/StitchCoreAWSService/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// swift-tools-version:4.0
import PackageDescription

let package = Package(
name: "StitchCoreAWSService",
products: [
.library(
name: "StitchCoreAWSService",
targets: ["StitchCoreAWSService"]),
],
dependencies: [
.package(url: "../../StitchCoreSDK", .branch("master"))
],
targets: [
.target(
name: "StitchCoreAWSService",
dependencies: ["StitchCoreSDK"]),
.testTarget(
name: "StitchCoreAWSServiceTests",
dependencies: ["StitchCoreAWSService", "StitchCoreSDKMocks"]),
]
)
3 changes: 3 additions & 0 deletions Core/Services/StitchCoreAWSService/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# StitchCoreAWSService

A description of this package.
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import Foundation
import MongoSwift

/**
* An error that the `AWSRequestBuilder` can throw if it is missing certain configuration properties.
*/
public enum AWSRequestBuilderError: Error {
case missingService
case missingAction
}

/**
* An AWSRequest encapsulates the details of an AWS request over the AWS service.
*/
public struct AWSRequest {
/**
* The service that the action in the request will be performed against.
*/
public let service: String

/**
* The action within the AWS service to perform.
*/
public let action: String

/**
* The region that service in this request should be scoped to.
*/
public let region: String?

/**
* The arguments that will be used in the action.
*/
public let arguments: Document
}

/**
* A builder that can build an `AWSRequest`
*/
public class AWSRequestBuilder {
internal var service: String?
internal var action: String?
internal var region: String?
internal var arguments: Document?

/**
* Initializes a new builder for an AWS request.
*/
public init() { }

/**
* Sets the service that the action in the request will be performed against.
*/
@discardableResult
public func with(service: String) -> Self {
self.service = service
return self
}

/**
* Sets the action within the AWS service to perform.
*/
@discardableResult
public func with(action: String) -> Self {
self.action = action
return self
}

/**
* Sets the region that service in this request should be scoped to.
*/
@discardableResult
public func with(region: String) -> Self {
self.region = region
return self
}

/**
* Sets the arguments that will be used in the action.
*/
@discardableResult
public func with(arguments: Document) -> Self {
self.arguments = arguments
return self
}

/**
* Builds, validates, and returns the `AWSRequest`.
*/
public func build() throws -> AWSRequest {
guard let service = service, service != "" else {
throw AWSRequestBuilderError.missingService
}

guard let action = action, action != "" else {
throw AWSRequestBuilderError.missingAction
}

return AWSRequest.init(
service: service,
action: action,
region: region,
arguments: arguments ?? Document.init()
)
}
}
Loading

0 comments on commit 6f0e519

Please sign in to comment.