From 7bd25e5abb53ccb0837c01a514b1c1da3db08980 Mon Sep 17 00:00:00 2001 From: Marthinus Ettienne van Zyl - u19012366 Date: Wed, 11 Oct 2023 10:00:38 +0200 Subject: [PATCH 1/9] Update ENV file names --- .github/workflows/main2.yml | 4 +-- Dockerfile | 2 +- client/ios/Podfile.lock | 4 +-- client/ios/Runner.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- client/lib/Utils/constants_util.dart | 2 +- client/pubspec.lock | 34 ++++++++++++------- .../com/teamcaffeine/koja/KojaApplication.kt | 2 +- .../koja/controller/LocationController.kt | 4 +-- .../service/GoogleCalendarAdapterService.kt | 4 +-- .../koja/service/LocationService.kt | 8 ++--- ...AccountManagerControllerIntegrationTest.kt | 2 +- .../UserAccountManagerControllerUnitTest.kt | 2 +- .../UserControllerIntergrationTest.kt | 2 +- .../koja/controller/UserControllerUnitTest.kt | 2 +- .../koja/service/CustomExtension.kt | 2 +- .../GoogleCalendarAdapterServiceTest.kt | 2 +- .../service/UserAccountManagerServiceTest.kt | 2 +- .../UserCalendarServiceIntergrationTest.kt | 2 +- .../koja/service/UserCalendarServiceTest.kt | 2 +- 20 files changed, 47 insertions(+), 39 deletions(-) diff --git a/.github/workflows/main2.yml b/.github/workflows/main2.yml index 9c96f208..48824dad 100644 --- a/.github/workflows/main2.yml +++ b/.github/workflows/main2.yml @@ -25,7 +25,7 @@ jobs: echo GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} >> client/assets/.env echo GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }} >> client/assets/.env echo KOJA_JWT_SECRET=${{ secrets.KOJA_JWT_SECRET }} >> client/assets/.env - echo API_KEY=${{ secrets.API_KEY }} >> client/assets/.env + echo GOOGLE_MAPS_API_KEY=${{ secrets.GOOGLE_MAPS_API_KEY }} >> client/assets/.env echo OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} >> client/assets/.env echo KOJA_ID_SECRET=${{ secrets.KOJA_ID_SECRET }} >> client/assets/.env echo COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_REPO_TOKEN }} >> client/assets/.env @@ -79,7 +79,7 @@ jobs: echo GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} >> .env echo GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }} >> .env echo KOJA_JWT_SECRET=${{ secrets.KOJA_JWT_SECRET }} >> .env - echo API_KEY=${{ secrets.API_KEY }} >> .env + echo GOOGLE_MAPS_API_KEY=${{ secrets.GOOGLE_MAPS_API_KEY }} >> .env echo OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} >> .env echo KOJA_ID_SECRET=${{ secrets.KOJA_ID_SECRET }} >> .env echo COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_REPO_TOKEN }} >> .env diff --git a/Dockerfile b/Dockerfile index ec7939ad..f16556e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,7 @@ RUN echo "KOJA_AWS_RDS_DATABASE_URL=$KOJA_AWS_RDS_DATABASE_URL" >> .env && \ echo "GOOGLE_CLIENT_SECRET=$GOOGLE_CLIENT_SECRET" >> .env && \ echo "KOJA_JWT_SECRET=$KOJA_JWT_SECRET" >> .env && \ echo "KOJA_ID_SECRET=$KOJA_AI_SECRET" >> .env && \ - echo "API_KEY=$API_KEY" >> .env && \ + echo "GOOGLE_MAPS_API_KEY=$GOOGLE_MAPS_API_KEY" >> .env && \ echo "OPENAI_API_KEY=$OPENAI_API_KEY" >> .env && \ echo "COVERALLS_REPO_TOKEN=$COVERALLS_REPO_TOKEN" >> .env && \ echo "KOJA_PRIVATE_KEY_PASS=$KOJA_PRIVATE_KEY_PASS" >> .env && \ diff --git a/client/ios/Podfile.lock b/client/ios/Podfile.lock index 93f16de6..48473acd 100644 --- a/client/ios/Podfile.lock +++ b/client/ios/Podfile.lock @@ -118,7 +118,7 @@ SPEC CHECKSUMS: device_info_plus: 7545d84d8d1b896cb16a4ff98c19f07ec4b298ea fl_location: 68b4a6c4aad2a453493ff66f196e0748280cf43e Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 - flutter_inappwebview: bfd58618f49dc62f2676de690fc6dcda1d6c3721 + flutter_inappwebview: acd4fc0f012cefd09015000c241137d82f01ba62 flutter_pdfview: 25f53dd6097661e6395b17de506e6060585946bd flutter_web_auth_2: a1bc00762c408a8f80b72a538cd7ff5b601c3e71 FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a @@ -138,4 +138,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 70d9d25280d0dd177a5f637cdb0f0b0b12c6a189 -COCOAPODS: 1.12.1 +COCOAPODS: 1.13.0 diff --git a/client/ios/Runner.xcodeproj/project.pbxproj b/client/ios/Runner.xcodeproj/project.pbxproj index c86ba155..9b16e446 100644 --- a/client/ios/Runner.xcodeproj/project.pbxproj +++ b/client/ios/Runner.xcodeproj/project.pbxproj @@ -214,7 +214,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = ""; TargetAttributes = { 331C8080294A63A400263BE5 = { diff --git a/client/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/client/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index e42adcb3..87131a09 100644 --- a/client/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/client/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ =3.0.0 <4.0.0" + dart: ">=3.1.0-185.0.dev <4.0.0" flutter: ">=3.10.0" diff --git a/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt b/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt index 827b4aa3..d6666e32 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt @@ -28,7 +28,7 @@ fun main(args: Array) { // Set Google Sign In client ID and client secret properties setProperty("GOOGLE_CLIENT_ID", dotenv["GOOGLE_CLIENT_ID"]!!) setProperty("GOOGLE_CLIENT_SECRET", dotenv["GOOGLE_CLIENT_SECRET"]!!) - setProperty("API_KEY", dotenv["API_KEY"]!!) + setProperty("GOOGLE_MAPS_API_KEY", dotenv["GOOGLE_MAPS_API_KEY"]!!) // Set JWT secret key property setProperty("KOJA_JWT_SECRET", dotenv["KOJA_JWT_SECRET"]!!) diff --git a/src/main/kotlin/com/teamcaffeine/koja/controller/LocationController.kt b/src/main/kotlin/com/teamcaffeine/koja/controller/LocationController.kt index 0e5c705c..aea6b5cc 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/controller/LocationController.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/controller/LocationController.kt @@ -109,7 +109,7 @@ LocationController(private val locationService: LocationService) { fun getDistance(origin: String?, destination: String?): String? { val context = GeoApiContext.Builder() - .apiKey(System.getProperty("API_KEY")) + .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) .build() val result: DistanceMatrix = DistanceMatrixApi.newRequest(context) @@ -146,7 +146,7 @@ LocationController(private val locationService: LocationService) { fun getTravelTime(placeId: String, destLat: Double, destLng: Double): Long? { val context = GeoApiContext.Builder() - .apiKey(System.getProperty("API_KEY")) + .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) .build() val result: DistanceMatrix = DistanceMatrixApi.newRequest(context) diff --git a/src/main/kotlin/com/teamcaffeine/koja/service/GoogleCalendarAdapterService.kt b/src/main/kotlin/com/teamcaffeine/koja/service/GoogleCalendarAdapterService.kt index 3d1371d8..34e63ec4 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/service/GoogleCalendarAdapterService.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/service/GoogleCalendarAdapterService.kt @@ -481,7 +481,7 @@ class GoogleCalendarAdapterService( val endDateTime = DateTime(eventEndTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)) val context = GeoApiContext.Builder() - .apiKey(System.getProperty("API_KEY")) + .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) .build() val calendarTimezone = getCalendarTimezone(calendarService, "primary") @@ -899,7 +899,7 @@ class GoogleCalendarAdapterService( // private lateinit var googleCalendarAdapterService: GoogleCalendarAdapterService // fun getTimeOfTimeZone(jwtToken: String): String? { // val context = GeoApiContext.Builder() -// .apiKey(System.getProperty("API_KEY")) +// .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) // .build() // val userLocations = LocationService(userRepository, googleCalendarAdapterService) // val userLocation = userLocations.getUserSavedLocations(jwtToken)["currentLocation"] as Pair<*, *> diff --git a/src/main/kotlin/com/teamcaffeine/koja/service/LocationService.kt b/src/main/kotlin/com/teamcaffeine/koja/service/LocationService.kt index 84f4ecc0..06626f75 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/service/LocationService.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/service/LocationService.kt @@ -60,7 +60,7 @@ class LocationService(private val userRepository: UserRepository, private val go fun getTravelTime(originLat: Double, originLng: Double, placeId: String): Long? { val context = GeoApiContext.Builder() - .apiKey(System.getProperty("API_KEY")) + .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) .build() val result: DistanceMatrix = DistanceMatrixApi.newRequest(context) @@ -78,7 +78,7 @@ class LocationService(private val userRepository: UserRepository, private val go fun getTravelTime(placeIdOrigin: String, placeIdDestination: String): Long? { val context = GeoApiContext.Builder() - .apiKey(System.getProperty("API_KEY")) + .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) .build() val result: DistanceMatrix = DistanceMatrixApi.newRequest(context) @@ -115,7 +115,7 @@ class LocationService(private val userRepository: UserRepository, private val go vararg futureEventsLocations: String, ): DistanceMatrix? { val context = GeoApiContext.Builder() - .apiKey(System.getProperty("API_KEY")) + .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) .build() try { @@ -147,7 +147,7 @@ class LocationService(private val userRepository: UserRepository, private val go fun getLocationCoordinates(placeId: String): Pair? { val context = GeoApiContext.Builder() - .apiKey(System.getProperty("API_KEY")) + .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) .build() val results: Array = GeocodingApi.newRequest(context) diff --git a/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerIntegrationTest.kt b/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerIntegrationTest.kt index 9df601db..7788d115 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerIntegrationTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerIntegrationTest.kt @@ -67,7 +67,7 @@ class UserAccountManagerControllerIntegrationTest { dotenv["GOOGLE_CLIENT_ID"]?.let { System.setProperty("GOOGLE_CLIENT_ID", it) } dotenv["GOOGLE_CLIENT_SECRET"]?.let { System.setProperty("GOOGLE_CLIENT_SECRET", it) } - dotenv["API_KEY"]?.let { System.setProperty("API_KEY", it) } + dotenv["GOOGLE_MAPS_API_KEY"]?.let { System.setProperty("GOOGLE_MAPS_API_KEY", it) } dotenv["KOJA_JWT_SECRET"]?.let { System.setProperty("KOJA_JWT_SECRET", it) } } diff --git a/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerUnitTest.kt b/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerUnitTest.kt index 4ba01bbd..bce8da7b 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerUnitTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerUnitTest.kt @@ -60,7 +60,7 @@ class UserAccountManagerControllerUnitTest { dotenv["GOOGLE_CLIENT_ID"]?.let { System.setProperty("GOOGLE_CLIENT_ID", it) } dotenv["GOOGLE_CLIENT_SECRET"]?.let { System.setProperty("GOOGLE_CLIENT_SECRET", it) } - dotenv["API_KEY"]?.let { System.setProperty("API_KEY", it) } + dotenv["GOOGLE_MAPS_API_KEY"]?.let { System.setProperty("GOOGLE_MAPS_API_KEY", it) } dotenv["KOJA_JWT_SECRET"]?.let { System.setProperty("KOJA_JWT_SECRET", it) } } diff --git a/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerIntergrationTest.kt b/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerIntergrationTest.kt index f2971b0b..ab79d500 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerIntergrationTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerIntergrationTest.kt @@ -66,7 +66,7 @@ class UserControllerIntergrationTest { dotenv["GOOGLE_CLIENT_ID"]?.let { System.setProperty("GOOGLE_CLIENT_ID", it) } dotenv["GOOGLE_CLIENT_SECRET"]?.let { System.setProperty("GOOGLE_CLIENT_SECRET", it) } - dotenv["API_KEY"]?.let { System.setProperty("API_KEY", it) } + dotenv["GOOGLE_MAPS_API_KEY"]?.let { System.setProperty("GOOGLE_MAPS_API_KEY", it) } dotenv["KOJA_JWT_SECRET"]?.let { System.setProperty("KOJA_JWT_SECRET", it) } } diff --git a/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerUnitTest.kt b/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerUnitTest.kt index 751541ac..a7260972 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerUnitTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerUnitTest.kt @@ -69,7 +69,7 @@ class UserControllerUnitTest { dotenv["GOOGLE_CLIENT_ID"]?.let { System.setProperty("GOOGLE_CLIENT_ID", it) } dotenv["GOOGLE_CLIENT_SECRET"]?.let { System.setProperty("GOOGLE_CLIENT_SECRET", it) } - dotenv["API_KEY"]?.let { System.setProperty("API_KEY", it) } + dotenv["GOOGLE_MAPS_API_KEY"]?.let { System.setProperty("GOOGLE_MAPS_API_KEY", it) } dotenv["KOJA_JWT_SECRET"]?.let { System.setProperty("KOJA_JWT_SECRET", it) } } diff --git a/src/test/kotlin/com/teamcaffiene/koja/service/CustomExtension.kt b/src/test/kotlin/com/teamcaffiene/koja/service/CustomExtension.kt index f94f8a3c..b67509cd 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/service/CustomExtension.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/service/CustomExtension.kt @@ -16,7 +16,7 @@ class CustomExtension : BeforeEachCallback { // Set Google Sign In client ID and client secret properties System.setProperty("GOOGLE_CLIENT_ID", dotenv["GOOGLE_CLIENT_ID"]!!) System.setProperty("GOOGLE_CLIENT_SECRET", dotenv["GOOGLE_CLIENT_SECRET"]!!) - System.setProperty("API_KEY", dotenv["API_KEY"]!!) + System.setProperty("GOOGLE_MAPS_API_KEY", dotenv["GOOGLE_MAPS_API_KEY"]!!) // Set JWT secret key property System.setProperty("KOJA_JWT_SECRET", dotenv["KOJA_JWT_SECRET"]!!) diff --git a/src/test/kotlin/com/teamcaffiene/koja/service/GoogleCalendarAdapterServiceTest.kt b/src/test/kotlin/com/teamcaffiene/koja/service/GoogleCalendarAdapterServiceTest.kt index 1480766d..6378c495 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/service/GoogleCalendarAdapterServiceTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/service/GoogleCalendarAdapterServiceTest.kt @@ -64,7 +64,7 @@ class GoogleCalendarAdapterServiceTest { dotenv["GOOGLE_CLIENT_ID"]?.let { setProperty("GOOGLE_CLIENT_ID", it) } dotenv["GOOGLE_CLIENT_SECRET"]?.let { setProperty("GOOGLE_CLIENT_SECRET", it) } - dotenv["API_KEY"]?.let { setProperty("API_KEY", it) } + dotenv["GOOGLE_MAPS_API_KEY"]?.let { setProperty("GOOGLE_MAPS_API_KEY", it) } dotenv["KOJA_JWT_SECRET"]?.let { setProperty("KOJA_JWT_SECRET", it) } } diff --git a/src/test/kotlin/com/teamcaffiene/koja/service/UserAccountManagerServiceTest.kt b/src/test/kotlin/com/teamcaffiene/koja/service/UserAccountManagerServiceTest.kt index c0167208..c0e2412a 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/service/UserAccountManagerServiceTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/service/UserAccountManagerServiceTest.kt @@ -51,7 +51,7 @@ class UserAccountManagerServiceTest { dotenv["GOOGLE_CLIENT_ID"]?.let { System.setProperty("GOOGLE_CLIENT_ID", it) } dotenv["GOOGLE_CLIENT_SECRET"]?.let { System.setProperty("GOOGLE_CLIENT_SECRET", it) } - dotenv["API_KEY"]?.let { System.setProperty("API_KEY", it) } + dotenv["GOOGLE_MAPS_API_KEY"]?.let { System.setProperty("GOOGLE_MAPS_API_KEY", it) } dotenv["KOJA_JWT_SECRET"]?.let { System.setProperty("KOJA_JWT_SECRET", it) } } diff --git a/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceIntergrationTest.kt b/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceIntergrationTest.kt index 9a959b1a..e2e642c1 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceIntergrationTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceIntergrationTest.kt @@ -71,7 +71,7 @@ class UserCalendarServiceIntergrationTest { dotenv["GOOGLE_CLIENT_ID"]?.let { System.setProperty("GOOGLE_CLIENT_ID", it) } dotenv["GOOGLE_CLIENT_SECRET"]?.let { System.setProperty("GOOGLE_CLIENT_SECRET", it) } - dotenv["API_KEY"]?.let { System.setProperty("API_KEY", it) } + dotenv["GOOGLE_MAPS_API_KEY"]?.let { System.setProperty("GOOGLE_MAPS_API_KEY", it) } dotenv["KOJA_JWT_SECRET"]?.let { System.setProperty("KOJA_JWT_SECRET", it) } } diff --git a/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceTest.kt b/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceTest.kt index 4fd26d38..3297e383 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceTest.kt @@ -74,7 +74,7 @@ class UserCalendarServiceTest { // Set Google Sign In client ID and client secret properties System.setProperty("GOOGLE_CLIENT_ID", dotenv["GOOGLE_CLIENT_ID"]!!) System.setProperty("GOOGLE_CLIENT_SECRET", dotenv["GOOGLE_CLIENT_SECRET"]!!) - System.setProperty("API_KEY", dotenv["API_KEY"]!!) + System.setProperty("GOOGLE_MAPS_API_KEY", dotenv["GOOGLE_MAPS_API_KEY"]!!) // Set JWT secret key and other related properties System.setProperty("KOJA_JWT_SECRET", dotenv["KOJA_JWT_SECRET"]!!) From e4fded24b3bfe8bc2bc6e4916f8c47f2e0470cec Mon Sep 17 00:00:00 2001 From: Marthinus Ettienne van Zyl - u19012366 Date: Wed, 11 Oct 2023 10:17:45 +0200 Subject: [PATCH 2/9] Introduce Environment Variable Constant object for better maintainability --- .../com/teamcaffeine/koja/KojaApplication.kt | 82 ++++++++++++++----- .../constants/EnvironmentVariableConstant.kt | 22 +++++ .../GoogleCalendarAdapterServiceTest.kt | 31 +++++-- 3 files changed, 105 insertions(+), 30 deletions(-) create mode 100644 src/main/kotlin/com/teamcaffeine/koja/constants/EnvironmentVariableConstant.kt diff --git a/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt b/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt index d6666e32..e2d13741 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt @@ -1,5 +1,6 @@ package com.teamcaffeine.koja +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import io.github.cdimascio.dotenv.Dotenv import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration @@ -12,30 +13,69 @@ class KojaApplication fun main(args: Array) { val dotenv: Dotenv = Dotenv.load() - setProperty("KOJA_AWS_RDS_DATABASE_URL", dotenv["KOJA_AWS_RDS_DATABASE_URL"]!!) - setProperty("KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME", dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME"]!!) - setProperty("KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD", dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD"]!!) - setProperty("KOJA_AWS_DYNAMODB_ACCESS_KEY_ID", dotenv["KOJA_AWS_DYNAMODB_ACCESS_KEY_ID"]!!) - setProperty("KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET", dotenv["KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET"]!!) - setProperty("OPENAI_API_KEY", dotenv["OPENAI_API_KEY"]!!) - setProperty("SERVER_ADDRESS", dotenv["SERVER_ADDRESS"]!!) - if (dotenv["SERVER_PORT"] != null) { - setProperty("SERVER_PORT", dotenv["SERVER_PORT"]!!) - } else { - setProperty("SERVER_PORT", "") - } - + setProperty( + EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL, + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL]!!, + ) + setProperty( + EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME, + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME]!!, + ) + setProperty( + EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD, + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD]!!, + ) + setProperty( + EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID, + dotenv[EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID]!!, + ) + setProperty( + EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET, + dotenv[EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET]!!, + ) + setProperty( + EnvironmentVariableConstant.OPENAI_API_KEY, + dotenv[EnvironmentVariableConstant.OPENAI_API_KEY]!!, + ) + setProperty( + EnvironmentVariableConstant.SERVER_ADDRESS, + dotenv[EnvironmentVariableConstant.SERVER_ADDRESS]!!, + ) + setProperty( + EnvironmentVariableConstant.SERVER_PORT, + dotenv[EnvironmentVariableConstant.SERVER_PORT] ?: "", + ) // Set Google Sign In client ID and client secret properties - setProperty("GOOGLE_CLIENT_ID", dotenv["GOOGLE_CLIENT_ID"]!!) - setProperty("GOOGLE_CLIENT_SECRET", dotenv["GOOGLE_CLIENT_SECRET"]!!) - setProperty("GOOGLE_MAPS_API_KEY", dotenv["GOOGLE_MAPS_API_KEY"]!!) + setProperty( + EnvironmentVariableConstant.GOOGLE_CLIENT_ID, + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_ID]!!, + ) + setProperty( + EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET, + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET]!!, + ) + setProperty( + EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY, + dotenv[EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY]!!, + ) // Set JWT secret key property - setProperty("KOJA_JWT_SECRET", dotenv["KOJA_JWT_SECRET"]!!) - setProperty("KOJA_ID_SECRET", dotenv["KOJA_ID_SECRET"]!!) - - setProperty("KOJA_PRIVATE_KEY_PASS", dotenv["KOJA_PRIVATE_KEY_PASS"]!!) - setProperty("KOJA_PRIVATE_KEY_SALT", dotenv["KOJA_PRIVATE_KEY_SALT"]!!) + setProperty( + EnvironmentVariableConstant.KOJA_JWT_SECRET, + dotenv[EnvironmentVariableConstant.KOJA_JWT_SECRET]!!, + ) + setProperty( + EnvironmentVariableConstant.KOJA_ID_SECRET, + dotenv[EnvironmentVariableConstant.KOJA_ID_SECRET]!!, + ) + setProperty( + EnvironmentVariableConstant.KOJA_PRIVATE_KEY_PASS, + dotenv[EnvironmentVariableConstant.KOJA_PRIVATE_KEY_PASS]!!, + ) + setProperty( + EnvironmentVariableConstant.KOJA_PRIVATE_KEY_SALT, + dotenv[EnvironmentVariableConstant.KOJA_PRIVATE_KEY_SALT]!!, + ) runApplication(*args) } diff --git a/src/main/kotlin/com/teamcaffeine/koja/constants/EnvironmentVariableConstant.kt b/src/main/kotlin/com/teamcaffeine/koja/constants/EnvironmentVariableConstant.kt new file mode 100644 index 00000000..0c304462 --- /dev/null +++ b/src/main/kotlin/com/teamcaffeine/koja/constants/EnvironmentVariableConstant.kt @@ -0,0 +1,22 @@ +package com.teamcaffeine.koja.constants + +object EnvironmentVariableConstant { + const val KOJA_AWS_RDS_DATABASE_URL = "KOJA_AWS_RDS_DATABASE_URL" + const val KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME = "KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME" + const val KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD = "KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD" + const val KOJA_AWS_DYNAMODB_ACCESS_KEY_ID = "KOJA_AWS_DYNAMODB_ACCESS_KEY_ID" + const val KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET = "KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET" + const val GOOGLE_CLIENT_ID = "GOOGLE_CLIENT_ID" + const val GOOGLE_CLIENT_SECRET = "GOOGLE_CLIENT_SECRET" + const val GOOGLE_MAPS_API_KEY = "GOOGLE_MAPS_API_KEY" + const val KOJA_JWT_SECRET = "KOJA_JWT_SECRET" + const val OPENAI_API_KEY = "OPENAI_API_KEY" + const val KOJA_ID_SECRET = "KOJA_ID_SECRET" + const val COVERALLS_REPO_TOKEN = "COVERALLS_REPO_TOKEN" + const val KOJA_PRIVATE_KEY_PASS = "KOJA_PRIVATE_KEY_PASS" + const val KOJA_PRIVATE_KEY_SALT = "KOJA_PRIVATE_KEY_SALT" + const val AI_PRIVATE_KEY_PASS = "AI_PRIVATE_KEY_PASS" + const val AI_PRIVATE_KEY_SALT = "AI_PRIVATE_KEY_SALT" + const val SERVER_ADDRESS = "SERVER_ADDRESS" + const val SERVER_PORT = "SERVER_PORT" +} diff --git a/src/test/kotlin/com/teamcaffiene/koja/service/GoogleCalendarAdapterServiceTest.kt b/src/test/kotlin/com/teamcaffiene/koja/service/GoogleCalendarAdapterServiceTest.kt index 6378c495..a1639f25 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/service/GoogleCalendarAdapterServiceTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/service/GoogleCalendarAdapterServiceTest.kt @@ -6,6 +6,7 @@ import com.google.api.client.util.DateTime import com.google.api.services.calendar.model.Event import com.google.api.services.calendar.model.EventDateTime import com.google.api.services.calendar.model.Events +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.dto.JWTGoogleDTO import com.teamcaffeine.koja.dto.UserEventDTO import com.teamcaffeine.koja.entity.UserAccount @@ -58,15 +59,27 @@ class GoogleCalendarAdapterServiceTest { private fun importEnvironmentVariables() { dotenv = Dotenv.load() - dotenv["KOJA_AWS_RDS_DATABASE_URL"]?.let { setProperty("KOJA_AWS_RDS_DATABASE_URL", it) } - dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME"]?.let { setProperty("KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME", it) } - dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD"]?.let { setProperty("KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD", it) } - - dotenv["GOOGLE_CLIENT_ID"]?.let { setProperty("GOOGLE_CLIENT_ID", it) } - dotenv["GOOGLE_CLIENT_SECRET"]?.let { setProperty("GOOGLE_CLIENT_SECRET", it) } - dotenv["GOOGLE_MAPS_API_KEY"]?.let { setProperty("GOOGLE_MAPS_API_KEY", it) } - - dotenv["KOJA_JWT_SECRET"]?.let { setProperty("KOJA_JWT_SECRET", it) } + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL]?.let { + setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL, it) + } + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME]?.let { + setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME, it) + } + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD]?.let { + setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_ID]?.let { + setProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_ID, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET]?.let { + setProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY]?.let { + setProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY, it) + } + dotenv[EnvironmentVariableConstant.KOJA_JWT_SECRET]?.let { + setProperty(EnvironmentVariableConstant.KOJA_JWT_SECRET, it) + } } /* From c8e29b8e136860ba6006a272f21696a9ddc037f1 Mon Sep 17 00:00:00 2001 From: Marthinus Ettienne van Zyl - u19012366 Date: Wed, 11 Oct 2023 11:08:54 +0200 Subject: [PATCH 3/9] Migrate ENV file calls to use constants --- .../koja/controller/LocationController.kt | 5 +- .../koja/controller/TokenManagerController.kt | 5 +- .../com/teamcaffeine/koja/dto/JWTGoogleDTO.kt | 5 +- .../koja/dto/JWTRealFuntionality.kt | 3 +- .../koja/service/AIUserDataService.kt | 17 +-- .../koja/service/CryptoService.kt | 5 +- .../service/GoogleCalendarAdapterService.kt | 25 +++-- .../koja/service/LocationService.kt | 9 +- .../koja/service/UserAccountManagerService.kt | 7 +- .../koja/service/UserCalendarService.kt | 9 +- .../GoogleCalendarControllerTests.kt | 10 +- .../TokenManagerControllerUnitTest.kt | 6 +- ...AccountManagerControllerIntegrationTest.kt | 37 ++++--- .../UserAccountManagerControllerUnitTest.kt | 35 +++--- .../UserControllerIntergrationTest.kt | 79 +++++++------- .../koja/controller/UserControllerUnitTest.kt | 37 ++++--- .../koja/service/CustomExtension.kt | 36 +++++-- .../service/UserAccountManagerServiceTest.kt | 35 +++--- .../UserCalendarServiceIntergrationTest.kt | 74 +++++++------ .../koja/service/UserCalendarServiceTest.kt | 102 +++++++++++++----- 20 files changed, 327 insertions(+), 214 deletions(-) diff --git a/src/main/kotlin/com/teamcaffeine/koja/controller/LocationController.kt b/src/main/kotlin/com/teamcaffeine/koja/controller/LocationController.kt index aea6b5cc..a147afce 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/controller/LocationController.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/controller/LocationController.kt @@ -4,6 +4,7 @@ import com.google.maps.DistanceMatrixApi import com.google.maps.GeoApiContext import com.google.maps.model.DistanceMatrix import com.google.maps.model.TravelMode +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.constants.HeaderConstant import com.teamcaffeine.koja.constants.ResponseConstant import com.teamcaffeine.koja.service.LocationService @@ -109,7 +110,7 @@ LocationController(private val locationService: LocationService) { fun getDistance(origin: String?, destination: String?): String? { val context = GeoApiContext.Builder() - .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) + .apiKey(System.getProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY)) .build() val result: DistanceMatrix = DistanceMatrixApi.newRequest(context) @@ -146,7 +147,7 @@ LocationController(private val locationService: LocationService) { fun getTravelTime(placeId: String, destLat: Double, destLng: Double): Long? { val context = GeoApiContext.Builder() - .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) + .apiKey(System.getProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY)) .build() val result: DistanceMatrix = DistanceMatrixApi.newRequest(context) diff --git a/src/main/kotlin/com/teamcaffeine/koja/controller/TokenManagerController.kt b/src/main/kotlin/com/teamcaffeine/koja/controller/TokenManagerController.kt index 3030af3d..e027113a 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/controller/TokenManagerController.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/controller/TokenManagerController.kt @@ -3,6 +3,7 @@ package com.teamcaffeine.koja.controller import com.auth0.jwt.JWT import com.auth0.jwt.algorithms.Algorithm import com.google.gson.Gson +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.constants.HeaderConstant import com.teamcaffeine.koja.dto.JWTAuthDetailsDTO import com.teamcaffeine.koja.dto.JWTAuthDetailsDTO.Companion.parseJWTFormatString @@ -49,7 +50,7 @@ class TokenManagerController { companion object { private const val oneMinuteInSeconds: Long = 60L - private val jwtSecret: String = System.getProperty("KOJA_JWT_SECRET") + private val jwtSecret: String = System.getProperty(EnvironmentVariableConstant.KOJA_JWT_SECRET) private fun decrypt(text: String, key: SecretKey): String { val cipher = Cipher.getInstance("AES") @@ -109,7 +110,7 @@ class TokenManagerController { } fun getUserJWTTokenData(jwtToken: String, verifyValidity: Boolean = true): UserJWTTokenDataDTO { - val jwtSecret: String = System.getProperty("KOJA_JWT_SECRET") + val jwtSecret: String = System.getProperty(EnvironmentVariableConstant.KOJA_JWT_SECRET) val algorithm = Algorithm.HMAC512(jwtSecret) val verifier = JWT.require(algorithm).build() val decodedJWT = if (verifyValidity) { diff --git a/src/main/kotlin/com/teamcaffeine/koja/dto/JWTGoogleDTO.kt b/src/main/kotlin/com/teamcaffeine/koja/dto/JWTGoogleDTO.kt index 1c256340..0c15f056 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/dto/JWTGoogleDTO.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/dto/JWTGoogleDTO.kt @@ -2,6 +2,7 @@ package com.teamcaffeine.koja.dto import com.google.api.client.googleapis.auth.oauth2.GoogleCredential import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.enums.AuthProviderEnum class JWTGoogleDTO(private var accessToken: String, private val refreshToken: String, var expireTimeInSeconds: Long) : @@ -32,8 +33,8 @@ class JWTGoogleDTO(private var accessToken: String, private val refreshToken: St val jsonFactory = com.google.api.client.json.jackson2.JacksonFactory.getDefaultInstance() val httpTransport = com.google.api.client.http.javanet.NetHttpTransport.Builder().build() - val clientId = System.getProperty("GOOGLE_CLIENT_ID") - val clientSecret = System.getProperty("GOOGLE_CLIENT_SECRET") + val clientId = System.getProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_ID) + val clientSecret = System.getProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET) val credential = GoogleCredential.Builder() .setJsonFactory(jsonFactory) diff --git a/src/main/kotlin/com/teamcaffeine/koja/dto/JWTRealFuntionality.kt b/src/main/kotlin/com/teamcaffeine/koja/dto/JWTRealFuntionality.kt index a089d673..f5ae3396 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/dto/JWTRealFuntionality.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/dto/JWTRealFuntionality.kt @@ -3,6 +3,7 @@ package com.teamcaffeine.koja.dto import com.auth0.jwt.JWT import com.auth0.jwt.algorithms.Algorithm import com.google.gson.Gson +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.controller.TokenManagerController import com.teamcaffeine.koja.enums.AuthProviderEnum import org.springframework.stereotype.Service @@ -19,7 +20,7 @@ class JWTRealFuntionality : JWTFunctionality { } override fun getUserJWTTokenData(jwtToken: String): UserJWTTokenDataDTO { - val jwtSecret: String = System.getProperty("KOJA_JWT_SECRET") + val jwtSecret: String = System.getProperty(EnvironmentVariableConstant.KOJA_JWT_SECRET) val algorithm = Algorithm.HMAC512(jwtSecret) val verifier = JWT.require(algorithm).build() val decodedJWT = verifier.verify(jwtToken) diff --git a/src/main/kotlin/com/teamcaffeine/koja/service/AIUserDataService.kt b/src/main/kotlin/com/teamcaffeine/koja/service/AIUserDataService.kt index ce86b91b..b09c4ff4 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/service/AIUserDataService.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/service/AIUserDataService.kt @@ -1,5 +1,6 @@ package com.teamcaffeine.koja.service +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.dto.AIUserEventDataDTO import com.teamcaffeine.koja.dto.EncryptedData import com.teamcaffeine.koja.dto.TimeSlot @@ -30,8 +31,8 @@ import java.util.Base64 @Service @Transactional class AIUserDataService(private val userRepository: UserRepository, private val userAccountRepository: UserAccountRepository, private val cryptoService: CryptoService) { - private val clientId = System.getProperty("GOOGLE_CLIENT_ID") - private val clientSecret = System.getProperty("GOOGLE_CLIENT_SECRET") + private val clientId = System.getProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_ID) + private val clientSecret = System.getProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET) private fun getTimeslotPairList( semester: List, @@ -198,7 +199,7 @@ class AIUserDataService(private val userRepository: UserRepository, private val if (timeSlotDuration / eventDuration >= 2) { var timeSlotOffset = 0L while (timeSlot.startTime.plusSeconds(timeSlotOffset) - .isBefore(timeSlot.endTime) + .isBefore(timeSlot.endTime) ) { tempTimeSlots.add( TimeSlot( @@ -238,8 +239,8 @@ class AIUserDataService(private val userRepository: UserRepository, private val val userIdsToDelete = ArrayList>() val awsCreds = AwsBasicCredentials.create( - System.getProperty("KOJA_AWS_DYNAMODB_ACCESS_KEY_ID"), - System.getProperty("KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET"), + System.getProperty(EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID), + System.getProperty(EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET), ) val dynamoDBClient = DynamoDbClient.builder() @@ -291,7 +292,7 @@ class AIUserDataService(private val userRepository: UserRepository, private val fun validateKojaSecretID(id: String): Boolean { val decrypted = decrypt(id) - return decrypted == System.getProperty("KOJA_ID_SECRET") + return decrypted == System.getProperty(EnvironmentVariableConstant.KOJA_ID_SECRET) } private fun removeOldEntries( @@ -313,8 +314,8 @@ class AIUserDataService(private val userRepository: UserRepository, private val private fun userHasRecommendations(userID: String): Boolean { val awsCreds = AwsBasicCredentials.create( - System.getProperty("KOJA_AWS_DYNAMODB_ACCESS_KEY_ID"), - System.getProperty("KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET"), + System.getProperty(EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID), + System.getProperty(EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET), ) val dynamoDBClient = DynamoDbClient.builder() diff --git a/src/main/kotlin/com/teamcaffeine/koja/service/CryptoService.kt b/src/main/kotlin/com/teamcaffeine/koja/service/CryptoService.kt index 47ee9668..997fcf10 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/service/CryptoService.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/service/CryptoService.kt @@ -1,5 +1,6 @@ package com.teamcaffeine.koja.service +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import org.bouncycastle.asn1.pkcs.RSAPrivateKey import org.springframework.core.io.ClassPathResource import org.springframework.stereotype.Service @@ -29,8 +30,8 @@ class CryptoService { private val privateKeyDir = "keys" private val privateKeyPath = "$privateKeyDir/private_key.pem" - private val passphrase = System.getProperty("KOJA_PRIVATE_KEY_PASS") - private val salt = System.getProperty("KOJA_PRIVATE_KEY_SALT") + private val passphrase = System.getProperty(EnvironmentVariableConstant.KOJA_PRIVATE_KEY_PASS) + private val salt = System.getProperty(EnvironmentVariableConstant.KOJA_PRIVATE_KEY_SALT) private val keyPair: KeyPair init { diff --git a/src/main/kotlin/com/teamcaffeine/koja/service/GoogleCalendarAdapterService.kt b/src/main/kotlin/com/teamcaffeine/koja/service/GoogleCalendarAdapterService.kt index 34e63ec4..0ed70a1e 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/service/GoogleCalendarAdapterService.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/service/GoogleCalendarAdapterService.kt @@ -20,6 +20,7 @@ import com.google.gson.JsonPrimitive import com.google.gson.JsonSerializationContext import com.google.gson.JsonSerializer import com.google.maps.GeoApiContext +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.constants.ExceptionMessageConstant import com.teamcaffeine.koja.constants.Frequency import com.teamcaffeine.koja.controller.TokenManagerController @@ -69,9 +70,9 @@ class GoogleCalendarAdapterService( ) : CalendarAdapterService(AuthProviderEnum.GOOGLE) { private val httpTransport = GoogleNetHttpTransport.newTrustedTransport() private val jsonFactory: JsonFactory = JacksonFactory.getDefaultInstance() - private val clientId = System.getProperty("GOOGLE_CLIENT_ID") - private val clientSecret = System.getProperty("GOOGLE_CLIENT_SECRET") - private val serverAddress = "${System.getProperty("SERVER_ADDRESS")}:${System.getProperty("SERVER_PORT")}" + private val clientId = System.getProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_ID) + private val clientSecret = System.getProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET) + private val serverAddress = "${System.getProperty(EnvironmentVariableConstant.SERVER_ADDRESS)}:${System.getProperty(EnvironmentVariableConstant.SERVER_PORT)}" private val redirectUriBase = "$serverAddress/api/v1/auth" private val scopes = listOf( "https://www.googleapis.com/auth/calendar", @@ -148,8 +149,8 @@ class GoogleCalendarAdapterService( val parameters = LinkedMultiValueMap() parameters.add("grant_type", "authorization_code") parameters.add("code", authCode) - parameters.add("client_id", System.getProperty("GOOGLE_CLIENT_ID")) - parameters.add("client_secret", System.getProperty("GOOGLE_CLIENT_SECRET")) + parameters.add("client_id", System.getProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_ID)) + parameters.add("client_secret", System.getProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET)) if (deviceType == CallbackConfigEnum.WEB) { parameters.add("redirect_uri", "$serverAddress/api/v1/auth/google/callback") @@ -224,11 +225,13 @@ class GoogleCalendarAdapterService( timeBoundary.user = newUser userRepository.save(newUser) + val awsCreds = AwsBasicCredentials.create( - System.getProperty("KOJA_AWS_DYNAMODB_ACCESS_KEY_ID"), - System.getProperty("KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET"), + System.getProperty(EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID), + System.getProperty(EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET) ) + val dynamoDBClient = DynamoDbClient.builder() .region(Region.EU_NORTH_1) .credentialsProvider { awsCreds } @@ -269,8 +272,8 @@ class GoogleCalendarAdapterService( val parameters = LinkedMultiValueMap() parameters.add("grant_type", "authorization_code") parameters.add("code", authCode) - parameters.add("client_id", System.getProperty("GOOGLE_CLIENT_ID")) - parameters.add("client_secret", System.getProperty("GOOGLE_CLIENT_SECRET")) + parameters.add("client_id", System.getProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_ID)) + parameters.add("client_secret", System.getProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET)) parameters.add("redirect_uri", "$serverAddress/api/v1/user/auth/add-email/callback") val requestEntity = HttpEntity(parameters, headers) @@ -481,7 +484,7 @@ class GoogleCalendarAdapterService( val endDateTime = DateTime(eventEndTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)) val context = GeoApiContext.Builder() - .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) + .apiKey(System.getProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY)) .build() val calendarTimezone = getCalendarTimezone(calendarService, "primary") @@ -899,7 +902,7 @@ class GoogleCalendarAdapterService( // private lateinit var googleCalendarAdapterService: GoogleCalendarAdapterService // fun getTimeOfTimeZone(jwtToken: String): String? { // val context = GeoApiContext.Builder() -// .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) +// .apiKey(System.getProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY)) // .build() // val userLocations = LocationService(userRepository, googleCalendarAdapterService) // val userLocation = userLocations.getUserSavedLocations(jwtToken)["currentLocation"] as Pair<*, *> diff --git a/src/main/kotlin/com/teamcaffeine/koja/service/LocationService.kt b/src/main/kotlin/com/teamcaffeine/koja/service/LocationService.kt index 06626f75..96649af5 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/service/LocationService.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/service/LocationService.kt @@ -6,6 +6,7 @@ import com.google.maps.GeocodingApi import com.google.maps.model.DistanceMatrix import com.google.maps.model.GeocodingResult import com.google.maps.model.TravelMode +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.controller.TokenManagerController import com.teamcaffeine.koja.entity.User import com.teamcaffeine.koja.repository.UserRepository @@ -60,7 +61,7 @@ class LocationService(private val userRepository: UserRepository, private val go fun getTravelTime(originLat: Double, originLng: Double, placeId: String): Long? { val context = GeoApiContext.Builder() - .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) + .apiKey(System.getProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY)) .build() val result: DistanceMatrix = DistanceMatrixApi.newRequest(context) @@ -78,7 +79,7 @@ class LocationService(private val userRepository: UserRepository, private val go fun getTravelTime(placeIdOrigin: String, placeIdDestination: String): Long? { val context = GeoApiContext.Builder() - .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) + .apiKey(System.getProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY)) .build() val result: DistanceMatrix = DistanceMatrixApi.newRequest(context) @@ -115,7 +116,7 @@ class LocationService(private val userRepository: UserRepository, private val go vararg futureEventsLocations: String, ): DistanceMatrix? { val context = GeoApiContext.Builder() - .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) + .apiKey(System.getProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY)) .build() try { @@ -147,7 +148,7 @@ class LocationService(private val userRepository: UserRepository, private val go fun getLocationCoordinates(placeId: String): Pair? { val context = GeoApiContext.Builder() - .apiKey(System.getProperty("GOOGLE_MAPS_API_KEY")) + .apiKey(System.getProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY)) .build() val results: Array = GeocodingApi.newRequest(context) diff --git a/src/main/kotlin/com/teamcaffeine/koja/service/UserAccountManagerService.kt b/src/main/kotlin/com/teamcaffeine/koja/service/UserAccountManagerService.kt index bd372c33..4a5bbf80 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/service/UserAccountManagerService.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/service/UserAccountManagerService.kt @@ -5,6 +5,7 @@ import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport import com.google.api.client.json.JsonFactory import com.google.api.client.json.jackson2.JacksonFactory +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.controller.TokenManagerController import com.teamcaffeine.koja.controller.TokenManagerController.Companion.getUserJWTTokenData import com.teamcaffeine.koja.controller.TokenRequest @@ -35,7 +36,11 @@ class UserAccountManagerService(private val userAccountRepository: UserAccountRe val userTokens = emptyArray().toMutableList() if (existingUserAccounts != null) { for (userAccount in existingUserAccounts) { - val updatedCredentials = refreshAccessToken(System.getProperty("GOOGLE_CLIENT_ID"), System.getProperty("GOOGLE_CLIENT_SECRET"), userAccount.refreshToken) + val updatedCredentials = refreshAccessToken( + System.getProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_ID), + System.getProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET), + userAccount.refreshToken + ) if (updatedCredentials != null) { userTokens.add( JWTGoogleDTO( diff --git a/src/main/kotlin/com/teamcaffeine/koja/service/UserCalendarService.kt b/src/main/kotlin/com/teamcaffeine/koja/service/UserCalendarService.kt index 20950045..000a44a1 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/service/UserCalendarService.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/service/UserCalendarService.kt @@ -1,5 +1,6 @@ package com.teamcaffeine.koja.service +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.controller.TokenManagerController.Companion.getUserJWTTokenData import com.teamcaffeine.koja.dto.JWTFunctionality import com.teamcaffeine.koja.dto.UserEventDTO @@ -560,8 +561,8 @@ class UserCalendarService( fun getUserSuggestions(userID: String): Any { val awsCreds = AwsBasicCredentials.create( - System.getProperty("KOJA_AWS_DYNAMODB_ACCESS_KEY_ID"), - System.getProperty("KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET"), + System.getProperty(EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID), + System.getProperty(EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET), ) val dynamoDBClient = DynamoDbClient.builder() @@ -593,9 +594,9 @@ class UserCalendarService( if (recommendations != null) { toReturn = recommendations.mapValues { entry -> entry.value.l().map { - value -> + value -> value.m()["week_days"]?.m()?.mapValues { - attr -> + attr -> attr.value.l().map { it.s() ?: "" } diff --git a/src/test/kotlin/com/teamcaffiene/koja/controller/GoogleCalendarControllerTests.kt b/src/test/kotlin/com/teamcaffiene/koja/controller/GoogleCalendarControllerTests.kt index 24b69e13..78d48136 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/controller/GoogleCalendarControllerTests.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/controller/GoogleCalendarControllerTests.kt @@ -1,5 +1,6 @@ package com.teamcaffiene.koja.controller +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import io.github.cdimascio.dotenv.Dotenv import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.extension.ExtendWith @@ -26,9 +27,12 @@ class GoogleCalendarControllerTests { @BeforeEach fun setup() { - Mockito.`when`(dotenv["KOJA_AWS_RDS_DATABASE_URL"]).thenReturn("your_test_database_url") - Mockito.`when`(dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME"]).thenReturn("your_test_username") - Mockito.`when`(dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD"]).thenReturn("your_test_password") + Mockito.`when`(dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL]) + .thenReturn("your_test_database_url") + Mockito.`when`(dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME]) + .thenReturn("your_test_username") + Mockito.`when`(dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD]) + .thenReturn("your_test_password") } // @Test diff --git a/src/test/kotlin/com/teamcaffiene/koja/controller/TokenManagerControllerUnitTest.kt b/src/test/kotlin/com/teamcaffiene/koja/controller/TokenManagerControllerUnitTest.kt index ee674e51..c8a36708 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/controller/TokenManagerControllerUnitTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/controller/TokenManagerControllerUnitTest.kt @@ -1,5 +1,6 @@ package com.teamcaffiene.koja.controller +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.controller.TokenManagerController class TokenManagerControllerUnitTest { @@ -9,7 +10,10 @@ class TokenManagerControllerUnitTest { // @BeforeEach // fun setUp() { // val dotenv: Dotenv = Dotenv.load() -// System.setProperty("KOJA_JWT_SECRET", dotenv["KOJA_JWT_SECRET"]!!) +// System.setProperty( +// EnvironmentVariableConstant.KOJA_JWT_SECRET, +// dotenv[EnvironmentVariableConstant.KOJA_JWT_SECRET]!! +// ) // tokenManagerController = TokenManagerController() // } // diff --git a/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerIntegrationTest.kt b/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerIntegrationTest.kt index 7788d115..d6ea4839 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerIntegrationTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerIntegrationTest.kt @@ -1,5 +1,6 @@ package com.teamcaffiene.koja.controller +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.controller.TokenManagerController import com.teamcaffeine.koja.controller.TokenRequest import com.teamcaffeine.koja.controller.UserAccountManagerController @@ -51,25 +52,27 @@ class UserAccountManagerControllerIntegrationTest { private fun importEnvironmentVariables() { dotenv = Dotenv.load() - dotenv["KOJA_AWS_RDS_DATABASE_URL"]?.let { System.setProperty("KOJA_AWS_RDS_DATABASE_URL", it) } - dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME"]?.let { - System.setProperty( - "KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME", - it, - ) + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL, it) } - dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD"]?.let { - System.setProperty( - "KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD", - it, - ) + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME, it) + } + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_ID]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_ID, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY, it) + } + dotenv[EnvironmentVariableConstant.KOJA_JWT_SECRET]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_JWT_SECRET, it) } - - dotenv["GOOGLE_CLIENT_ID"]?.let { System.setProperty("GOOGLE_CLIENT_ID", it) } - dotenv["GOOGLE_CLIENT_SECRET"]?.let { System.setProperty("GOOGLE_CLIENT_SECRET", it) } - dotenv["GOOGLE_MAPS_API_KEY"]?.let { System.setProperty("GOOGLE_MAPS_API_KEY", it) } - - dotenv["KOJA_JWT_SECRET"]?.let { System.setProperty("KOJA_JWT_SECRET", it) } } @Test diff --git a/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerUnitTest.kt b/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerUnitTest.kt index bce8da7b..acd6a9f1 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerUnitTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/controller/UserAccountManagerControllerUnitTest.kt @@ -1,5 +1,6 @@ package com.teamcaffiene.koja.controller +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.constants.ResponseConstant import com.teamcaffeine.koja.controller.TokenManagerController.Companion.createToken import com.teamcaffeine.koja.controller.TokenRequest @@ -44,25 +45,29 @@ class UserAccountManagerControllerUnitTest { private fun importEnvironmentVariables() { dotenv = Dotenv.load() - dotenv["KOJA_AWS_RDS_DATABASE_URL"]?.let { System.setProperty("KOJA_AWS_RDS_DATABASE_URL", it) } - dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME"]?.let { - System.setProperty( - "KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME", - it, - ) + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL, it) } - dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD"]?.let { - System.setProperty( - "KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD", - it, - ) + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME, it) + } + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD, it) } - dotenv["GOOGLE_CLIENT_ID"]?.let { System.setProperty("GOOGLE_CLIENT_ID", it) } - dotenv["GOOGLE_CLIENT_SECRET"]?.let { System.setProperty("GOOGLE_CLIENT_SECRET", it) } - dotenv["GOOGLE_MAPS_API_KEY"]?.let { System.setProperty("GOOGLE_MAPS_API_KEY", it) } + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_ID]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_ID, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY, it) + } - dotenv["KOJA_JWT_SECRET"]?.let { System.setProperty("KOJA_JWT_SECRET", it) } + dotenv[EnvironmentVariableConstant.KOJA_JWT_SECRET]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_JWT_SECRET, it) + } } /** diff --git a/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerIntergrationTest.kt b/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerIntergrationTest.kt index ab79d500..ddb725ac 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerIntergrationTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerIntergrationTest.kt @@ -1,5 +1,6 @@ package com.teamcaffiene.koja.service +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.constants.HeaderConstant import com.teamcaffeine.koja.controller.UserController import com.teamcaffeine.koja.dto.JWTFunctionality @@ -50,48 +51,50 @@ class UserControllerIntergrationTest { private fun importEnvironmentVariables() { dotenv = Dotenv.load() - dotenv["KOJA_AWS_RDS_DATABASE_URL"]?.let { System.setProperty("KOJA_AWS_RDS_DATABASE_URL", it) } - dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME"]?.let { - System.setProperty( - "KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME", - it, - ) + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL, it) } - dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD"]?.let { - System.setProperty( - "KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD", - it, - ) + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME, it) + } + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_ID]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_ID, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY, it) + } + dotenv[EnvironmentVariableConstant.KOJA_JWT_SECRET]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_JWT_SECRET, it) } - - dotenv["GOOGLE_CLIENT_ID"]?.let { System.setProperty("GOOGLE_CLIENT_ID", it) } - dotenv["GOOGLE_CLIENT_SECRET"]?.let { System.setProperty("GOOGLE_CLIENT_SECRET", it) } - dotenv["GOOGLE_MAPS_API_KEY"]?.let { System.setProperty("GOOGLE_MAPS_API_KEY", it) } - - dotenv["KOJA_JWT_SECRET"]?.let { System.setProperty("KOJA_JWT_SECRET", it) } } - /* @Test - fun `test addTimeBoundary with valid input`() { - val token = "validToken" - val userID = "user123" - - // Prepare the user data in the database for the given token - val user = User() - userRepository.save(user) - - // Perform the HTTP POST request to the endpoint - mockMvc.perform( - post("/addTimeBoundary") - .header(HeaderConstant.AUTHORISATION, token) - .param("name", "Office hours") - .param("startTime", "09:00") - .param("endTime", "17:00") - .param("type", "allowed") - .contentType(MediaType.APPLICATION_JSON), - ) - .andExpect(status().isOk) - }*/ + /* @Test + fun `test addTimeBoundary with valid input`() { + val token = "validToken" + val userID = "user123" + + // Prepare the user data in the database for the given token + val user = User() + userRepository.save(user) + + // Perform the HTTP POST request to the endpoint + mockMvc.perform( + post("/addTimeBoundary") + .header(HeaderConstant.AUTHORISATION, token) + .param("name", "Office hours") + .param("startTime", "09:00") + .param("endTime", "17:00") + .param("type", "allowed") + .contentType(MediaType.APPLICATION_JSON), + ) + .andExpect(status().isOk) + }*/ @Test fun `test addTimeBoundary with missing parameters`() { diff --git a/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerUnitTest.kt b/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerUnitTest.kt index a7260972..19cb352b 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerUnitTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/controller/UserControllerUnitTest.kt @@ -2,6 +2,7 @@ package com.teamcaffiene.koja.controller import com.google.gson.Gson import com.google.gson.GsonBuilder +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.constants.ResponseConstant import com.teamcaffeine.koja.controller.TokenManagerController.Companion.createToken import com.teamcaffeine.koja.controller.TokenRequest @@ -53,25 +54,27 @@ class UserControllerUnitTest { private fun importEnvironmentVariables() { dotenv = Dotenv.load() - dotenv["KOJA_AWS_RDS_DATABASE_URL"]?.let { System.setProperty("KOJA_AWS_RDS_DATABASE_URL", it) } - dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME"]?.let { - System.setProperty( - "KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME", - it, - ) + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL, it) } - dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD"]?.let { - System.setProperty( - "KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD", - it, - ) + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME, it) + } + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_ID]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_ID, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY, it) + } + dotenv[EnvironmentVariableConstant.KOJA_JWT_SECRET]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_JWT_SECRET, it) } - - dotenv["GOOGLE_CLIENT_ID"]?.let { System.setProperty("GOOGLE_CLIENT_ID", it) } - dotenv["GOOGLE_CLIENT_SECRET"]?.let { System.setProperty("GOOGLE_CLIENT_SECRET", it) } - dotenv["GOOGLE_MAPS_API_KEY"]?.let { System.setProperty("GOOGLE_MAPS_API_KEY", it) } - - dotenv["KOJA_JWT_SECRET"]?.let { System.setProperty("KOJA_JWT_SECRET", it) } } /** diff --git a/src/test/kotlin/com/teamcaffiene/koja/service/CustomExtension.kt b/src/test/kotlin/com/teamcaffiene/koja/service/CustomExtension.kt index b67509cd..49f157af 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/service/CustomExtension.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/service/CustomExtension.kt @@ -1,5 +1,6 @@ package com.teamcaffiene.koja.service +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import io.github.cdimascio.dotenv.Dotenv import org.junit.jupiter.api.extension.BeforeEachCallback import org.junit.jupiter.api.extension.ExtensionContext @@ -9,16 +10,37 @@ class CustomExtension : BeforeEachCallback { override fun beforeEach(context: ExtensionContext) { val dotenv: Dotenv = Dotenv.load() - System.setProperty("KOJA_AWS_RDS_DATABASE_URL", dotenv["KOJA_AWS_RDS_DATABASE_URL"]!!) - System.setProperty("KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME", dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME"]!!) - System.setProperty("KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD", dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD"]!!) + System.setProperty( + EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL, + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL]!!, + ) + System.setProperty( + EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME, + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME]!!, + ) + System.setProperty( + EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD, + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD]!!, + ) // Set Google Sign In client ID and client secret properties - System.setProperty("GOOGLE_CLIENT_ID", dotenv["GOOGLE_CLIENT_ID"]!!) - System.setProperty("GOOGLE_CLIENT_SECRET", dotenv["GOOGLE_CLIENT_SECRET"]!!) - System.setProperty("GOOGLE_MAPS_API_KEY", dotenv["GOOGLE_MAPS_API_KEY"]!!) + System.setProperty( + EnvironmentVariableConstant.GOOGLE_CLIENT_ID, + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_ID]!!, + ) + System.setProperty( + EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET, + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET]!!, + ) + System.setProperty( + EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY, + dotenv[EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY]!!, + ) // Set JWT secret key property - System.setProperty("KOJA_JWT_SECRET", dotenv["KOJA_JWT_SECRET"]!!) + System.setProperty( + EnvironmentVariableConstant.KOJA_JWT_SECRET, + dotenv[EnvironmentVariableConstant.KOJA_JWT_SECRET]!!, + ) } } diff --git a/src/test/kotlin/com/teamcaffiene/koja/service/UserAccountManagerServiceTest.kt b/src/test/kotlin/com/teamcaffiene/koja/service/UserAccountManagerServiceTest.kt index c0e2412a..450f0222 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/service/UserAccountManagerServiceTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/service/UserAccountManagerServiceTest.kt @@ -35,26 +35,31 @@ class UserAccountManagerServiceTest { private fun importEnvironmentVariables() { dotenv = Dotenv.load() - dotenv["KOJA_AWS_RDS_DATABASE_URL"]?.let { System.setProperty("KOJA_AWS_RDS_DATABASE_URL", it) } - dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME"]?.let { - System.setProperty( - "KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME", - it, - ) + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL, it) } - dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD"]?.let { - System.setProperty( - "KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD", - it, - ) + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME, it) + } + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD, it) } - dotenv["GOOGLE_CLIENT_ID"]?.let { System.setProperty("GOOGLE_CLIENT_ID", it) } - dotenv["GOOGLE_CLIENT_SECRET"]?.let { System.setProperty("GOOGLE_CLIENT_SECRET", it) } - dotenv["GOOGLE_MAPS_API_KEY"]?.let { System.setProperty("GOOGLE_MAPS_API_KEY", it) } + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_ID]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_ID, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY, it) + } - dotenv["KOJA_JWT_SECRET"]?.let { System.setProperty("KOJA_JWT_SECRET", it) } + dotenv[EnvironmentVariableConstant.KOJA_JWT_SECRET]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_JWT_SECRET, it) + } } + @Test fun `deleteGoogleAccount should delete the correct user account`() { diff --git a/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceIntergrationTest.kt b/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceIntergrationTest.kt index e2e642c1..157fc264 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceIntergrationTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceIntergrationTest.kt @@ -1,5 +1,6 @@ package com.teamcaffiene.koja.service +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.controller.UserController import com.teamcaffeine.koja.dto.JWTFunctionality import com.teamcaffeine.koja.entity.TimeBoundary @@ -55,48 +56,51 @@ class UserCalendarServiceIntergrationTest { private fun importEnvironmentVariables() { dotenv = Dotenv.load() - dotenv["KOJA_AWS_RDS_DATABASE_URL"]?.let { System.setProperty("KOJA_AWS_RDS_DATABASE_URL", it) } - dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME"]?.let { - System.setProperty( - "KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME", - it, - ) + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL, it) } - dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD"]?.let { - System.setProperty( - "KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD", - it, - ) + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME, it) + } + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_ID]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_ID, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET, it) + } + dotenv[EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY]?.let { + System.setProperty(EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY, it) + } + dotenv[EnvironmentVariableConstant.KOJA_JWT_SECRET]?.let { + System.setProperty(EnvironmentVariableConstant.KOJA_JWT_SECRET, it) } - - dotenv["GOOGLE_CLIENT_ID"]?.let { System.setProperty("GOOGLE_CLIENT_ID", it) } - dotenv["GOOGLE_CLIENT_SECRET"]?.let { System.setProperty("GOOGLE_CLIENT_SECRET", it) } - dotenv["GOOGLE_MAPS_API_KEY"]?.let { System.setProperty("GOOGLE_MAPS_API_KEY", it) } - - dotenv["KOJA_JWT_SECRET"]?.let { System.setProperty("KOJA_JWT_SECRET", it) } } -/* - @Test - fun `test addTimeBoundary with valid time boundary`() { - val token = "validToken" - val userID = "user123" - // Prepare the user data in the database for the given token - val user = User(userID, "John Doe") - userRepository.save(user) + /* + @Test + fun `test addTimeBoundary with valid time boundary`() { + val token = "validToken" + val userID = "user123" - // Create a valid time boundary - val timeBoundary = TimeBoundary("Office hours", "09:00", "17:00", TimeBoundaryType.ALLOWED) + // Prepare the user data in the database for the given token + val user = User(userID, "John Doe") + userRepository.save(user) - // Perform the function call - val result = userCalendarService.addTimeBoundary(token, timeBoundary) + // Create a valid time boundary + val timeBoundary = TimeBoundary("Office hours", "09:00", "17:00", TimeBoundaryType.ALLOWED) - // Optionally, verify the database state after adding the time boundary - val retrievedUser = userRepository.findById(userID).orElse(null) - assertNotNull(retrievedUser) - assertTrue(result) - assertTrue(retrievedUser.getTimeBoundaries().contains(timeBoundary)) - }*/ + // Perform the function call + val result = userCalendarService.addTimeBoundary(token, timeBoundary) + + // Optionally, verify the database state after adding the time boundary + val retrievedUser = userRepository.findById(userID).orElse(null) + assertNotNull(retrievedUser) + assertTrue(result) + assertTrue(retrievedUser.getTimeBoundaries().contains(timeBoundary)) + }*/ @Test fun `test addTimeBoundary with invalid token`() { diff --git a/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceTest.kt b/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceTest.kt index 3297e383..877ef612 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/service/UserCalendarServiceTest.kt @@ -1,5 +1,6 @@ package com.teamcaffiene.koja.service +import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.controller.TokenManagerController import com.teamcaffeine.koja.controller.TokenRequest import com.teamcaffeine.koja.dto.JWTAuthDetailsDTO @@ -58,39 +59,82 @@ class UserCalendarServiceTest { private fun importEnvironmentVariables() { val dotenv: Dotenv = Dotenv.load() - System.setProperty("KOJA_AWS_RDS_DATABASE_URL", dotenv["KOJA_AWS_RDS_DATABASE_URL"]!!) - System.setProperty("KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME", dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME"]!!) - System.setProperty("KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD", dotenv["KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD"]!!) - System.setProperty("KOJA_AWS_DYNAMODB_ACCESS_KEY_ID", dotenv["KOJA_AWS_DYNAMODB_ACCESS_KEY_ID"]!!) - System.setProperty("KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET", dotenv["KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET"]!!) - System.setProperty("OPENAI_API_KEY", dotenv["OPENAI_API_KEY"]!!) - System.setProperty("SERVER_ADDRESS", dotenv["SERVER_ADDRESS"]!!) - if (dotenv["SERVER_PORT"] != null) { - System.setProperty("SERVER_PORT", dotenv["SERVER_PORT"]!!) - } else { - System.setProperty("SERVER_PORT", "") - } - + System.setProperty( + EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL, + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL]!!, + ) + System.setProperty( + EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME, + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME]!!, + ) + System.setProperty( + EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD, + dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD]!!, + ) + System.setProperty( + EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID, + dotenv[EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID]!!, + ) + System.setProperty( + EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET, + dotenv[EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET]!!, + ) + System.setProperty( + EnvironmentVariableConstant.OPENAI_API_KEY, + dotenv[EnvironmentVariableConstant.OPENAI_API_KEY]!!, + ) + System.setProperty( + EnvironmentVariableConstant.SERVER_ADDRESS, + dotenv[EnvironmentVariableConstant.SERVER_ADDRESS]!!, + ) + System.setProperty( + EnvironmentVariableConstant.SERVER_PORT, + dotenv[EnvironmentVariableConstant.SERVER_PORT] ?: "", + ) // Set Google Sign In client ID and client secret properties - System.setProperty("GOOGLE_CLIENT_ID", dotenv["GOOGLE_CLIENT_ID"]!!) - System.setProperty("GOOGLE_CLIENT_SECRET", dotenv["GOOGLE_CLIENT_SECRET"]!!) - System.setProperty("GOOGLE_MAPS_API_KEY", dotenv["GOOGLE_MAPS_API_KEY"]!!) - + System.setProperty( + EnvironmentVariableConstant.GOOGLE_CLIENT_ID, + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_ID]!!, + ) + System.setProperty( + EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET, + dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET]!!, + ) + System.setProperty( + EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY, + dotenv[EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY]!!, + ) // Set JWT secret key and other related properties - System.setProperty("KOJA_JWT_SECRET", dotenv["KOJA_JWT_SECRET"]!!) - System.setProperty("KOJA_ID_SECRET", dotenv["KOJA_ID_SECRET"]!!) - System.setProperty("KOJA_PRIVATE_KEY_PASS", dotenv["KOJA_PRIVATE_KEY_PASS"]!!) - System.setProperty("KOJA_PRIVATE_KEY_SALT", dotenv["KOJA_PRIVATE_KEY_SALT"]!!) + System.setProperty( + EnvironmentVariableConstant.KOJA_JWT_SECRET, + dotenv[EnvironmentVariableConstant.KOJA_JWT_SECRET]!!, + ) + System.setProperty( + EnvironmentVariableConstant.KOJA_ID_SECRET, + dotenv[EnvironmentVariableConstant.KOJA_ID_SECRET]!!, + ) + System.setProperty( + EnvironmentVariableConstant.KOJA_PRIVATE_KEY_PASS, + dotenv[EnvironmentVariableConstant.KOJA_PRIVATE_KEY_PASS]!!, + ) + System.setProperty( + EnvironmentVariableConstant.KOJA_PRIVATE_KEY_SALT, + dotenv[EnvironmentVariableConstant.KOJA_PRIVATE_KEY_SALT]!!, + ) } - /* @BeforeEach - fun setup() { - val dotenv: Dotenv = Dotenv.load() - System.setProperty("KOJA_JWT_SECRET", dotenv["KOJA_JWT_SECRET"]!!) - userRepository = mockk() - userAccountRepository = mockk() - userCalendarService = UserCalendarService(userRepository) - }*/ +// @BeforeEach +// fun setup() { +// val dotenv: Dotenv = Dotenv.load() +// System.setProperty( +// EnvironmentVariableConstant.KOJA_JWT_SECRET, +// dotenv[EnvironmentVariableConstant.KOJA_JWT_SECRET]!! +// ) +// +// userRepository = mockk() +// userAccountRepository = mockk() +// userCalendarService = UserCalendarService(userRepository) +// } @Test fun getAllUserEvents_with_null_token_throws_exception() { From 8986afd9809095955ae78944a02f8202ae36cbfc Mon Sep 17 00:00:00 2001 From: Marthinus Ettienne van Zyl - u19012366 Date: Wed, 11 Oct 2023 11:28:16 +0200 Subject: [PATCH 4/9] Introduced and migrated to Environmental variable constants file --- client/lib/Utils/constants_util.dart | 6 ++++-- .../Utils/environment_variable_constants.dart | 20 +++++++++++++++++++ client/lib/providers/service_provider.dart | 5 +++-- 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 client/lib/Utils/environment_variable_constants.dart diff --git a/client/lib/Utils/constants_util.dart b/client/lib/Utils/constants_util.dart index d049ed48..7ce349a0 100644 --- a/client/lib/Utils/constants_util.dart +++ b/client/lib/Utils/constants_util.dart @@ -1,8 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; -final String apiKey = dotenv.env['GOOGLE_MAPS_API_KEY'] ?? ""; -final String serverAddress = dotenv.env['SERVER_ADDRESS'] ?? ""; +import 'environment_variable_constants.dart'; + +final String apiKey = dotenv.env[EnvironmentVariableConstant.googleMapsApiKey] ?? ""; +final String serverAddress = dotenv.env[EnvironmentVariableConstant.serverAddress] ?? ""; const darkBlue = Color(0xFF1976D2); /// This store the list of locations diff --git a/client/lib/Utils/environment_variable_constants.dart b/client/lib/Utils/environment_variable_constants.dart new file mode 100644 index 00000000..b81de094 --- /dev/null +++ b/client/lib/Utils/environment_variable_constants.dart @@ -0,0 +1,20 @@ +class EnvironmentVariableConstant { + static const String kojaAwsRdsDatabaseUrl = "KOJA_AWS_RDS_DATABASE_URL"; + static const String kojaAwsRdsDatabaseAdminUsername = "KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME"; + static const String kojaAwsRdsDatabaseAdminPassword = "KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD"; + static const String kojaAwsDynamodbAccessKeyId = "KOJA_AWS_DYNAMODB_ACCESS_KEY_ID"; + static const String kojaAwsDynamodbAccessKeySecret = "KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET"; + static const String googleClientId = "GOOGLE_CLIENT_ID"; + static const String googleClientSecret = "GOOGLE_CLIENT_SECRET"; + static const String googleMapsApiKey = "GOOGLE_MAPS_API_KEY"; + static const String kojaJwtSecret = "KOJA_JWT_SECRET"; + static const String openaiApiKey = "OPENAI_API_KEY"; + static const String kojaIdSecret = "KOJA_ID_SECRET"; + static const String coverallsRepoToken = "COVERALLS_REPO_TOKEN"; + static const String kojaPrivateKeyPass = "KOJA_PRIVATE_KEY_PASS"; + static const String kojaPrivateKeySalt = "KOJA_PRIVATE_KEY_SALT"; + static const String aiPrivateKeyPass = "AI_PRIVATE_KEY_PASS"; + static const String aiPrivateKeySalt = "AI_PRIVATE_KEY_SALT"; + static const String serverAddress = "SERVER_ADDRESS"; + static const String serverPort = "SERVER_PORT"; +} \ No newline at end of file diff --git a/client/lib/providers/service_provider.dart b/client/lib/providers/service_provider.dart index d1cbdc28..b750bb54 100644 --- a/client/lib/providers/service_provider.dart +++ b/client/lib/providers/service_provider.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:flutter/services.dart'; +import 'package:koja/Utils/environment_variable_constants.dart'; import 'package:koja/models/user_time_boundary_model.dart'; import 'package:koja/providers/context_provider.dart'; import 'package:flutter/foundation.dart'; @@ -57,8 +58,8 @@ class ServiceProvider with ChangeNotifier { Future init() async { startLocationListner(); - _serverAddress = dotenv.get("SERVER_ADDRESS", fallback: "10.0.2.2"); - _serverPort = dotenv.get("SERVER_PORT", fallback: "8080"); + _serverAddress = dotenv.get(EnvironmentVariableConstant.serverAddress, fallback: "10.0.2.2"); + _serverPort = dotenv.get(EnvironmentVariableConstant.serverPort, fallback: "8080"); return this; } From 6eb8482c3559c9c493cb78f30cd08fc504c710aa Mon Sep 17 00:00:00 2001 From: Marthinus Ettienne van Zyl - u19012366 Date: Mon, 16 Oct 2023 12:16:06 +0200 Subject: [PATCH 5/9] Attempt to migrate to more robust deployment setup --- Dockerfile | 20 +---- build.gradle.kts | 2 +- .../com/teamcaffeine/koja/KojaApplication.kt | 81 +++++-------------- .../constants/EnvironmentVariableConstant.kt | 57 ++++++++----- 4 files changed, 60 insertions(+), 100 deletions(-) diff --git a/Dockerfile b/Dockerfile index f16556e0..40edcbfe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,24 +27,8 @@ WORKDIR /app COPY --from=builder /home/gradle/project/build/libs/ /app/ # Create .env file based on the environment variables of the environment where the Dockerfile is being built -RUN echo "KOJA_AWS_RDS_DATABASE_URL=$KOJA_AWS_RDS_DATABASE_URL" >> .env && \ - echo "KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME=$KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME" >> .env && \ - echo "KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD=$KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD" >> .env && \ - echo "KOJA_AWS_DYNAMODB_ACCESS_KEY_ID=$KOJA_AWS_DYNAMODB_ACCESS_KEY_ID" >> .env && \ - echo "KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET=$KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET" >> .env && \ - echo "GOOGLE_CLIENT_ID=$GOOGLE_CLIENT_ID" >> .env && \ - echo "GOOGLE_CLIENT_SECRET=$GOOGLE_CLIENT_SECRET" >> .env && \ - echo "KOJA_JWT_SECRET=$KOJA_JWT_SECRET" >> .env && \ - echo "KOJA_ID_SECRET=$KOJA_AI_SECRET" >> .env && \ - echo "GOOGLE_MAPS_API_KEY=$GOOGLE_MAPS_API_KEY" >> .env && \ - echo "OPENAI_API_KEY=$OPENAI_API_KEY" >> .env && \ - echo "COVERALLS_REPO_TOKEN=$COVERALLS_REPO_TOKEN" >> .env && \ - echo "KOJA_PRIVATE_KEY_PASS=$KOJA_PRIVATE_KEY_PASS" >> .env && \ - echo "KOJA_PRIVATE_KEY_SALT=$KOJA_PRIVATE_KEY_SALT" >> .env && \ - echo "AI_PRIVATE_KEY_PASS=$AI_PRIVATE_KEY_PASS" >> .env && \ - echo "AI_PRIVATE_KEY_SALT=$AI_PRIVATE_KEY_SALT" >> .env && \ - echo "SERVER_ADDRESS=$SERVER_ADDRESS" >> .env && \ - echo "SERVER_PORT=$SERVER_PORT" >> .env +RUN echo "koja_server_address=$koja_server_address" >> .env && \ + echo "koja_server_port=$koja_server_port" >> .env # Start the built spring boot project when the Docker container is started diff --git a/build.gradle.kts b/build.gradle.kts index f6dd06a6..9dba3f20 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -55,7 +55,7 @@ dependencies { implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2") implementation("software.amazon.awssdk:dynamodb:2.20.115") implementation("org.bouncycastle:bcprov-jdk15on:1.68") - + implementation("com.google.cloud:google-cloud-secretmanager:2.28.0") implementation(kotlin("stdlib-jdk8")) } diff --git a/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt b/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt index e2d13741..b0f204d1 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt @@ -1,5 +1,7 @@ package com.teamcaffeine.koja +import com.google.cloud.secretmanager.v1.SecretManagerServiceClient +import com.google.cloud.secretmanager.v1.SecretVersionName import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import io.github.cdimascio.dotenv.Dotenv import org.springframework.boot.autoconfigure.SpringBootApplication @@ -10,72 +12,25 @@ import java.lang.System.setProperty @SpringBootApplication(exclude = [SecurityAutoConfiguration::class]) class KojaApplication +const val envSecretVersion = "latest" +const val projectId = "koja-401505" + +fun getSecret(projectId: String, secretId: String, versionId: String): String { + SecretManagerServiceClient.create().use { client -> + val secretVersionName = SecretVersionName.of(projectId, secretId, versionId) + val response = client.accessSecretVersion(secretVersionName) + return response.payload.data.toStringUtf8() + } +} + fun main(args: Array) { val dotenv: Dotenv = Dotenv.load() - setProperty( - EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL, - dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_URL]!!, - ) - setProperty( - EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME, - dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME]!!, - ) - setProperty( - EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD, - dotenv[EnvironmentVariableConstant.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD]!!, - ) - setProperty( - EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID, - dotenv[EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID]!!, - ) - setProperty( - EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET, - dotenv[EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET]!!, - ) - setProperty( - EnvironmentVariableConstant.OPENAI_API_KEY, - dotenv[EnvironmentVariableConstant.OPENAI_API_KEY]!!, - ) - setProperty( - EnvironmentVariableConstant.SERVER_ADDRESS, - dotenv[EnvironmentVariableConstant.SERVER_ADDRESS]!!, - ) - setProperty( - EnvironmentVariableConstant.SERVER_PORT, - dotenv[EnvironmentVariableConstant.SERVER_PORT] ?: "", - ) - // Set Google Sign In client ID and client secret properties - setProperty( - EnvironmentVariableConstant.GOOGLE_CLIENT_ID, - dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_ID]!!, - ) - setProperty( - EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET, - dotenv[EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET]!!, - ) - setProperty( - EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY, - dotenv[EnvironmentVariableConstant.GOOGLE_MAPS_API_KEY]!!, - ) - - // Set JWT secret key property - setProperty( - EnvironmentVariableConstant.KOJA_JWT_SECRET, - dotenv[EnvironmentVariableConstant.KOJA_JWT_SECRET]!!, - ) - setProperty( - EnvironmentVariableConstant.KOJA_ID_SECRET, - dotenv[EnvironmentVariableConstant.KOJA_ID_SECRET]!!, - ) - setProperty( - EnvironmentVariableConstant.KOJA_PRIVATE_KEY_PASS, - dotenv[EnvironmentVariableConstant.KOJA_PRIVATE_KEY_PASS]!!, - ) - setProperty( - EnvironmentVariableConstant.KOJA_PRIVATE_KEY_SALT, - dotenv[EnvironmentVariableConstant.KOJA_PRIVATE_KEY_SALT]!!, - ) + EnvironmentVariableConstant.asMap.forEach { (key, secretName) -> + val valueFromEnv = dotenv[key] + val finalValue = valueFromEnv ?: getSecret(projectId, secretName, envSecretVersion) + setProperty(key, finalValue) + } runApplication(*args) } diff --git a/src/main/kotlin/com/teamcaffeine/koja/constants/EnvironmentVariableConstant.kt b/src/main/kotlin/com/teamcaffeine/koja/constants/EnvironmentVariableConstant.kt index 0c304462..5204bb9f 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/constants/EnvironmentVariableConstant.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/constants/EnvironmentVariableConstant.kt @@ -1,22 +1,43 @@ package com.teamcaffeine.koja.constants object EnvironmentVariableConstant { - const val KOJA_AWS_RDS_DATABASE_URL = "KOJA_AWS_RDS_DATABASE_URL" - const val KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME = "KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME" - const val KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD = "KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD" - const val KOJA_AWS_DYNAMODB_ACCESS_KEY_ID = "KOJA_AWS_DYNAMODB_ACCESS_KEY_ID" - const val KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET = "KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET" - const val GOOGLE_CLIENT_ID = "GOOGLE_CLIENT_ID" - const val GOOGLE_CLIENT_SECRET = "GOOGLE_CLIENT_SECRET" - const val GOOGLE_MAPS_API_KEY = "GOOGLE_MAPS_API_KEY" - const val KOJA_JWT_SECRET = "KOJA_JWT_SECRET" - const val OPENAI_API_KEY = "OPENAI_API_KEY" - const val KOJA_ID_SECRET = "KOJA_ID_SECRET" - const val COVERALLS_REPO_TOKEN = "COVERALLS_REPO_TOKEN" - const val KOJA_PRIVATE_KEY_PASS = "KOJA_PRIVATE_KEY_PASS" - const val KOJA_PRIVATE_KEY_SALT = "KOJA_PRIVATE_KEY_SALT" - const val AI_PRIVATE_KEY_PASS = "AI_PRIVATE_KEY_PASS" - const val AI_PRIVATE_KEY_SALT = "AI_PRIVATE_KEY_SALT" - const val SERVER_ADDRESS = "SERVER_ADDRESS" - const val SERVER_PORT = "SERVER_PORT" + const val KOJA_AWS_RDS_DATABASE_URL = "koja_aws_rds_database_url" + const val KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME = "koja_aws_rds_database_admin_username" + const val KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD = "koja_aws_rds_database_admin_password" + const val KOJA_AWS_DYNAMODB_ACCESS_KEY_ID = "koja_aws_dynamodb_access_key_id" + const val KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET = "koja_aws_dynamodb_access_key_secret" + const val GOOGLE_CLIENT_ID = "koja_google_client_id" + const val GOOGLE_CLIENT_SECRET = "koja_google_client_secret" + const val GOOGLE_MAPS_API_KEY = "koja_google_maps_api_key" + const val KOJA_JWT_SECRET = "koja_jwt_secret" + const val OPENAI_API_KEY = "koja_openai_api_key" + const val KOJA_ID_SECRET = "koja_id_secret" + const val COVERALLS_REPO_TOKEN = "koja_coveralls_repo_token" + const val KOJA_PRIVATE_KEY_PASS = "koja_private_key_password" + const val KOJA_PRIVATE_KEY_SALT = "koja_private_key_salt" + const val AI_PRIVATE_KEY_PASS = "koja_ai_private_key_password" + const val AI_PRIVATE_KEY_SALT = "koja_ai_private_key_salt" + const val SERVER_ADDRESS = "koja_server_address" + const val SERVER_PORT = "koja_server_port" + + val asMap: Map = mapOf( + "KOJA_AWS_RDS_DATABASE_URL" to KOJA_AWS_RDS_DATABASE_URL, + "KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME" to KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME, + "KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD" to KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD, + "KOJA_AWS_DYNAMODB_ACCESS_KEY_ID" to KOJA_AWS_DYNAMODB_ACCESS_KEY_ID, + "KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET" to KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET, + "GOOGLE_CLIENT_ID" to GOOGLE_CLIENT_ID, + "GOOGLE_CLIENT_SECRET" to GOOGLE_CLIENT_SECRET, + "GOOGLE_MAPS_API_KEY" to GOOGLE_MAPS_API_KEY, + "KOJA_JWT_SECRET" to KOJA_JWT_SECRET, + "OPENAI_API_KEY" to OPENAI_API_KEY, + "KOJA_ID_SECRET" to KOJA_ID_SECRET, + "COVERALLS_REPO_TOKEN" to COVERALLS_REPO_TOKEN, + "KOJA_PRIVATE_KEY_PASS" to KOJA_PRIVATE_KEY_PASS, + "KOJA_PRIVATE_KEY_SALT" to KOJA_PRIVATE_KEY_SALT, + "AI_PRIVATE_KEY_PASS" to AI_PRIVATE_KEY_PASS, + "AI_PRIVATE_KEY_SALT" to AI_PRIVATE_KEY_SALT, + "SERVER_ADDRESS" to SERVER_ADDRESS, + "SERVER_PORT" to SERVER_PORT, + ) } From ec3cb9076e0f7c02babe9757111c50040057f057 Mon Sep 17 00:00:00 2001 From: Marthinus Ettienne van Zyl - u19012366 Date: Mon, 16 Oct 2023 12:58:12 +0200 Subject: [PATCH 6/9] Fix code to align with coding standards --- .../teamcaffeine/koja/service/GoogleCalendarAdapterService.kt | 4 +--- .../teamcaffeine/koja/service/UserAccountManagerService.kt | 2 +- .../koja/controller/TokenManagerControllerUnitTest.kt | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/teamcaffeine/koja/service/GoogleCalendarAdapterService.kt b/src/main/kotlin/com/teamcaffeine/koja/service/GoogleCalendarAdapterService.kt index 0ed70a1e..91314cfc 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/service/GoogleCalendarAdapterService.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/service/GoogleCalendarAdapterService.kt @@ -225,13 +225,11 @@ class GoogleCalendarAdapterService( timeBoundary.user = newUser userRepository.save(newUser) - val awsCreds = AwsBasicCredentials.create( System.getProperty(EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID), - System.getProperty(EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET) + System.getProperty(EnvironmentVariableConstant.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET), ) - val dynamoDBClient = DynamoDbClient.builder() .region(Region.EU_NORTH_1) .credentialsProvider { awsCreds } diff --git a/src/main/kotlin/com/teamcaffeine/koja/service/UserAccountManagerService.kt b/src/main/kotlin/com/teamcaffeine/koja/service/UserAccountManagerService.kt index 4a5bbf80..dc85d727 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/service/UserAccountManagerService.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/service/UserAccountManagerService.kt @@ -39,7 +39,7 @@ class UserAccountManagerService(private val userAccountRepository: UserAccountRe val updatedCredentials = refreshAccessToken( System.getProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_ID), System.getProperty(EnvironmentVariableConstant.GOOGLE_CLIENT_SECRET), - userAccount.refreshToken + userAccount.refreshToken, ) if (updatedCredentials != null) { userTokens.add( diff --git a/src/test/kotlin/com/teamcaffiene/koja/controller/TokenManagerControllerUnitTest.kt b/src/test/kotlin/com/teamcaffiene/koja/controller/TokenManagerControllerUnitTest.kt index c8a36708..83b4dcbb 100644 --- a/src/test/kotlin/com/teamcaffiene/koja/controller/TokenManagerControllerUnitTest.kt +++ b/src/test/kotlin/com/teamcaffiene/koja/controller/TokenManagerControllerUnitTest.kt @@ -1,6 +1,5 @@ package com.teamcaffiene.koja.controller -import com.teamcaffeine.koja.constants.EnvironmentVariableConstant import com.teamcaffeine.koja.controller.TokenManagerController class TokenManagerControllerUnitTest { From 2b65d01079530b9701f5187af7bccd221ab15c12 Mon Sep 17 00:00:00 2001 From: Marthinus Ettienne van Zyl - u19012366 Date: Mon, 16 Oct 2023 13:03:56 +0200 Subject: [PATCH 7/9] Fix more code to align with standards --- .../kotlin/com/teamcaffeine/koja/service/AIUserDataService.kt | 2 +- .../com/teamcaffeine/koja/service/UserCalendarService.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/teamcaffeine/koja/service/AIUserDataService.kt b/src/main/kotlin/com/teamcaffeine/koja/service/AIUserDataService.kt index b09c4ff4..15c14563 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/service/AIUserDataService.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/service/AIUserDataService.kt @@ -199,7 +199,7 @@ class AIUserDataService(private val userRepository: UserRepository, private val if (timeSlotDuration / eventDuration >= 2) { var timeSlotOffset = 0L while (timeSlot.startTime.plusSeconds(timeSlotOffset) - .isBefore(timeSlot.endTime) + .isBefore(timeSlot.endTime) ) { tempTimeSlots.add( TimeSlot( diff --git a/src/main/kotlin/com/teamcaffeine/koja/service/UserCalendarService.kt b/src/main/kotlin/com/teamcaffeine/koja/service/UserCalendarService.kt index 000a44a1..aebdd45a 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/service/UserCalendarService.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/service/UserCalendarService.kt @@ -594,9 +594,9 @@ class UserCalendarService( if (recommendations != null) { toReturn = recommendations.mapValues { entry -> entry.value.l().map { - value -> + value -> value.m()["week_days"]?.m()?.mapValues { - attr -> + attr -> attr.value.l().map { it.s() ?: "" } From ba82996f0b159fd2ff830c7b41418fe7fbf7826c Mon Sep 17 00:00:00 2001 From: Marthinus Ettienne van Zyl - u19012366 Date: Mon, 16 Oct 2023 13:19:00 +0200 Subject: [PATCH 8/9] Update GitHub actions to map env variables correctly --- .github/workflows/main2.yml | 80 ++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/.github/workflows/main2.yml b/.github/workflows/main2.yml index 48824dad..d5b541c9 100644 --- a/.github/workflows/main2.yml +++ b/.github/workflows/main2.yml @@ -17,34 +17,34 @@ jobs: - name: Create .env run: | - echo KOJA_AWS_RDS_DATABASE_URL=${{ secrets.KOJA_AWS_RDS_DATABASE_URL }} >> client/assets/.env - echo KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME=${{ secrets.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME }} >> client/assets/.env - echo KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD=${{ secrets.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD }} >> client/assets/.env - echo KOJA_AWS_DYNAMODB_ACCESS_KEY_ID=${{ secrets.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID }} >> client/assets/.env - echo KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET=${{ secrets.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET }} >> client/assets/.env - echo GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} >> client/assets/.env - echo GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }} >> client/assets/.env - echo KOJA_JWT_SECRET=${{ secrets.KOJA_JWT_SECRET }} >> client/assets/.env - echo GOOGLE_MAPS_API_KEY=${{ secrets.GOOGLE_MAPS_API_KEY }} >> client/assets/.env - echo OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} >> client/assets/.env - echo KOJA_ID_SECRET=${{ secrets.KOJA_ID_SECRET }} >> client/assets/.env - echo COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_REPO_TOKEN }} >> client/assets/.env - echo KOJA_PRIVATE_KEY_PASS=${{ secrets.KOJA_PRIVATE_KEY_PASS }} >> client/assets/.env - echo KOJA_PRIVATE_KEY_SALT=${{ secrets.KOJA_PRIVATE_KEY_SALT }} >> client/assets/.env - echo AI_PRIVATE_KEY_PASS=${{ secrets.AI_PRIVATE_KEY_PASS }} >> client/assets/.env - echo AI_PRIVATE_KEY_SALT=${{ secrets.AI_PRIVATE_KEY_SALT }} >> client/assets/.env - echo SERVER_ADDRESS=${{ secrets.SERVER_ADDRESS }} >> client/assets/.env - echo SERVER_PORT=${{ secrets.SERVER_PORT }} >> client/assets/.env + echo koja_aws_rds_database_url=${{ secrets.KOJA_AWS_RDS_DATABASE_URL }} >> client/assets/.env + echo koja_aws_rds_database_admin_username=${{ secrets.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME }} >> client/assets/.env + echo koja_aws_rds_database_admin_password=${{ secrets.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD }} >> client/assets/.env + echo koja_aws_dynamodb_access_key_id=${{ secrets.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID }} >> client/assets/.env + echo koja_aws_dynamodb_access_key_secret=${{ secrets.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET }} >> client/assets/.env + echo koja_google_client_id=${{ secrets.GOOGLE_CLIENT_ID }} >> client/assets/.env + echo koja_google_client_secret=${{ secrets.GOOGLE_CLIENT_SECRET }} >> client/assets/.env + echo koja_jwt_secret=${{ secrets.KOJA_JWT_SECRET }} >> client/assets/.env + echo koja_google_maps_api_key=${{ secrets.GOOGLE_MAPS_API_KEY }} >> client/assets/.env + echo koja_openai_api_key=${{ secrets.OPENAI_API_KEY }} >> client/assets/.env + echo koja_id_secret=${{ secrets.KOJA_ID_SECRET }} >> client/assets/.env + echo koja_coveralls_repo_token=${{ secrets.COVERALLS_REPO_TOKEN }} >> client/assets/.env + echo koja_private_key_password=${{ secrets.KOJA_PRIVATE_KEY_PASS }} >> client/assets/.env + echo koja_private_key_salt=${{ secrets.KOJA_PRIVATE_KEY_SALT }} >> client/assets/.env + echo koja_ai_private_key_password=${{ secrets.AI_PRIVATE_KEY_PASS }} >> client/assets/.env + echo koja_ai_private_key_salt=${{ secrets.AI_PRIVATE_KEY_SALT }} >> client/assets/.env + echo koja_server_address=${{ secrets.SERVER_ADDRESS }} >> client/assets/.env + echo koja_server_port=${{ secrets.SERVER_PORT }} >> client/assets/.env - name: Set up Flutter uses: subosito/flutter-action@v1 with: flutter-version: '3.10' - + - name: Install Flutter dependencies run: flutter pub get working-directory: client - + - name: Run Flutter linter run: flutter analyze working-directory: client @@ -71,30 +71,30 @@ jobs: - name: Create .env run: | - echo KOJA_AWS_RDS_DATABASE_URL=${{ secrets.KOJA_AWS_RDS_DATABASE_URL }} >> .env - echo KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME=${{ secrets.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME }} >> .env - echo KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD=${{ secrets.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD }} >> .env - echo KOJA_AWS_DYNAMODB_ACCESS_KEY_ID=${{ secrets.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID }} >> .env - echo KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET=${{ secrets.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET }} >> .env - echo GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} >> .env - echo GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }} >> .env - echo KOJA_JWT_SECRET=${{ secrets.KOJA_JWT_SECRET }} >> .env - echo GOOGLE_MAPS_API_KEY=${{ secrets.GOOGLE_MAPS_API_KEY }} >> .env - echo OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} >> .env - echo KOJA_ID_SECRET=${{ secrets.KOJA_ID_SECRET }} >> .env - echo COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_REPO_TOKEN }} >> .env - echo KOJA_PRIVATE_KEY_PASS=${{ secrets.KOJA_PRIVATE_KEY_PASS }} >> .env - echo KOJA_PRIVATE_KEY_SALT=${{ secrets.KOJA_PRIVATE_KEY_SALT }} >> .env - echo AI_PRIVATE_KEY_PASS=${{ secrets.AI_PRIVATE_KEY_PASS }} >> .env - echo AI_PRIVATE_KEY_SALT=${{ secrets.AI_PRIVATE_KEY_SALT }} >> .env - echo SERVER_ADDRESS=${{ secrets.SERVER_ADDRESS }} >> .env - echo SERVER_PORT=${{ secrets.SERVER_PORT }} >> .env + echo koja_aws_rds_database_url=${{ secrets.KOJA_AWS_RDS_DATABASE_URL }} >> .env + echo koja_aws_rds_database_admin_username=${{ secrets.KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME }} >> .env + echo koja_aws_rds_database_admin_password=${{ secrets.KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD }} >> .env + echo koja_aws_dynamodb_access_key_id=${{ secrets.KOJA_AWS_DYNAMODB_ACCESS_KEY_ID }} >> .env + echo koja_aws_dynamodb_access_key_secret=${{ secrets.KOJA_AWS_DYNAMODB_ACCESS_KEY_SECRET }} >> .env + echo koja_google_client_id=${{ secrets.GOOGLE_CLIENT_ID }} >> .env + echo koja_google_client_secret=${{ secrets.GOOGLE_CLIENT_SECRET }} >> .env + echo koja_jwt_secret=${{ secrets.KOJA_JWT_SECRET }} >> .env + echo koja_google_maps_api_key=${{ secrets.GOOGLE_MAPS_API_KEY }} >> .env + echo koja_openai_api_key=${{ secrets.OPENAI_API_KEY }} >> .env + echo koja_id_secret=${{ secrets.KOJA_ID_SECRET }} >> .env + echo koja_coveralls_repo_token=${{ secrets.COVERALLS_REPO_TOKEN }} >> .env + echo koja_private_key_password=${{ secrets.KOJA_PRIVATE_KEY_PASS }} >> .env + echo koja_private_key_salt=${{ secrets.KOJA_PRIVATE_KEY_SALT }} >> .env + echo koja_ai_private_key_password=${{ secrets.AI_PRIVATE_KEY_PASS }} >> .env + echo koja_ai_private_key_salt=${{ secrets.AI_PRIVATE_KEY_SALT }} >> .env + echo koja_server_address=${{ secrets.SERVER_ADDRESS }} >> .env + echo koja_server_port=${{ secrets.SERVER_PORT }} >> .env - name: Run Linter run: ./gradlew ktlintCheck - name: Run Tests run: ./gradlew test - + - name: Build Spring Boot project - run: ./gradlew build -x test -x check + run: ./gradlew build -x test -x check \ No newline at end of file From f7225ab949691d5a8b3965c300026579e9b1c7d0 Mon Sep 17 00:00:00 2001 From: Marthinus Ettienne van Zyl - u19012366 Date: Mon, 16 Oct 2023 15:50:33 +0200 Subject: [PATCH 9/9] Fix deployment bugs --- .../com/teamcaffeine/koja/KojaApplication.kt | 6 +++--- src/main/resources/application.properties | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt b/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt index b0f204d1..198f1259 100644 --- a/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt +++ b/src/main/kotlin/com/teamcaffeine/koja/KojaApplication.kt @@ -26,10 +26,10 @@ fun getSecret(projectId: String, secretId: String, versionId: String): String { fun main(args: Array) { val dotenv: Dotenv = Dotenv.load() - EnvironmentVariableConstant.asMap.forEach { (key, secretName) -> - val valueFromEnv = dotenv[key] + EnvironmentVariableConstant.asMap.forEach { (_, secretName) -> + val valueFromEnv = dotenv[secretName] val finalValue = valueFromEnv ?: getSecret(projectId, secretName, envSecretVersion) - setProperty(key, finalValue) + setProperty(secretName, finalValue) } runApplication(*args) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b3e1d3e7..b98c52af 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,16 +1,16 @@ -spring.datasource.url=${KOJA_AWS_RDS_DATABASE_URL} -spring.datasource.username=${KOJA_AWS_RDS_DATABASE_ADMIN_USERNAME} -spring.datasource.password=${KOJA_AWS_RDS_DATABASE_ADMIN_PASSWORD} +spring.datasource.url=${koja_aws_rds_database_url} +spring.datasource.username=${koja_aws_rds_database_admin_username} +spring.datasource.password=${koja_aws_rds_database_admin_password} spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect spring.jpa.show-sql=true spring.jpa.hibernate.ddl-auto=update -google.client.client-id=${GOOGLE_CLIENT_ID} -google.client.client-secret=${GOOGLE_CLIENT_SECRET} +google.client.client-id=${koja_google_client_id} +google.client.client-secret=${koja_google_client_secret} google.client.redirectUri=http://localhost:8080 spring.security.oauth2.client.registration.google.scope=https://www.googleapis.com/auth/calendar -spring.security.oauth2.client.registration.google.client-id=${GOOGLE_CLIENT_ID} -spring.security.oauth2.client.registration.google.client-secret=${GOOGLE_CLIENT_SECRET} +spring.security.oauth2.client.registration.google.client-id=${koja_google_client_id} +spring.security.oauth2.client.registration.google.client-secret=${koja_google_client_secret} spring.security.oauth2.client.registration.google.redirect-uri=http://localhost:8080 spring.jpa.open-in-view=false server.address=0.0.0.0