Skip to content

Commit

Permalink
feat(v2 backend): updated the hack flavor to use v2 endpoints in the …
Browse files Browse the repository at this point in the history
…client (#1979)

* 🏗️ 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
  • Loading branch information
bezfeng committed Apr 6, 2021
1 parent 78c43d4 commit 47c3334
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 38 deletions.
17 changes: 8 additions & 9 deletions 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"
Expand Down
2 changes: 1 addition & 1 deletion client/ios/Podfile.lock
Expand Up @@ -273,4 +273,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 9d4c3d65f49f1f96ea75d153f1d9d301a0abef49

COCOAPODS: 1.10.0
COCOAPODS: 1.10.1
16 changes: 7 additions & 9 deletions client/ios/config/hack/GoogleService-Info.plist
Expand Up @@ -3,21 +3,21 @@
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>1019264280603-ess3r5dam39hur3aehgd3ob6hl6pjuf1.apps.googleusercontent.com</string>
<string>782697208208-kkm2vf12l0js9ltphusvlr79c2cmoe6v.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.1019264280603-ess3r5dam39hur3aehgd3ob6hl6pjuf1</string>
<string>com.googleusercontent.apps.782697208208-kkm2vf12l0js9ltphusvlr79c2cmoe6v</string>
<key>API_KEY</key>
<string>AIzaSyATWv6UdIffm2lQyXvpog_HIESeaMOILjs</string>
<string>AIzaSyASZVUTMDzfxud-RdicFbH2nPsMlTL-JvI</string>
<key>GCM_SENDER_ID</key>
<string>1019264280603</string>
<string>782697208208</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>int.who.WHOMyHealth</string>
<key>PROJECT_ID</key>
<string>who-mh-hack</string>
<string>who-mh2-dev1</string>
<key>STORAGE_BUCKET</key>
<string>who-mh-hack.appspot.com</string>
<string>who-mh2-dev1.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
Expand All @@ -29,8 +29,6 @@
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:1019264280603:ios:f670199389d1884268b0be</string>
<key>DATABASE_URL</key>
<string>https://who-mh-hack.firebaseio.com</string>
<string>1:782697208208:ios:74fff45695d1a3c2117b15</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion client/lib/api/content/content_loading.dart
Expand Up @@ -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.
Expand Down
31 changes: 18 additions & 13 deletions client/lib/api/endpoints.dart
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions client/lib/api/who_service.dart
Expand Up @@ -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(),
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions client/lib/main.dart
Expand Up @@ -168,9 +168,8 @@ class _MyAppState extends State<MyApp> 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);
Expand Down

0 comments on commit 47c3334

Please sign in to comment.