From 47c3334b526197bd95add2789d1acc5ce415512c Mon Sep 17 00:00:00 2001 From: Bezhou Feng Date: Mon, 5 Apr 2021 23:27:50 -0400 Subject: [PATCH] feat(v2 backend): updated the hack flavor to use v2 endpoints in the client (#1979) * :building_construction: refactor: updated the hack flavor to use v2 endpoints in the client * Update Endpoints to support our cloud functions and static content URLs * Update WhoService and ContentService to support new URLs * Add v2 Firebase project configs for the hack flavor Closes #1971 * Address review comments * Remove old prod code * Add TODOs --- .../android/app/src/hack/google-services.json | 17 +++++----- client/ios/Podfile.lock | 2 +- .../ios/config/hack/GoogleService-Info.plist | 16 +++++----- client/lib/api/content/content_loading.dart | 2 +- client/lib/api/endpoints.dart | 31 +++++++++++-------- client/lib/api/who_service.dart | 4 +-- client/lib/main.dart | 5 ++- 7 files changed, 39 insertions(+), 38 deletions(-) diff --git a/client/android/app/src/hack/google-services.json b/client/android/app/src/hack/google-services.json index 049657753a..afa30b5fd9 100644 --- a/client/android/app/src/hack/google-services.json +++ b/client/android/app/src/hack/google-services.json @@ -1,38 +1,37 @@ { "project_info": { - "project_number": "1019264280603", - "firebase_url": "https://who-mh-hack.firebaseio.com", - "project_id": "who-mh-hack", - "storage_bucket": "who-mh-hack.appspot.com" + "project_number": "782697208208", + "project_id": "who-mh2-dev1", + "storage_bucket": "who-mh2-dev1.appspot.com" }, "client": [ { "client_info": { - "mobilesdk_app_id": "1:1019264280603:android:79ab878c37831d1768b0be", + "mobilesdk_app_id": "1:782697208208:android:274abd32c3cd7148117b15", "android_client_info": { "package_name": "org.who.WHOMyHealth" } }, "oauth_client": [ { - "client_id": "1019264280603-ckd61pshej0dhtlp1a3vgqleukn3pvb8.apps.googleusercontent.com", + "client_id": "782697208208-eu469qapogtekc4uqhlfokim7hd4mf92.apps.googleusercontent.com", "client_type": 3 } ], "api_key": [ { - "current_key": "AIzaSyBf0EUssHwLrTBVuH7JR_0f2Ur_OosuCro" + "current_key": "AIzaSyALEM_u9zcqjuYpEYONA0RoR_KubflX-sU" } ], "services": { "appinvite_service": { "other_platform_oauth_client": [ { - "client_id": "1019264280603-ckd61pshej0dhtlp1a3vgqleukn3pvb8.apps.googleusercontent.com", + "client_id": "782697208208-eu469qapogtekc4uqhlfokim7hd4mf92.apps.googleusercontent.com", "client_type": 3 }, { - "client_id": "1019264280603-ess3r5dam39hur3aehgd3ob6hl6pjuf1.apps.googleusercontent.com", + "client_id": "782697208208-kkm2vf12l0js9ltphusvlr79c2cmoe6v.apps.googleusercontent.com", "client_type": 2, "ios_info": { "bundle_id": "int.who.WHOMyHealth" diff --git a/client/ios/Podfile.lock b/client/ios/Podfile.lock index cafe652f6c..afc269b4c9 100644 --- a/client/ios/Podfile.lock +++ b/client/ios/Podfile.lock @@ -273,4 +273,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 9d4c3d65f49f1f96ea75d153f1d9d301a0abef49 -COCOAPODS: 1.10.0 +COCOAPODS: 1.10.1 diff --git a/client/ios/config/hack/GoogleService-Info.plist b/client/ios/config/hack/GoogleService-Info.plist index 438fee63ef..6f0bf43439 100644 --- a/client/ios/config/hack/GoogleService-Info.plist +++ b/client/ios/config/hack/GoogleService-Info.plist @@ -3,21 +3,21 @@ CLIENT_ID - 1019264280603-ess3r5dam39hur3aehgd3ob6hl6pjuf1.apps.googleusercontent.com + 782697208208-kkm2vf12l0js9ltphusvlr79c2cmoe6v.apps.googleusercontent.com REVERSED_CLIENT_ID - com.googleusercontent.apps.1019264280603-ess3r5dam39hur3aehgd3ob6hl6pjuf1 + com.googleusercontent.apps.782697208208-kkm2vf12l0js9ltphusvlr79c2cmoe6v API_KEY - AIzaSyATWv6UdIffm2lQyXvpog_HIESeaMOILjs + AIzaSyASZVUTMDzfxud-RdicFbH2nPsMlTL-JvI GCM_SENDER_ID - 1019264280603 + 782697208208 PLIST_VERSION 1 BUNDLE_ID int.who.WHOMyHealth PROJECT_ID - who-mh-hack + who-mh2-dev1 STORAGE_BUCKET - who-mh-hack.appspot.com + who-mh2-dev1.appspot.com IS_ADS_ENABLED IS_ANALYTICS_ENABLED @@ -29,8 +29,6 @@ IS_SIGNIN_ENABLED GOOGLE_APP_ID - 1:1019264280603:ios:f670199389d1884268b0be - DATABASE_URL - https://who-mh-hack.firebaseio.com + 1:782697208208:ios:74fff45695d1a3c2117b15 \ No newline at end of file diff --git a/client/lib/api/content/content_loading.dart b/client/lib/api/content/content_loading.dart index 39e5573ee0..f0edc2773a 100644 --- a/client/lib/api/content/content_loading.dart +++ b/client/lib/api/content/content_loading.dart @@ -15,7 +15,7 @@ class ContentService { static final String baseAssetPath = 'assets/content_bundles'; // no trailing ContentService({@required Endpoint endpoint}) - : baseContentURL = '${endpoint.serviceUrl}/content/bundles'; + : baseContentURL = '${endpoint.staticContentUrl}/content/bundles'; /// Load a localized content bundle loaded preferentially from the network, falling back /// to a local asset. If no bundle can be found with the specified name an exception is thrown. diff --git a/client/lib/api/endpoints.dart b/client/lib/api/endpoints.dart index c35d0a8319..096ca245be 100644 --- a/client/lib/api/endpoints.dart +++ b/client/lib/api/endpoints.dart @@ -2,34 +2,39 @@ class Endpoint { static const _whoMhPrefix = 'who-mh-'; - static const _prodProjectId = 'who-mh-prod'; - static const _prodServiceUrl = 'https://covid19app.who.int'; + static const _whoMh2Prefix = 'who-mh2-'; - static bool _isProd(String projectId) { - return projectId == _prodProjectId; - } + // TODO: Figure out a way to avoid hardcoding regions in client code. + static const _region = 'europe-west6'; static String _projectIdShort(String projectId) { - if (!projectId.startsWith(_whoMhPrefix)) { + if (!projectId.startsWith(_whoMh2Prefix) && + !projectId.startsWith(_whoMhPrefix)) { throw Exception( "Project: $projectId doesn't match prefix: $_whoMhPrefix"); } - return projectId.substring(_whoMhPrefix.length); + return projectId.startsWith(_whoMh2Prefix) + ? projectId.substring(_whoMh2Prefix.length) + : projectId.substring(_whoMhPrefix.length); } static String _serviceUrl(String projectId) { - if (_isProd(projectId)) { - return _prodServiceUrl; - } - return 'https://${_projectIdShort(projectId)}.whocoronavirus.org'; + return 'https://${_region}-${projectId}.cloudfunctions.net'; + } + + static String _staticContentUrl(String projectId) { + return 'https://${projectId}.web.app'; } + // TODO: Hook up prod endpoints once V2 is deployed in prod. final bool isProd; final String projectIdShort; final String serviceUrl; + final String staticContentUrl; Endpoint(String projectId) - : isProd = _isProd(projectId), + : isProd = false, projectIdShort = _projectIdShort(projectId), - serviceUrl = _serviceUrl(projectId); + serviceUrl = _serviceUrl(projectId), + staticContentUrl = _staticContentUrl(projectId); } diff --git a/client/lib/api/who_service.dart b/client/lib/api/who_service.dart index 62dadb767a..e75893e2db 100644 --- a/client/lib/api/who_service.dart +++ b/client/lib/api/who_service.dart @@ -12,7 +12,7 @@ import 'package:firebase_performance/firebase_performance.dart'; class WhoService { final String serviceUrl; - WhoService({@required String endpoint}) : serviceUrl = '$endpoint/WhoService'; + WhoService({@required String endpoint}) : serviceUrl = endpoint; final _MetricHttpClient http = _MetricHttpClient( Client(), @@ -105,7 +105,7 @@ class _MetricHttpClient extends BaseClient { try { response = await _inner.send(request); metric - ..responsePayloadSize = response.contentLength + ..responsePayloadSize = response.contentLength ?? 0 ..responseContentType = response.headers['Content-Type'] ..requestPayloadSize = request.contentLength ..httpResponseCode = response.statusCode; diff --git a/client/lib/main.dart b/client/lib/main.dart index 5dcebb28f5..ca8400bce5 100644 --- a/client/lib/main.dart +++ b/client/lib/main.dart @@ -168,9 +168,8 @@ class _MyAppState extends State with WidgetsBindingObserver { initialData: UserPreferencesStore.empty(), ), ProxyProvider( - update: (_, Endpoint endpoint, __) => WhoService( - endpoint: endpoint.serviceUrl, - )), + update: (_, Endpoint endpoint, __) => + WhoService(endpoint: endpoint.serviceUrl)), ProxyProvider2( update: (_, WhoService service, UserPreferencesStore prefs, __) { final ret = Notifications(service: service, prefs: prefs);