Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose static methods to get the default project ID and credentials #1241

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public B clock(Clock clock) {
}

/**
* Sets project id.
* Sets project ID.
*
* @return the builder
*/
Expand Down Expand Up @@ -235,7 +235,18 @@ protected boolean projectIdRequired() {
return true;
}

private static AuthCredentials defaultAuthCredentials() {
/**
* Returns the default authentication credentials, or {@code null} if no default credentials could
* be found. This method returns the first available credentials among the following sources:
* <ol>
* <li>App Engine credentials
* <li>JSON credentials pointed to by the {@code GOOGLE_APPLICATION_CREDENTIALS} environment

This comment was marked as spam.

* variable
* <li>Google Cloud SDK credentials
* <li>Compute Engine credentials
* </ol>
*/
public static AuthCredentials defaultAuthCredentials() {
// Consider App Engine.
if (appEngineAppId() != null) {
try {
Expand All @@ -261,6 +272,21 @@ protected String defaultHost() {
}

protected String defaultProject() {
return defaultProjectId();
}

/**
* Returns the default project ID, or {@code null} if no default project ID could be found. This
* method returns the first available project ID among the following sources:
* <ol>
* <li>App Engine project ID

This comment was marked as spam.

* <li>Project ID specified in the JSON credentials file pointed by the
* {@code GOOGLE_APPLICATION_CREDENTIALS} environment variable
* <li>Google Cloud SDK project ID
* <li>Compute Engine project ID
* </ol>
*/
public static String defaultProjectId() {
String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME));
if (projectId == null) {
projectId =
Expand Down Expand Up @@ -402,8 +428,8 @@ public ServiceRpcT rpc() {
}

/**
* Returns the project id. Return value can be null (for services that don't require a project
* id).
* Returns the project ID. Return value can be null (for services that don't require a project
* ID).
*/
public String projectId() {
return projectId;
Expand Down