Skip to content

Commit

Permalink
Merge branch 'main' into feature/emulator_args
Browse files Browse the repository at this point in the history
  • Loading branch information
rrousselGit authored Jul 9, 2024
2 parents 46749f3 + 336de14 commit fbe67f2
Show file tree
Hide file tree
Showing 40 changed files with 338 additions and 5,230 deletions.
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Bug report
about: There is a problem in how provider behaves
title: ""
labels: bug, needs triage
assignees:
- rrousselGit
---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**

<Please add a small sample to that can be executed to reproduce the problem. As a general rule, 100 lines is the maximum>

**Expected behavior**
A clear and concise description of what you expected to happen.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: I have a problem and I need help
url: https://github.com/rrousselGit/riverpod/discussions
about: Please ask and answer questions here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/example_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Documentation improvement request
about: >-
Suggest a new example/documentation or ask for clarification about an
existing one.
title: ""
labels: documentation, needs triage
assignees:
- rrousselGit
---

**Describe what scenario you think is uncovered by the existing examples/articles**
A clear and concise description of the problem that you want explained.

**Describe why existing examples/articles do not cover this case**
Explain which examples/articles you have seen before making this request, and
why they did not help you with your problem.

**Additional context**
Add any other context or screenshots about the documentation request here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ""
labels: enhancement, needs triage
assignees:
- rrousselGit
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
34 changes: 34 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Related Issues

fixes #your-issue-number

<!--
Update to link the issue that is going to be fixed by this.
Unless this concerns documentation, make sure to create an issue first
before raising a PR.
You do not need to describe what this PR is doing, as this should
already be covered by the associated issue.
If the linked issue isn't enough, then chances are a new issue
is needed.
Don't hesitate to create many issues! This can avoid working
on something, only to have your PR closed or have to be rewritten
due to a disagreement/misunderstanding.
-->

## Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (`[x]`).

- [ ] I have updated the `CHANGELOG.md` of the relevant packages.
Changelog files must be edited under the form:

```md
## Unreleased fix/major/minor

- Description of your change. (thanks to @yourGithubId)
```

- [ ] If this contains new features or behavior changes,
I have updated the documentation to match those changes.
7 changes: 7 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
enable-beta-ecosystems: true
updates:
- package-ecosystem: "pub"
directory: "/"
schedule:
interval: "weekly"
50 changes: 50 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build

on:
pull_request:
paths-ignore:
- "**.md"
- "**.mdx"

schedule:
# runs the CI everyday at 10AM
- cron: "0 10 * * *"

jobs:
build:
runs-on: ubuntu-latest

defaults:
run:
working-directory: packages/dart_firebase_admin

steps:
- uses: actions/[email protected]
with:
fetch-depth: 2
- uses: actions/setup-node@v4
- uses: subosito/[email protected]
with:
channel: master
- name: Add pub cache bin to PATH
run: echo "$HOME/.pub-cache/bin" >> $GITHUB_PATH
- name: Add pub cache to PATH
run: echo "PUB_CACHE="$HOME/.pub-cache"" >> $GITHUB_ENV

- name: Install firebase CLI
run: npm install -g firebase-tools

- name: Install dependencies
run: dart pub get && cd example && dart pub get && cd -

- name: Check format
run: dart format --set-exit-if-changed .

- name: Analyze
run: dart analyze

- name: Run tests
run: ${{github.workspace}}/scripts/coverage.sh

- name: Upload coverage to codecov
run: curl -s https://codecov.io/bash | bash
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
firebase-debug.log
ui-debug.log
firestore-debug.log

build
coverage

Expand Down
4 changes: 4 additions & 0 deletions packages/dart_firebase_admin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased fix

- Fixes crash when updating users (thanks to @HeySreelal)

## 0.3.1

- **FEAT**: Use GOOGLE_APPLICATION_CREDENTIALS if json value (#32).
Expand Down
3 changes: 1 addition & 2 deletions packages/dart_firebase_admin/lib/messaging.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export 'src/messaging.dart'
hide FirebaseMessagingRequestHandler, MessagingTopicManagementResponse;
export 'src/messaging.dart' hide FirebaseMessagingRequestHandler;
1 change: 1 addition & 0 deletions packages/dart_firebase_admin/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:io';
import 'package:firebaseapis/identitytoolkit/v3.dart' as auth3;
import 'package:googleapis_auth/auth_io.dart' as auth;
import 'package:googleapis_auth/googleapis_auth.dart';
import 'package:http/http.dart';
import 'package:meta/meta.dart';

part 'app/credential.dart';
Expand Down
57 changes: 40 additions & 17 deletions packages/dart_firebase_admin/lib/src/app/credential.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,46 @@ part of '../app.dart';
@internal
const envSymbol = #_envSymbol;

class _RequestImpl extends BaseRequest {
_RequestImpl(super.method, super.url, [Stream<List<int>>? stream])
: _stream = stream ?? const Stream.empty();

final Stream<List<int>> _stream;

@override
ByteStream finalize() {
super.finalize();
return ByteStream(_stream);
}
}

/// Will close the underlying `http.Client` depending on a constructor argument.
class _EmulatorClient extends BaseClient {
_EmulatorClient(this.client);

final Client client;

@override
Future<StreamedResponse> send(BaseRequest request) async {
// Make new request object and perform the authenticated request.
final modifiedRequest = _RequestImpl(
request.method,
request.url,
request.finalize(),
);
modifiedRequest.headers.addAll(request.headers);
modifiedRequest.headers['Authorization'] = 'Bearer owner';

return client.send(modifiedRequest);
}

@override
void close() {
client.close();
super.close();
}
}

/// Authentication information for Firebase Admin SDK.
class Credential {
Credential._(
Expand Down Expand Up @@ -72,21 +112,4 @@ class Credential {

@internal
final auth.ServiceAccountCredentials? serviceAccountCredentials;

@internal
late final client = _getClient(
[
auth3.IdentityToolkitApi.cloudPlatformScope,
auth3.IdentityToolkitApi.firebaseScope,
],
);

Future<AutoRefreshingAuthClient> _getClient(List<String> scopes) async {
final serviceAccountCredentials = this.serviceAccountCredentials;
final client = serviceAccountCredentials == null
? await auth.clientViaApplicationDefaultCredentials(scopes: scopes)
: await auth.clientViaServiceAccount(serviceAccountCredentials, scopes);

return client;
}
}
2 changes: 1 addition & 1 deletion packages/dart_firebase_admin/lib/src/app/exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ String _platformErrorCodeMessage(String code) {
}

/// Base interface for all Firebase Admin related errors.
abstract class FirebaseAdminException {
abstract class FirebaseAdminException implements Exception {
FirebaseAdminException(this.service, this._code, [this._message]);

final String service;
Expand Down
23 changes: 22 additions & 1 deletion packages/dart_firebase_admin/lib/src/app/firebase_admin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,30 @@ class FirebaseAdminApp {
firestoreApiHost = Uri.http('${emulator.host}:${emulator.port}', '/');
}

@internal
late final client = _getClient(
[
auth3.IdentityToolkitApi.cloudPlatformScope,
auth3.IdentityToolkitApi.firebaseScope,
],
);

Future<Client> _getClient(List<String> scopes) async {
if (isUsingEmulator) {
return _EmulatorClient(Client());
}

final serviceAccountCredentials = credential.serviceAccountCredentials;
final client = serviceAccountCredentials == null
? await auth.clientViaApplicationDefaultCredentials(scopes: scopes)
: await auth.clientViaServiceAccount(serviceAccountCredentials, scopes);

return client;
}

/// Stops the app and releases any resources associated with it.
Future<void> close() async {
final client = await credential.client;
final client = await this.client;
client.close();
}
}
2 changes: 1 addition & 1 deletion packages/dart_firebase_admin/lib/src/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:firebaseapis/identitytoolkit/v1.dart' as v1;
import 'package:firebaseapis/identitytoolkit/v2.dart' as auth2;
import 'package:firebaseapis/identitytoolkit/v2.dart' as v2;
import 'package:firebaseapis/identitytoolkit/v3.dart' as auth3;
import 'package:googleapis_auth/googleapis_auth.dart';
import 'package:http/http.dart';
import 'package:meta/meta.dart';

import 'app.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,8 @@ abstract class _AbstractAuthRequestHandler {
phoneNumber: properties.phoneNumber?.value,
// Will be null if deleted or set to null. "deleteAttribute" will take over
photoUrl: properties.photoURL?.value,
// The UID of the user to be updated.
localId: uid,
);

final response = await _httpClient.setAccountInfo(request);
Expand All @@ -750,7 +752,6 @@ class _AuthHttpClient {
_AuthHttpClient(this.app);

// TODO handle tenants
// TODO needs to send "owner" as bearer token when using the emulator
final FirebaseAdminApp app;

String _buildParent() => 'projects/${app.projectId}';
Expand Down Expand Up @@ -1012,9 +1013,9 @@ class _AuthHttpClient {
}

Future<R> _run<R>(
Future<R> Function(AutoRefreshingAuthClient client) fn,
Future<R> Function(Client client) fn,
) {
return _authGuard(() => app.credential.client.then(fn));
return _authGuard(() => app.client.then(fn));
}

Future<R> v1<R>(
Expand Down
Loading

0 comments on commit fbe67f2

Please sign in to comment.