Skip to content

Commit

Permalink
Merge branch 'dev' into feat/projects
Browse files Browse the repository at this point in the history
  • Loading branch information
mcosta74 authored Feb 19, 2025
2 parents 35bc100 + 0a3a5b5 commit 3134a42
Show file tree
Hide file tree
Showing 24 changed files with 272 additions and 2,693 deletions.
Binary file modified .github/resources/integ-service-account.json.gpg
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ['1.20', '1.21', '1.22']
go: ['1.21', '1.22', '1.23']

steps:
- name: Check out code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '1.21'

- name: Install golint
run: go install golang.org/x/lint/golint@latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '1.21'

- name: Install golint
run: go install golang.org/x/lint/golint@latest
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ requests, code review feedback, and also pull requests.
## Supported Go Versions

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

## Documentation

Expand Down
1 change: 1 addition & 0 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func NewClient(ctx context.Context, conf *internal.AuthConfig) (*Client, error)
hc.CreateErrFn = handleHTTPError
hc.Opts = []internal.HTTPOption{
internal.WithHeader("X-Client-Version", fmt.Sprintf("Go/Admin/%s", conf.Version)),
internal.WithHeader("x-goog-api-client", internal.GetMetricsHeader(conf.Version)),
}

baseURL := defaultAuthURL
Expand Down
5 changes: 5 additions & 0 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,11 @@ func checkBaseClient(client *Client, wantProjectID string) error {
return fmt.Errorf("version = %q; want = %q", version, wantVersion)
}

xGoogAPIClientHeader := internal.GetMetricsHeader(testVersion)
if h := req.Header.Get("x-goog-api-client"); h != xGoogAPIClientHeader {
return fmt.Errorf("x-goog-api-client header = %q; want = %q", h, xGoogAPIClientHeader)
}

return nil
}

Expand Down
3 changes: 3 additions & 0 deletions auth/token_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ func newIAMSigner(ctx context.Context, config *internal.AuthConfig) (*iamSigner,
if err != nil {
return nil, err
}
hc.Opts = []internal.HTTPOption{
internal.WithHeader("x-goog-api-client", internal.GetMetricsHeader(config.Version)),
}

return &iamSigner{
mutex: &sync.Mutex{},
Expand Down
13 changes: 11 additions & 2 deletions auth/token_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func TestIAMSigner(t *testing.T) {
conf := &internal.AuthConfig{
Opts: optsWithTokenSource,
ServiceAccountID: "test-service-account",
Version: testVersion,
}
signer, err := newIAMSigner(ctx, conf)
if err != nil {
Expand Down Expand Up @@ -155,6 +156,7 @@ func TestIAMSignerHTTPError(t *testing.T) {
conf := &internal.AuthConfig{
Opts: optsWithTokenSource,
ServiceAccountID: "test-service-account",
Version: testVersion,
}
signer, err := newIAMSigner(context.Background(), conf)
if err != nil {
Expand Down Expand Up @@ -182,6 +184,7 @@ func TestIAMSignerUnknownHTTPError(t *testing.T) {
conf := &internal.AuthConfig{
Opts: optsWithTokenSource,
ServiceAccountID: "test-service-account",
Version: testVersion,
}
signer, err := newIAMSigner(context.Background(), conf)
if err != nil {
Expand All @@ -208,7 +211,8 @@ func TestIAMSignerUnknownHTTPError(t *testing.T) {
func TestIAMSignerWithMetadataService(t *testing.T) {
ctx := context.Background()
conf := &internal.AuthConfig{
Opts: optsWithTokenSource,
Opts: optsWithTokenSource,
Version: testVersion,
}

signer, err := newIAMSigner(ctx, conf)
Expand Down Expand Up @@ -253,7 +257,8 @@ func TestIAMSignerWithMetadataService(t *testing.T) {
func TestIAMSignerNoMetadataService(t *testing.T) {
ctx := context.Background()
conf := &internal.AuthConfig{
Opts: optsWithTokenSource,
Opts: optsWithTokenSource,
Version: testVersion,
}

signer, err := newIAMSigner(ctx, conf)
Expand Down Expand Up @@ -340,6 +345,10 @@ func iamServer(t *testing.T, serviceAcct, signature string) *httptest.Server {
if r.URL.Path != wantPath {
t.Errorf("Path = %q; want = %q", r.URL.Path, wantPath)
}
xGoogAPIClientHeader := internal.GetMetricsHeader(testVersion)
if h := r.Header.Get("x-goog-api-client"); h != xGoogAPIClientHeader {
t.Errorf("x-goog-api-client header = %q; want = %q", h, xGoogAPIClientHeader)
}

w.Header().Set("Content-Type", "application/json")
b, err := json.Marshal(resp)
Expand Down
14 changes: 6 additions & 8 deletions auth/token_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,7 @@ func (k *httpKeySource) refreshKeys(ctx context.Context) error {
return err
}

maxAge, err := findMaxAge(resp)
if err != nil {
return err
}
maxAge := findMaxAge(resp)

k.CachedKeys = append([]*publicKey(nil), newKeys...)
k.ExpiryTime = k.Clock.Now().Add(*maxAge)
Expand Down Expand Up @@ -476,19 +473,20 @@ func parsePublicKey(kid string, key []byte) (*publicKey, error) {
return &publicKey{kid, pk}, nil
}

func findMaxAge(resp *http.Response) (*time.Duration, error) {
func findMaxAge(resp *http.Response) *time.Duration {
cc := resp.Header.Get("cache-control")
for _, value := range strings.Split(cc, ",") {
value = strings.TrimSpace(value)
if strings.HasPrefix(value, "max-age=") {
sep := strings.Index(value, "=")
seconds, err := strconv.ParseInt(value[sep+1:], 10, 64)
if err != nil {
return nil, err
seconds = 0
}
duration := time.Duration(seconds) * time.Second
return &duration, nil
return &duration
}
}
return nil, errors.New("Could not find expiry time from HTTP headers")
defaultDuration := time.Duration(0) * time.Second
return &defaultDuration
}
31 changes: 9 additions & 22 deletions auth/token_verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,38 +140,25 @@ func TestFindMaxAge(t *testing.T) {
{"max-age=100", 100},
{"public, max-age=100", 100},
{"public,max-age=100", 100},
{"public, max-age=100, must-revalidate, no-transform", 100},
{"", 0},
{"max-age 100", 0},
{"max-age: 100", 0},
{"max-age2=100", 0},
{"max-age=foo", 0},
{"private,", 0},
}
for _, tc := range cases {
resp := &http.Response{
Header: http.Header{"Cache-Control": {tc.cc}},
}
age, err := findMaxAge(resp)
if err != nil {
t.Errorf("findMaxAge(%q) = %v", tc.cc, err)
} else if *age != (time.Duration(tc.want) * time.Second) {
age := findMaxAge(resp)
if *age != (time.Duration(tc.want) * time.Second) {
t.Errorf("findMaxAge(%q) = %v; want = %v", tc.cc, *age, tc.want)
}
}
}

func TestFindMaxAgeError(t *testing.T) {
cases := []string{
"",
"max-age 100",
"max-age: 100",
"max-age2=100",
"max-age=foo",
}
for _, tc := range cases {
resp := &http.Response{
Header: http.Header{"Cache-Control": []string{tc}},
}
if age, err := findMaxAge(resp); age != nil || err == nil {
t.Errorf("findMaxAge(%q) = (%v, %v); want = (nil, err)", tc, age, err)
}
}
}

func TestParsePublicKeys(t *testing.T) {
b, err := ioutil.ReadFile("../testdata/public_certs.json")
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions auth/user_mgt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2315,6 +2315,12 @@ func echoServer(resp interface{}, t *testing.T) *mockAuthServer {
t.Errorf("X-Client-Version header = %q; want: %q", gh, wh)
}

gh = r.Header.Get("x-goog-api-client")
wh = internal.GetMetricsHeader(testVersion)
if gh != wh {
t.Errorf("x-goog-api-client header = %q; want: %q", gh, wh)
}

for k, v := range s.Header {
w.Header().Set(k, v)
}
Expand Down
3 changes: 2 additions & 1 deletion firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
var defaultAuthOverrides = make(map[string]interface{})

// Version of the Firebase Go Admin SDK.
const Version = "4.14.0"
const Version = "4.15.2"

// firebaseEnvName is the name of the environment variable with the Config.
const firebaseEnvName = "FIREBASE_CONFIG"
Expand Down Expand Up @@ -116,6 +116,7 @@ func (a *App) InstanceID(ctx context.Context) (*iid.Client, error) {
conf := &internal.InstanceIDConfig{
ProjectID: a.projectID,
Opts: a.opts,
Version: Version,
}
return iid.NewClient(ctx, conf)
}
Expand Down
82 changes: 47 additions & 35 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,49 +1,61 @@
module firebase.google.com/go/v4

go 1.20
go 1.21

require (
cloud.google.com/go/firestore v1.15.0
cloud.google.com/go/storage v1.40.0
cloud.google.com/go/firestore v1.18.0
cloud.google.com/go/storage v1.49.0
github.com/MicahParks/keyfunc v1.9.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang-jwt/jwt/v4 v4.5.1
github.com/google/go-cmp v0.6.0
golang.org/x/oauth2 v0.18.0
google.golang.org/api v0.170.0
google.golang.org/appengine/v2 v2.0.2
golang.org/x/oauth2 v0.25.0
google.golang.org/api v0.215.0
google.golang.org/appengine/v2 v2.0.6
)

require (
cloud.google.com/go v0.112.1 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.7 // indirect
cloud.google.com/go/longrunning v0.5.5 // indirect
cel.dev/expr v0.16.1 // indirect
cloud.google.com/go v0.117.0 // indirect
cloud.google.com/go/auth v0.13.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
cloud.google.com/go/compute/metadata v0.6.0 // indirect
cloud.google.com/go/iam v1.2.2 // indirect
cloud.google.com/go/longrunning v0.6.2 // indirect
cloud.google.com/go/monitoring v1.21.2 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.25.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.48.1 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.1 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect
github.com/envoyproxy/go-control-plane v0.13.1 // indirect
github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240311132316-a219d84964c2 // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.29.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.8.0 // indirect
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241223144023-3abc09e42ca8 // indirect
google.golang.org/grpc v1.67.3 // indirect
google.golang.org/protobuf v1.36.1 // indirect
)
Loading

0 comments on commit 3134a42

Please sign in to comment.