diff --git a/.github/workflows/build-release.yaml b/.github/workflows/build-release.yaml index a8062ae..f260741 100644 --- a/.github/workflows/build-release.yaml +++ b/.github/workflows/build-release.yaml @@ -20,8 +20,11 @@ jobs: brew install sunshinejr/formulae/pouch - name: Generate Secrets.swift env: - CLOUDINARY_CLOUD_NAME: ${{ secrets.CLOUDINARY_CLOUD_NAME }} - CLOUDINARY_UPLOAD_PRESET_NAME: ${{ secrets.CLOUDINARY_UPLOAD_PRESET_NAME }} + AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }} + AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }} + AWS_BUCKET_NAME: ${{ vars.AWS_BUCKET_NAME }} + AWS_BUCKET_REGION: ${{ vars.AWS_BUCKET_REGION }} + AWS_BUCKET_PREFIX: ${{ vars.AWS_BUCKET_PREFIX }} PROTECT_EARTH_API_TOKEN: ${{ secrets.PROTECT_EARTH_API_TOKEN }} PROTECT_EARTH_API_BASE_URL: ${{ secrets.PROTECT_EARTH_API_BASE_URL }} PROTECT_EARTH_ENV_NAME: ${{ secrets.PROTECT_EARTH_ENV_NAME }} @@ -51,8 +54,11 @@ jobs: brew install sunshinejr/formulae/pouch - name: Generate Secrets.swift env: - CLOUDINARY_CLOUD_NAME: ${{ secrets.CLOUDINARY_CLOUD_NAME }} - CLOUDINARY_UPLOAD_PRESET_NAME: ${{ secrets.CLOUDINARY_UPLOAD_PRESET_NAME }} + AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }} + AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }} + AWS_BUCKET_NAME: ${{ vars.AWS_BUCKET_NAME }} + AWS_BUCKET_REGION: ${{ vars.AWS_BUCKET_REGION }} + AWS_BUCKET_PREFIX: ${{ vars.AWS_BUCKET_PREFIX }} PROTECT_EARTH_API_TOKEN: ${{ secrets.PROTECT_EARTH_API_TOKEN }} PROTECT_EARTH_API_BASE_URL: ${{ secrets.PROTECT_EARTH_API_BASE_URL }} PROTECT_EARTH_ENV_NAME: ${{ secrets.PROTECT_EARTH_ENV_NAME }} @@ -120,8 +126,11 @@ jobs: brew install sunshinejr/formulae/pouch - name: Generate Secrets.swift env: - CLOUDINARY_CLOUD_NAME: ${{ secrets.CLOUDINARY_CLOUD_NAME }} - CLOUDINARY_UPLOAD_PRESET_NAME: ${{ secrets.CLOUDINARY_UPLOAD_PRESET_NAME }} + AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }} + AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }} + AWS_BUCKET_NAME: ${{ vars.AWS_BUCKET_NAME }} + AWS_BUCKET_REGION: ${{ vars.AWS_BUCKET_REGION }} + AWS_BUCKET_PREFIX: ${{ vars.AWS_BUCKET_PREFIX }} PROTECT_EARTH_API_TOKEN: ${{ secrets.PROTECT_EARTH_API_TOKEN }} PROTECT_EARTH_API_BASE_URL: ${{ secrets.PROTECT_EARTH_API_BASE_URL }} PROTECT_EARTH_ENV_NAME: ${{ secrets.PROTECT_EARTH_ENV_NAME }} diff --git a/.pouch.yml b/.pouch.yml index c8a0e6b..134e14b 100644 --- a/.pouch.yml +++ b/.pouch.yml @@ -1,5 +1,7 @@ secrets: - AWS_BUCKET_NAME +- AWS_BUCKET_REGION +- AWS_BUCKET_PREFIX - AWS_ACCESS_KEY - AWS_SECRET_KEY - PROTECT_EARTH_API_TOKEN diff --git a/Tree Tracker.xcodeproj/project.pbxproj b/Tree Tracker.xcodeproj/project.pbxproj index 75a7bd6..8eaa168 100644 --- a/Tree Tracker.xcodeproj/project.pbxproj +++ b/Tree Tracker.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 52; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -101,8 +101,8 @@ 9D2B454F2944F54000B09C84 /* LocationWarningOverlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D2B454E2944F54000B09C84 /* LocationWarningOverlayView.swift */; }; 9D2DB5F629606B220040B1DB /* UploadedTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D2DB5F529606B220040B1DB /* UploadedTree.swift */; }; 9D36C7EB2A22950B00E04552 /* AWSS3Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D36C7EA2A22950B00E04552 /* AWSS3Configuration.swift */; }; - 9D3C323729F420C800462558 /* AWSCore in Frameworks */ = {isa = PBXBuildFile; productRef = 9D3C323629F420C800462558 /* AWSCore */; }; - 9D3C323929F420C800462558 /* AWSS3 in Frameworks */ = {isa = PBXBuildFile; productRef = 9D3C323829F420C800462558 /* AWSS3 */; }; + 9D375F912AC8873C009AF2D2 /* AWSCore in Frameworks */ = {isa = PBXBuildFile; productRef = 9D375F902AC8873C009AF2D2 /* AWSCore */; }; + 9D375F932AC8873C009AF2D2 /* AWSS3 in Frameworks */ = {isa = PBXBuildFile; productRef = 9D375F922AC8873C009AF2D2 /* AWSS3 */; }; 9D3C323B29F5BDEA00462558 /* UploadCompletionHolder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D3C323A29F5BDEA00462558 /* UploadCompletionHolder.swift */; }; 9D47D97F286F293000F7B92F /* ProtectEarthSupervisor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D47D97E286F293000F7B92F /* ProtectEarthSupervisor.swift */; }; 9D47D982286F29E100F7B92F /* ProtectEarthCodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D47D981286F29E100F7B92F /* ProtectEarthCodableTests.swift */; }; @@ -294,8 +294,8 @@ 85A0EF7F25A226D9003CE744 /* GRDB in Frameworks */, 85B83A0D25B87C0D0008E167 /* BSImagePicker in Frameworks */, 9DCC548C28073F0A00CF67AA /* Resolver in Frameworks */, - 9D3C323929F420C800462558 /* AWSS3 in Frameworks */, - 9D3C323729F420C800462558 /* AWSCore in Frameworks */, + 9D375F932AC8873C009AF2D2 /* AWSS3 in Frameworks */, + 9D375F912AC8873C009AF2D2 /* AWSCore in Frameworks */, 9D01D566285CD2E50009F753 /* RollbarSwift in Frameworks */, 9D01D564285CD2E50009F753 /* RollbarNotifier in Frameworks */, 85A0EF8325A2271C003CE744 /* Alamofire in Frameworks */, @@ -666,8 +666,8 @@ 9D01D561285CD2E50009F753 /* RollbarCommon */, 9D01D563285CD2E50009F753 /* RollbarNotifier */, 9D01D565285CD2E50009F753 /* RollbarSwift */, - 9D3C323629F420C800462558 /* AWSCore */, - 9D3C323829F420C800462558 /* AWSS3 */, + 9D375F902AC8873C009AF2D2 /* AWSCore */, + 9D375F922AC8873C009AF2D2 /* AWSS3 */, ); productName = "Tree Tracker"; productReference = 853ABD522596144900144B0D /* Tree Tracker.app */; @@ -708,7 +708,7 @@ 85B83A0B25B87C0D0008E167 /* XCRemoteSwiftPackageReference "BSImagePicker" */, 9DCC548A28073F0A00CF67AA /* XCRemoteSwiftPackageReference "Resolver" */, 9D01D560285CD2E50009F753 /* XCRemoteSwiftPackageReference "rollbar-apple" */, - 9D3C323529F420C800462558 /* XCRemoteSwiftPackageReference "aws-sdk-ios-spm" */, + 9D375F8F2AC8873C009AF2D2 /* XCRemoteSwiftPackageReference "aws-sdk-ios-spm" */, ); productRefGroup = 853ABD532596144900144B0D /* Products */; projectDirPath = ""; @@ -1073,7 +1073,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = K5RUKV288P; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = K5RUKV288P; INFOPLIST_FILE = "Tree Tracker/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 15.0; @@ -1185,12 +1185,12 @@ minimumVersion = 2.0.0; }; }; - 9D3C323529F420C800462558 /* XCRemoteSwiftPackageReference "aws-sdk-ios-spm" */ = { + 9D375F8F2AC8873C009AF2D2 /* XCRemoteSwiftPackageReference "aws-sdk-ios-spm" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/aws-amplify/aws-sdk-ios-spm"; requirement = { kind = upToNextMinorVersion; - minimumVersion = 2.30.0; + minimumVersion = 2.33.0; }; }; 9DCC548A28073F0A00CF67AA /* XCRemoteSwiftPackageReference "Resolver" */ = { @@ -1234,14 +1234,14 @@ package = 9D01D560285CD2E50009F753 /* XCRemoteSwiftPackageReference "rollbar-apple" */; productName = RollbarSwift; }; - 9D3C323629F420C800462558 /* AWSCore */ = { + 9D375F902AC8873C009AF2D2 /* AWSCore */ = { isa = XCSwiftPackageProductDependency; - package = 9D3C323529F420C800462558 /* XCRemoteSwiftPackageReference "aws-sdk-ios-spm" */; + package = 9D375F8F2AC8873C009AF2D2 /* XCRemoteSwiftPackageReference "aws-sdk-ios-spm" */; productName = AWSCore; }; - 9D3C323829F420C800462558 /* AWSS3 */ = { + 9D375F922AC8873C009AF2D2 /* AWSS3 */ = { isa = XCSwiftPackageProductDependency; - package = 9D3C323529F420C800462558 /* XCRemoteSwiftPackageReference "aws-sdk-ios-spm" */; + package = 9D375F8F2AC8873C009AF2D2 /* XCRemoteSwiftPackageReference "aws-sdk-ios-spm" */; productName = AWSS3; }; 9D5CDBD427BBB7D2007D4F0A /* Alamofire */ = { diff --git a/Tree Tracker.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Tree Tracker.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 1636e7b..0a0e528 100644 --- a/Tree Tracker.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Tree Tracker.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/aws-amplify/aws-sdk-ios-spm", "state" : { - "revision" : "51d99d74be7249ac6444581bd1e394fb60ea86a3", - "version" : "2.30.4" + "revision" : "ca31418963a90bac80538e13f6b7af87ea14d279", + "version" : "2.33.4" } }, { diff --git a/Tree Tracker/AppDelegate+Injection.swift b/Tree Tracker/AppDelegate+Injection.swift index 9fef574..8db0675 100644 --- a/Tree Tracker/AppDelegate+Injection.swift +++ b/Tree Tracker/AppDelegate+Injection.swift @@ -2,6 +2,7 @@ import Resolver import Photos import UIKit import AWSS3 +import AWSCore extension Resolver: ResolverRegistering { @@ -20,7 +21,9 @@ extension Resolver: ResolverRegistering { register { UIScreenLockManager() } register { PHCachingImageManager() } register { RecentSpeciesManager(defaults: resolve(), strategy: .todayUsedSpecies) } - register { AWSS3Configuration(accessKey: Secrets.awsAccessKey, secretKey: Secrets.awsSecretKey, region: .EUWest1) } + register { AWSS3Configuration(accessKey: Secrets.awsAccessKey, + secretKey: Secrets.awsSecretKey, + region: Secrets.awsBucketRegion.aws_regionTypeValue()) } // MARK: Services register { ProtectEarthSessionFactory(baseUrl: Constants.Http.protectEarthApiBaseUrl, diff --git a/Tree Tracker/Screens/Settings/SettingsController.swift b/Tree Tracker/Screens/Settings/SettingsController.swift index 6a09595..865d943 100644 --- a/Tree Tracker/Screens/Settings/SettingsController.swift +++ b/Tree Tracker/Screens/Settings/SettingsController.swift @@ -13,7 +13,10 @@ class SettingsController: UITableViewController { private var entityTypes = ["Sites", "Supervisors", "Species"] private var apiProperties = [Constants.Http.protectEarthApiBaseUrl, - Constants.Http.protectEarthEnvironmentName] + Constants.Http.protectEarthEnvironmentName, + Secrets.awsBucketName, + "\(Secrets.awsAccessKey.prefix(4))************\(Secrets.awsAccessKey.suffix(4))", + Secrets.awsBucketRegion] override func viewDidLoad() { super.viewDidLoad() diff --git a/Tree Tracker/Services/ProtectEarth/ProtectEarthTreeService.swift b/Tree Tracker/Services/ProtectEarth/ProtectEarthTreeService.swift index 3bbafb3..6618791 100644 --- a/Tree Tracker/Services/ProtectEarth/ProtectEarthTreeService.swift +++ b/Tree Tracker/Services/ProtectEarth/ProtectEarthTreeService.swift @@ -102,7 +102,7 @@ class ProtectEarthTreeService: TreeService { transferUtility.uploadData(data, bucket: Secrets.awsBucketName, - key: tree.treeId, + key: "\(Secrets.awsBucketPrefix)/\(tree.treeId)", contentType: "image/jpeg", expression: expression, completionHandler: completionHolder.completionHandler diff --git a/Tree Tracker/Utilities/UploadCompletionHolder.swift b/Tree Tracker/Utilities/UploadCompletionHolder.swift index 629fc84..fd40756 100644 --- a/Tree Tracker/Utilities/UploadCompletionHolder.swift +++ b/Tree Tracker/Utilities/UploadCompletionHolder.swift @@ -16,7 +16,8 @@ class UploadCompletionHolder { self.completionHandler = { (task, error) -> Void in if let error = error { - completion(.failure(.remoteError(errorCode: 243, errorMessage: error.localizedDescription))) + let responseCode = task.response?.statusCode.description ?? "???" + completion(.failure(.remoteError(errorCode: 243, errorMessage: "Error in S3 upload - [\(responseCode)] \(error.localizedDescription)"))) } else if task.status != .completed { completion(.failure(.remoteError(errorCode: 245, errorMessage: "Unknown S3 error")))