Skip to content

Commit

Permalink
Add design section.
Browse files Browse the repository at this point in the history
  • Loading branch information
solid-dimakoniaiev authored and mergify-bot committed Mar 3, 2021
1 parent b66bbf4 commit 9a5d618
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 3 deletions.
45 changes: 42 additions & 3 deletions metrics/cli/docs/04_managing_firestore_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ The `dartbase_admin` package requires the following parameters:

2. The JSON of the service account's key, which can be downloaded using the following command:

```bash
gcloud iam service-accounts keys create key.json --iam-account [email protected]
```
```bash
gcloud iam service-accounts keys create key.json --iam-account [email protected]
```

_**Note**: The above-described key is a `private key` for the chosen service account, which requires additional secure factors when working with it.
Therefore, to make sure the user does not need to worry about managing created `private key`, the CLI tool should deactivate the `key` after finishing work with it using the following command:_

```bash
gcloud iam service-accounts keys delete KEY-ID [email protected]
```


Example of creating document using dart package:

Expand Down Expand Up @@ -112,3 +120,34 @@ Cons:
### Decision
As we've analyzed above, the [Cloud Functions](#using-cloud-functions-for-firebase) does not allow us to automate the Cloud Firestore data managing, so we should choose the [Dart Package](#using-dart-package) since it provides a more clean and fully automated way of managing Cloud Firestore data.

## Design

The following sections provide an implementation of managing Firestore data integration into the Metrics CLI tool.

Let's take a look on the main classes the managing firestore data integration requires.
### FirestoreConfigRepository
The `FirestoreConfigRepository` is a repository, which provides methods for managing the [feature config](https://github.com/platform-platform/monorepo/blob/master/docs/19_security_audit_document.md#the-feature_config-collection)
and [allowed domains](https://github.com/platform-platform/monorepo/blob/master/docs/19_security_audit_document.md#the-allowed_email_domains-collection) collections data. For this, purposes the repository using the [dartbase_admin package](https://pub.dev/packages/dartbase_admin) as described in the [decision](#decision).
### FirebaseService
The `FirebaseService` is an existing service interface, in which we should add the following methods required for this integration:
- `seedFirestoreData` - seeds Firestore database with required data;
- `initAdminFirestore` - initializes Firestore database with Admin privileges.
### GcloudService
The `GcloudService` is an existing service interface, in which we should add the following methods required for this integration:
- `downloadServiceKey` - downloads a service account's key;
- `deactivateServiceKey` - deactivates a service account's key.
### FirebaseServiceAdapter
The `FirebaseServiceAdapter` is an adapter for the [`FirebaseService`](#FirebaseService), which implements new added features using the [`FirestoreConfigRepository`](#FirestoreConfigRepository) and the [dartbase_admin package](https://pub.dev/packages/dartbase_admin).
Here is a class diagram, which demonstrates the structure and relationships of classes the Managing Firestore data integration requires:
![Managing Firestore Data class diagram](http://www.plantuml.com/plantuml/proxy?cache=no&fmt=svg&src=https://github.com/platform-platform/monorepo/raw/design_doc_firestore_data/metrics/cli/docs/diagrams/managing_firestore_data_class_diagram.puml)
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@startuml firestore_managing_data_class_diagram

package firebase {
package service as firebase.service {
interface FirebaseService {
+ login(): Future<String>
+ addProject(String gcloudProjectId): Future<void>
+ initAdminFirestore(String projectId, String service) : Future<void>
+ seedFirestoreData() : Future<void>
+ deployHosting(String appPath): Future<void>
+ deployFirestore(String firestorePath): Future<void>
}
}

package adapter as firebase.adapter {
class FirebaseServiceAdapter {
- _firebaseCli: FirebaseCli
- _firestoreConfigRepository: FirestoreConfigRepository
}
}

package cli as firebase.cli {
class FirebaseCli {
}
}

package repository as firebase.repository {
class FirestoreConfigRepository {
- _firestore : Firestore
+ addAllowedDomain(String domain) : Future<void>
+ setFeatureConfig(bool isPasswordSignInOptionEnabled, bool isDebugMenuEnabled): Future<void>
}
}
}

package interfaces {
package service {
interface InfoService {
+ version() : Future<void>
}
}
}

package core {
package data.model {
class FeatureConfigData {
+ Map<String, dynamic> toJson()
+ factory fromJson(Map<String, dynamic> json)
}
}

package domain.entities {
class FeatureConfig {
+ isPasswordSignInOptionEnabled : bool
+ isDebugMenuEnabled : bool
}
}
}

package dartbase_admin {
}

FirebaseService --|> InfoService
FeatureConfigData --|> FeatureConfig

FirebaseServiceAdapter ..|> FirebaseService
FirebaseServiceAdapter --> FirebaseCli : uses
FirebaseServiceAdapter --> FirestoreConfigRepository : uses
FirebaseServiceAdapter -up-> dartbase_admin : uses

FirestoreConfigRepository -up-> dartbase_admin : uses
FirestoreConfigRepository --> FeatureConfigData : uses

@enduml

0 comments on commit 9a5d618

Please sign in to comment.