Skip to content

Commit c746ccb

Browse files
authored
Merge branch 'dev' into feature/app-check-consume-endpoint
2 parents 604af8d + da7068d commit c746ccb

File tree

88 files changed

+3666
-398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3666
-398
lines changed

.github/scripts/generate_changelog.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Copyright 2020 Google Inc.
3+
# Copyright 2020 Google LLC
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.

.github/scripts/publish_preflight_check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Copyright 2020 Google Inc.
3+
# Copyright 2020 Google LLC
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.

.github/scripts/run_all_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Copyright 2020 Google Inc.
3+
# Copyright 2020 Google LLC
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
go: ['1.20', '1.21', '1.22']
11+
go: ['1.23', '1.24']
1212

1313
steps:
1414
- name: Check out code

.github/workflows/nightly.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021 Google Inc.
1+
# Copyright 2021 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ jobs:
3636
- name: Set up Go
3737
uses: actions/setup-go@v5
3838
with:
39-
go-version: '1.20'
39+
go-version: '1.23'
4040

4141
- name: Install golint
4242
run: go install golang.org/x/lint/golint@latest

.github/workflows/release.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020 Google Inc.
1+
# Copyright 2020 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ jobs:
4747
- name: Set up Go
4848
uses: actions/setup-go@v5
4949
with:
50-
go-version: '1.20'
50+
go-version: '1.23'
5151

5252
- name: Install golint
5353
run: go install golang.org/x/lint/golint@latest
@@ -76,6 +76,8 @@ jobs:
7676
startsWith(github.event.pull_request.title, '[chore] Release ')
7777

7878
runs-on: ubuntu-latest
79+
permissions:
80+
contents: write
7981

8082
steps:
8183
- name: Checkout source for publish

AGENTS.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Firebase Admin Go SDK - Agent Guide
2+
3+
This document provides a comprehensive guide for AI agents to understand the conventions, design patterns, and architecture of the Firebase Admin Go SDK. Adhering to these guidelines is crucial for making idiomatic and consistent code contributions.
4+
5+
## 1. High-Level Overview
6+
7+
The Firebase Admin Go SDK enables server-side (backend) applications to interact with Firebase services. Its design emphasizes idiomatic Go, thread-safety, and a consistent, discoverable API surface.
8+
9+
## 2. Directory Structure
10+
11+
- `firebase.go`: The primary entry point for initializing a Firebase `App` instance.
12+
- `internal/`: Contains private implementation details, such as HTTP clients and utility functions, that are not part of the public API.
13+
- `auth/`, `db/`, `messaging/`, etc.: Each directory contains a specific Firebase service client.
14+
- `*_test.go`: Unit tests are located alongside the code they test (e.g., `auth/auth_test.go`).
15+
- `integration/`: Contains integration tests that make live network calls to Firebase services.
16+
- `snippets/`: Contains code snippets used in documentation.
17+
- `errorutils/`: Contains common error type checkers and other error handling utils.
18+
- `testdata/`: Contains mock data used in some tests.
19+
20+
## 3. Core Design Patterns
21+
22+
- **Initialization:** The SDK is initialized by creating an `App` instance via `firebase.NewApp()`. This `App` object is the central point for accessing all service clients.
23+
- **Service Clients:** Service clients (e.g., `auth.Client`, `db.Client`) are obtained from the `App` instance (e.g., `app.Auth(ctx)`). These clients are lightweight and are typically created as needed.
24+
- **Error Handling:** Errors are handled using standard Go idioms. Firbase errors are defined in `internal/errors.go` however these errors can be further modified within each service. This modification is applied using that service's set `internal.HTTPClient.CreateErrFn` value.
25+
- **HTTP Communication:** All outgoing HTTP requests are managed by a centralized client located in `internal/http_client.go`. This ensures consistent handling of authentication, retries, and error parsing.
26+
- **Asynchronous Operations:** The SDK uses `context.Context` to manage deadlines, cancellations, and request-scoped values for all asynchronous operations.
27+
28+
## 4. Coding Style and Naming Conventions
29+
30+
- **Naming:**
31+
- Public functions, types, and fields use `PascalCase`.
32+
- Private functions and types use `camelCase`.
33+
- Constants are written in `PascalCase`.
34+
35+
## 5. Testing Philosophy
36+
37+
- **Unit Tests:** Unit tests follow the `*_test.go` naming pattern and are placed in the same directory as the code under test. They use standard Go testing packages and mocks to isolate dependencies.
38+
- **Integration Tests:** Integration tests are located in the `integration/` directory. They are designed to run against actual Firebase services and require a configured Firebase project.
39+
40+
## 6. Dependency Management
41+
42+
- **Manager:** The SDK uses Go Modules for dependency management.
43+
- **Manifest:** Dependencies are declared in the `go.mod` file.
44+
- **Command:** To add or update dependencies, use `go get` or `go mod tidy`.
45+
46+
## 7. Critical Developer Journeys
47+
48+
### Journey 1: How to Add a New API Method
49+
50+
1. **Define Public Method:** Add the new method or change to the appropriate service client files (e.g., `auth/user_mgt.go`).
51+
2. **Internal Logic:** Implement the core logic within the service package.
52+
3. **HTTP Client:** Use the client in `internal/http_client.go` to make the API calls.
53+
4. **Error Handling:** New or updated error codes implemented in the appropriate location.
54+
5. **Testing:**
55+
- Add unit tests in the corresponding `*_test.go` file (e.g., `auth/user_mgt_test.go`).
56+
- Add integration tests in the `integration/` directory if applicable.
57+
6. **Snippets:** (Optional) Add or update code snippets in the `snippets/` directory.
58+
59+
### Journey 2: How to Deprecate a Field/Method in an Existing API
60+
61+
1. **Add Deprecation Note:** Locate where the deprecated object is defined and add a deprecation warning with a note (e.g. `// Deprecated: Use X instead.`).
62+
63+
## 8. Critical Do's and Don'ts
64+
65+
- **DO:** Use the centralized HTTP client in `internal/http_client.go` for all network calls.
66+
- **DO:** Pass `context.Context` as the first argument to all functions that perform I/O or other blocking operations.
67+
- **DON'T:** Expose types or functions from the `internal/` directory in the public API.
68+
- **DON'T:** Introduce new third-party dependencies without a strong, documented justification and team consensus.
69+
70+
## 9. Branch Creation
71+
- When creating a new barnch use the format `agentName-short-description`.
72+
* Example: `jules-auth-token-parsing`
73+
* Example: `gemini-add-storage-file-signer`
74+
75+
76+
## 10. Commit and Pull Request Generation
77+
78+
After implementing and testing a change, you may create a commit and pull request which must follow the following these rules:
79+
80+
### Commit and Pull Request Title Format:
81+
Use the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification: `type(scope): subject`
82+
- `type` should be one of `feat`, `fix` or `chore`.
83+
- `scope` should be the service package changed (e.g., `auth`, `rtdb`, `deps`).
84+
- **Note**: Some services use specific abbreviations. Use the abbreviation if one exists. Common abbreviations include:
85+
- `messaging` -> `fcm`
86+
- `dataconnect` -> `fdc`
87+
- `database` -> `rtdb`
88+
- `appcheck` -> `fac`
89+
- `subject` should be a brief summary of the change depending on the action:
90+
- For pull requests this should focus on the larger goal the included commits achieve.
91+
- Example: `fix(auth): Resolved issue with custom token verification`
92+
- For commits this should focus on the specific changes made in that commit.
93+
- Example: `fix(auth): Added a new token verification check`
94+
95+
### Commit Body:
96+
This should be a brief explanation of code changes.
97+
98+
Example:
99+
```
100+
feat(fcm): Added `SendEachForMulticast` support for multicast messages
101+
102+
Added a new `SendEachForMulticast` method to the messaging client. This method wraps the `SendEach` method and sends the same message to each token.
103+
```
104+
105+
### Pull Request Body:
106+
- A brief explanation of the problem and the solution.
107+
- A summary of the testing strategy (e.g., "Added a new unit test to verify the fix.").
108+
- A **Context Sources** section that lists the `id` and repository path of every `AGENTS.md` file you used.
109+
110+
Example:
111+
```
112+
feat(fcm): Added support for multicast messages
113+
114+
This change introduces a new `SendEachForMulticast` method to the messaging client, allowing developers to send a single message to multiple tokens efficiently.
115+
116+
Testing: Added unit tests in `messaging_test.go` with a mock server and an integration test in `integration/messaging_test.go`.
117+
118+
Context Sources Used:
119+
- id: firebase-admin-go (`/AGENTS.md`)
120+
```
121+
122+
## 11. Metadata
123+
- id: firebase-admin-go

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ requests, code review feedback, and also pull requests.
4444

4545
## Supported Go Versions
4646

47-
The Admin Go SDK is compatible with at least the three most recent, major Go releases.
48-
We currently support Go v1.20 and higher.
47+
The Admin Go SDK is compatible with the two most-recent major Go releases.
48+
We currently support Go v1.23 and 1.24.
4949
[Continuous integration](https://github.com/firebase/firebase-admin-go/actions) system
50-
tests the code on Go v1.20 through v1.22.
50+
tests the code on Go v1.23 and v1.24.
5151

5252
## Documentation
5353

appcheck/appcheck.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Google Inc. All Rights Reserved.
1+
// Copyright 2022 Google LLC All Rights Reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

auth/auth.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017 Google Inc. All Rights Reserved.
1+
// Copyright 2017 Google LLC All Rights Reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -137,6 +137,7 @@ func NewClient(ctx context.Context, conf *internal.AuthConfig) (*Client, error)
137137
hc.CreateErrFn = handleHTTPError
138138
hc.Opts = []internal.HTTPOption{
139139
internal.WithHeader("X-Client-Version", fmt.Sprintf("Go/Admin/%s", conf.Version)),
140+
internal.WithHeader("x-goog-api-client", internal.GetMetricsHeader(conf.Version)),
140141
}
141142

142143
baseURL := defaultAuthURL

0 commit comments

Comments
 (0)