Skip to content

Commit

Permalink
Merge pull request #8 from makeen-project/main
Browse files Browse the repository at this point in the history
AWS SDK 0.46.0 hotfix related to StaticAWSCredentialIdentityResolver
  • Loading branch information
ejboucher authored Jun 25, 2024
2 parents 6310a2e + b22148d commit ab89a0b
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 37 deletions.
30 changes: 28 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# OSX
#
.DS_Store
.swiftpm/
Tests/AmazonLocationiOSAuthSDKTests/TestConfig.plist

# Xcode
#
.build
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
*.xcworkspacedata
/ios/Pods/

# Idea
#
.idea
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/awslabs/aws-sdk-swift",
"state" : {
"revision" : "14da8fcf13246e4f46cadc7a5ce291d839f3225d",
"version" : "0.45.0"
"branch" : "0.46.0",
"revision" : "3c20e0be8c8246de8b8e04372404ef1f90be71b6"
}
},
{
Expand All @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/smithy-lang/smithy-swift",
"state" : {
"revision" : "a30764bf83af6876a3956aa394c838dcf2975cb3",
"version" : "0.50.0"
"revision" : "b2322a067f85c230f17c80be8a67dd543454b081",
"version" : "0.51.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let package = Package(
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/evgenyneu/keychain-swift.git", from: "20.0.0"),
.package(url: "https://github.com/awslabs/aws-sdk-swift", .upToNextMajor(from: "0.44.0"))
.package(url: "https://github.com/awslabs/aws-sdk-swift", branch: "0.46.0")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
12 changes: 6 additions & 6 deletions Sources/AmazonLocationiOSAuthSDK/Auth/AuthHelper.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import Foundation

public class AuthHelper {
@objc public class AuthHelper: NSObject {

private var locationCredentialsProvider: LocationCredentialsProvider?

public init() {
@objc public override init() {
}

public func authenticateWithCognitoIdentityPool(identityPoolId: String) async throws -> LocationCredentialsProvider? {
@objc public func authenticateWithCognitoIdentityPool(identityPoolId: String) async throws -> LocationCredentialsProvider? {
let region = AmazonLocationRegion.toRegionString(identityPoolId: identityPoolId)
locationCredentialsProvider = try? await authenticateWithCognitoIdentityPoolAndRegion(identityPoolId: identityPoolId, region: region)
return locationCredentialsProvider
}

public func authenticateWithCognitoIdentityPool(identityPoolId: String, region: String) async throws -> LocationCredentialsProvider? {
@objc public func authenticateWithCognitoIdentityPool(identityPoolId: String, region: String) async throws -> LocationCredentialsProvider? {
locationCredentialsProvider = try? await authenticateWithCognitoIdentityPoolAndRegion(identityPoolId: identityPoolId, region: region)
return locationCredentialsProvider
}
Expand All @@ -25,15 +25,15 @@ public class AuthHelper {
return credentialProvider
}

public func authenticateWithApiKey(apiKey: String, region: String) -> LocationCredentialsProvider {
@objc public func authenticateWithApiKey(apiKey: String, region: String) -> LocationCredentialsProvider {
let credentialProvider = LocationCredentialsProvider(region: region, apiKey: apiKey)
credentialProvider.setAPIKey(apiKey: apiKey)
credentialProvider.setRegion(region: region)
locationCredentialsProvider = credentialProvider
return credentialProvider
}

public func getLocationClient() -> AmazonLocationClient?
@objc public func getLocationClient() -> AmazonLocationClient?
{
guard let locationCredentialsProvider = self.locationCredentialsProvider else {
return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import AWSLocation
import AWSClientRuntime
import SmithyIdentity
import SmithyIdentityAPI

public enum HTTPMethod: String {
Expand Down Expand Up @@ -34,17 +34,17 @@ public struct HTTPHeaders {
}
}

public class AmazonLocationClient {
@objc public class AmazonLocationClient: NSObject {
public let locationProvider: LocationCredentialsProvider
public var locationClient: LocationClient?

public init(locationCredentialsProvider: LocationCredentialsProvider) {
@objc public init(locationCredentialsProvider: LocationCredentialsProvider) {
self.locationProvider = locationCredentialsProvider
}

public func initialiseLocationClient() async throws {
@objc public func initialiseLocationClient() async throws {
if let credentials = locationProvider.getCognitoProvider()?.getCognitoCredentials() {
let resolver:AWSClientRuntime.StaticAWSCredentialIdentityResolver? = try StaticAWSCredentialIdentityResolver(AWSCredentialIdentity(accessKey: credentials.accessKeyId, secret: credentials.secretKey, expiration: credentials.expiration, sessionToken: credentials.sessionToken))
let resolver: StaticAWSCredentialIdentityResolver? = try StaticAWSCredentialIdentityResolver(AWSCredentialIdentity(accessKey: credentials.accessKeyId, secret: credentials.secretKey, expiration: credentials.expiration, sessionToken: credentials.sessionToken))

let clientConfig = try await LocationClient.LocationClientConfiguration(awsCredentialIdentityResolver: resolver, region: locationProvider.getRegion(), signingRegion: locationProvider.getRegion())
self.locationClient = LocationClient(config: clientConfig)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation

public class AmazonLocationApiCredentialsProvider {
@objc public class AmazonLocationApiCredentialsProvider: NSObject {
internal var apiKey: String?
internal var region: String?

public init(apiKey: String, region: String?) {
@objc public init(apiKey: String, region: String?) {
self.apiKey = apiKey
self.region = region
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Foundation

public class AmazonLocationCognitoCredentialsProvider {
@objc public class AmazonLocationCognitoCredentialsProvider: NSObject {
internal var identityPoolId: String?
internal var region: String?
private var cognitoCredentials: CognitoCredentials?

public init(identityPoolId: String, region: String?) {
@objc public init(identityPoolId: String, region: String?) {
self.identityPoolId = identityPoolId
self.region = region
}
Expand All @@ -21,15 +21,15 @@ public class AmazonLocationCognitoCredentialsProvider {
return self.cognitoCredentials
}

public func refreshCognitoCredentialsIfExpired() async throws {
@objc public func refreshCognitoCredentialsIfExpired() async throws {
if let savedCredentials = getCognitoCredentials(), savedCredentials.expiration! > Date() {
cognitoCredentials = savedCredentials
} else {
try? await refreshCognitoCredentials()
}
}

public func refreshCognitoCredentials() async throws {
@objc public func refreshCognitoCredentials() async throws {
if let identityPoolId = self.identityPoolId, let region = self.region, let cognitoCredentials = try await CognitoCredentialsProvider.generateCognitoCredentials(identityPoolId: identityPoolId, region: region) {
setCognitoCredentials(cognitoCredentials: cognitoCredentials)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
public class AmazonLocationRegion {
public static func toRegionString(identityPoolId: String) -> String {
import Foundation

@objc public class AmazonLocationRegion: NSObject {
@objc public static func toRegionString(identityPoolId: String) -> String {
return identityPoolId.components(separatedBy: ":").first ?? identityPoolId
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
public class LocationCredentialsProvider {
import Foundation

@objc public class LocationCredentialsProvider: NSObject {
private var cognitoProvider: AmazonLocationCognitoCredentialsProvider?
private var apiProvider: AmazonLocationApiCredentialsProvider?
private var region: String?

public init(region: String, identityPoolId: String){
@objc public init(region: String, identityPoolId: String){
self.region = region
self.cognitoProvider = AmazonLocationCognitoCredentialsProvider(identityPoolId: identityPoolId, region: region)
}

public init(region: String, apiKey: String){
@objc public init(region: String, apiKey: String){
self.region = region
self.apiProvider = AmazonLocationApiCredentialsProvider(apiKey: apiKey, region: region)
}

public func getCognitoProvider() -> AmazonLocationCognitoCredentialsProvider? {
@objc public func getCognitoProvider() -> AmazonLocationCognitoCredentialsProvider? {
return cognitoProvider
}

public func getApiProvider() -> AmazonLocationApiCredentialsProvider? {
@objc public func getApiProvider() -> AmazonLocationApiCredentialsProvider? {
return apiProvider
}

public func getIdentityPoolId() -> String? {
@objc public func getIdentityPoolId() -> String? {
return self.cognitoProvider?.identityPoolId
}

public func getAPIKey() -> String? {
@objc public func getAPIKey() -> String? {
return self.apiProvider?.apiKey
}

public func getRegion() -> String? {
@objc public func getRegion() -> String? {
return region
}

Expand Down
5 changes: 2 additions & 3 deletions Tests/AmazonLocationiOSAuthSDKTests/AuthHelperTests.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import XCTest

import Foundation
@testable import AmazonLocationiOSAuthSDK
import AWSLocation

final class AuthHelperTests: XCTestCase {

func readTestConfig() -> [String: String] {
// Implement reading from your chosen config file. This is an example for a plist.
guard let plistURL = Bundle.module.url(forResource: "TestConfig", withExtension: "plist"),
guard let plistURL = Foundation.Bundle.module.url(forResource: "TestConfig", withExtension: "plist"),
let plistData = try? Data(contentsOf: plistURL) else {
fatalError("Test configuration file not found.")
}
Expand Down

0 comments on commit ab89a0b

Please sign in to comment.