Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
java-version: [7, 8, 11]

steps:
- uses: actions/checkout@v1

- name: Set up JDK 1.7
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 1.7
java-version: ${{ matrix.java-version }}

# Does the following:
# 1. Runs the Checkstyle plugin (validate phase)
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
with:
ref: ${{ github.event.client_payload.ref || github.ref }}

- name: Set up JDK 1.7
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.7
java-version: 1.8

- name: Compile, test and package
run: ./.github/scripts/package_artifacts.sh
Expand All @@ -63,7 +63,7 @@ jobs:
subject: 'Nightly build ${{github.run_id}} of ${{github.repository}} failed!'
html: >
<b>Nightly workflow ${{github.run_id}} failed on: ${{github.repository}}</b>
<br /><br />Navigate to the
<br /><br />Navigate to the
<a href="https://github.com/firebase/firebase-admin-java/actions/runs/${{github.run_id}}">failed workflow</a>.
continue-on-error: true

Expand All @@ -78,6 +78,6 @@ jobs:
subject: 'Nightly build ${{github.run_id}} of ${{github.repository}} cancelled!'
html: >
<b>Nightly workflow ${{github.run_id}} cancelled on: ${{github.repository}}</b>
<br /><br />Navigate to the
<br /><br />Navigate to the
<a href="https://github.com/firebase/firebase-admin-java/actions/runs/${{github.run_id}}">cancelled workflow</a>.
continue-on-error: true
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ jobs:
with:
ref: ${{ github.event.client_payload.ref || github.ref }}

- name: Set up JDK 1.7
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.7
java-version: 1.8

- name: Compile, test and package
run: ./.github/scripts/package_artifacts.sh
Expand Down Expand Up @@ -82,10 +82,10 @@ jobs:
- name: Checkout source for publish
uses: actions/checkout@v2

- name: Set up JDK 1.7
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.7
java-version: 1.8

- name: Publish preflight check
id: preflight
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/google/firebase/FirebaseApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.firebase.internal.ApiClientUtils;
import com.google.firebase.internal.FirebaseProcessEnvironment;
import com.google.firebase.internal.FirebaseScheduledExecutor;
import com.google.firebase.internal.FirebaseService;
import com.google.firebase.internal.ListenableFuture2ApiFuture;
Expand Down Expand Up @@ -292,10 +293,10 @@ String getProjectId() {

// Try to get project ID from the environment.
if (Strings.isNullOrEmpty(projectId)) {
projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
projectId = FirebaseProcessEnvironment.getenv("GOOGLE_CLOUD_PROJECT");
}
if (Strings.isNullOrEmpty(projectId)) {
projectId = System.getenv("GCLOUD_PROJECT");
projectId = FirebaseProcessEnvironment.getenv("GCLOUD_PROJECT");
}
return projectId;
}
Expand Down Expand Up @@ -563,7 +564,7 @@ enum State {
}

private static FirebaseOptions getOptionsFromEnvironment() throws IOException {
String defaultConfig = System.getenv(FIREBASE_CONFIG_ENV_VAR);
String defaultConfig = FirebaseProcessEnvironment.getenv(FIREBASE_CONFIG_ENV_VAR);
if (Strings.isNullOrEmpty(defaultConfig)) {
return FirebaseOptions.builder()
.setCredentials(APPLICATION_DEFAULT_CREDENTIALS)
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/google/firebase/FirebaseOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.firebase.internal.ApiClientUtils;
import com.google.firebase.internal.ApplicationDefaultCredentialsProvider;
import com.google.firebase.internal.FirebaseThreadManagers;
import com.google.firebase.internal.NonNull;
import com.google.firebase.internal.Nullable;
Expand Down Expand Up @@ -64,7 +65,8 @@ public final class FirebaseOptions {
@Override
public GoogleCredentials get() {
try {
return GoogleCredentials.getApplicationDefault().createScoped(FIREBASE_SCOPES);
return ApplicationDefaultCredentialsProvider.getApplicationDefault()
.createScoped(FIREBASE_SCOPES);
} catch (IOException e) {
throw new IllegalStateException(e);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/google/firebase/auth/internal/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.firebase.internal.FirebaseProcessEnvironment;

public class Utils {
@VisibleForTesting
Expand All @@ -28,7 +29,7 @@ public static boolean isEmulatorMode() {
}

public static String getEmulatorHost() {
return System.getenv(AUTH_EMULATOR_HOST);
return FirebaseProcessEnvironment.getenv(AUTH_EMULATOR_HOST);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.firebase.database.core.RepoInfo;
import com.google.firebase.database.utilities.ParsedUrl;
import com.google.firebase.database.utilities.Utilities;
import com.google.firebase.internal.FirebaseProcessEnvironment;

public final class EmulatorHelper {

Expand All @@ -33,7 +34,7 @@ private EmulatorHelper() {
"FIREBASE_DATABASE_EMULATOR_HOST";

public static String getEmulatorHostFromEnv() {
return System.getenv(FIREBASE_RTDB_EMULATOR_HOST_ENV_VAR);
return FirebaseProcessEnvironment.getenv(FIREBASE_RTDB_EMULATOR_HOST_ENV_VAR);
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2021 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.firebase.internal;

import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;

/**
* Provides a hook to override application default credentials (ADC) lookup for tests. ADC has
* a dependency on environment variables, and Java famously doesn't support environment variable
* manipulation at runtime. With this class, the test cases that require ADC has a way to register
* their own mock credentials as ADC.
*
* <p>Once we are able to upgrade to Mockito 3.x (requires Java 8+), we can drop this class
* altogether, and use Mockito tools to mock the behavior of the GoogleCredentials static methods.
*/
public class ApplicationDefaultCredentialsProvider {

private static GoogleCredentials cachedCredentials;

public static GoogleCredentials getApplicationDefault() throws IOException {
if (cachedCredentials != null) {
return cachedCredentials;
}

return GoogleCredentials.getApplicationDefault();
}

public static void setApplicationDefault(GoogleCredentials credentials) {
cachedCredentials = credentials;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2021 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.firebase.internal;

import com.google.common.base.Strings;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* A utility for overriding environment variables during tests.
*/
public class FirebaseProcessEnvironment {

private static final Map<String, String> localCache = new ConcurrentHashMap<>();

public static String getenv(String name) {
String cachedValue = localCache.get(name);
if (!Strings.isNullOrEmpty(cachedValue)) {
return cachedValue;
}

return System.getenv(name);
}

public static void setenv(String name, String value) {
localCache.put(name, value);
}

public static void clearCache() {
localCache.clear();
}
}
Loading