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

Remove AuthCredentials and related classes, use google-auth-library-java instead #1375

Merged
merged 4 commits into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Authentication

`google-cloud-java` uses
[https://github.com/google/google-auth-library-java](https://github.com/google/google-auth-library-java)
to authenticate requests. `google-auth-library-java` supports a wide range of authentication types,
to authenticate requests. `google-auth-library-java` supports a wide range of authentication types;
see the project's [README](https://github.com/google/google-auth-library-java/blob/master/README.md)
and [javadoc](http://google.github.io/google-auth-library-java/releases/0.6.0/apidocs/) for more
details.
Expand Down Expand Up @@ -152,10 +152,10 @@ Storage storage = StorageOptions.getDefaultInstance().getService();
```
* If running locally for development/testing, you can use the
[Google Cloud SDK](https://cloud.google.com/sdk/). Create Application Default Credentials with
`gcloud auth application-default login`, `google-cloud` will automatically detect such
`gcloud auth application-default login`, and then `google-cloud` will automatically detect such
credentials.
* If you already have an OAuth2 access token, you can use it to authenticate (notice that in this
case the access token will not be automatically refreshed):
case, the access token will not be automatically refreshed):
```java
Storage storage = StorageOptions.newBuilder()
.setCredentials(new GoogleCredentials(new AccessToken(accessToken, expirationTime)))
Expand All @@ -167,7 +167,7 @@ If no credentials are provided, `google-cloud` will attempt to detect them from
using `GoogleCredentials.getApplicationDefault()` which will search for Default Application
Credentials in the following locations (in order):

1. Credentials file pointed to by the `GOOGLE_APPLICATION_CREDENTIALS` environment variable
1. The credentials file pointed to by the `GOOGLE_APPLICATION_CREDENTIALS` environment variable
2. Credentials provided by the Google Cloud SDK `gcloud auth application-default login` command
3. Google App Engine built-in credentials
4. Google Cloud Shell built-in credentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,7 @@ protected Serializable[] serializableObjects() {
.setProjectId("p1")
.setNoCredentials()
.build();
BigQueryOptions otherOptions = options.toBuilder()
.setProjectId("p2")
.setCredentials(null)
.build();
BigQueryOptions otherOptions = options.toBuilder().setProjectId("p2").build();
return new Serializable[]{DOMAIN_ACCESS, GROUP_ACCESS, USER_ACCESS, VIEW_ACCESS, DATASET_ID,
DATASET_INFO, TABLE_ID, CSV_OPTIONS, STREAMING_BUFFER, TABLE_DEFINITION,
EXTERNAL_TABLE_DEFINITION, VIEW_DEFINITION, TABLE_SCHEMA, TABLE_INFO, VIEW_INFO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ protected Serializable[] serializableObjects() {
ComputeOptions otherOptions = options.toBuilder()
.setProjectId("p2")
.setRetryParams(RetryParams.getDefaultInstance())
.setCredentials(null)
.build();
return new Serializable[]{DISK_TYPE_ID, DISK_TYPE, MACHINE_TYPE_ID, MACHINE_TYPE, REGION_ID,
REGION, ZONE_ID, ZONE, LICENSE_ID, LICENSE, DEPRECATION_STATUS, GLOBAL_OPERATION_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.auth.Credentials;
Expand Down Expand Up @@ -213,13 +214,18 @@ public B setHost(String host) {
}

/**
* Sets the service authentication credentials.
* Sets the service authentication credentials. If this method or {@link #setNoCredentials() are
* not used on the builder, {@link GoogleCredentials#getApplicationDefault()} will be used to
* attempt getting credentials from the environment.
*
* @param credentials authentication credentials, should not be {@code null}
* @return the builder
* @throws NullPointerException if {@code credentials} is {@code null}. To disable
* authentication use {@link Builder#setNoCredentials()}

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

*/
public B setCredentials(Credentials credentials) {
this.credentials = checkNotNull(credentials);
this.noCredentials = false;
this.credentials = credentials;
return self();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.spi.ServiceRpcFactory;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -105,6 +107,9 @@ public class ServiceOptionsTest {
private static final Pattern APPLICATION_NAME_PATTERN =
Pattern.compile(LIBRARY_NAME + "(/[0-9]+.[0-9]+.[0-9]+)?");

@Rule
public ExpectedException thrown = ExpectedException.none();

private static class TestClock extends Clock {
@Override
public long millis() {
Expand Down Expand Up @@ -226,6 +231,12 @@ public void testBuilderNoCredentials() {
assertSame(RetryParams.noRetries(), OPTIONS_NO_CREDENTIALS.getRetryParams());
}

@Test
public void testBuilderNullCredentials() {
thrown.expect(NullPointerException.class);
TestServiceOptions.newBuilder().setCredentials(null).build();
}

@Test
public void testBuilderDeprecated() {
assertSame(credentials, DEPRECATED_OPTIONS.getCredentials());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ protected java.io.Serializable[] serializableObjects() {
.setNoCredentials()
.setProjectId("ds1")
.build();
DatastoreOptions otherOptions = options.toBuilder()
.setNamespace("ns1")
.setCredentials(null)
.build();
DatastoreOptions otherOptions = options.toBuilder().setNamespace("ns1").build();
return new java.io.Serializable[]{KEY1, KEY2, INCOMPLETE_KEY1, INCOMPLETE_KEY2, ENTITY1,
ENTITY2, ENTITY3, EMBEDDED_ENTITY, PROJECTION_ENTITY, DATE_TIME1, BLOB1, CURSOR1, GQL1,
GQL2, QUERY1, QUERY2, QUERY3, NULL_VALUE, KEY_VALUE, STRING_VALUE, EMBEDDED_ENTITY_VALUE1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ protected Serializable[] serializableObjects() {
.setNoCredentials()
.setProjectId("id1")
.build();
DnsOptions otherOptions = options.toBuilder()
.setCredentials(null)
.build();
DnsOptions otherOptions = options.toBuilder().build();
return new Serializable[]{FULL_ZONE_INFO, PARTIAL_ZONE_INFO, ZONE_LIST_OPTION,
RECORD_SET_LIST_OPTION, CHANGE_REQUEST_LIST_OPTION, ZONE_OPTION, CHANGE_REQUEST_OPTION,
PROJECT_OPTION, PARTIAL_PROJECT_INFO, FULL_PROJECT_INFO, OPTIONS, FULL_ZONE, PARTIAL_ZONE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ protected Serializable[] serializableObjects() {
.setProjectId("p1")
.setNoCredentials()
.build();
StorageOptions otherOptions = options.toBuilder()
.setProjectId("p2")
.setCredentials(null)
.build();
StorageOptions otherOptions = options.toBuilder().setProjectId("p2").build();
return new Serializable[]{ACL_DOMAIN, ACL_GROUP, ACL_PROJECT_, ACL_USER, ACL_RAW, ACL,
BLOB_INFO, BLOB, BUCKET_INFO, BUCKET, ORIGIN, CORS, PAGE_RESULT, BLOB_LIST_OPTIONS,
BLOB_SOURCE_OPTIONS, BLOB_TARGET_OPTIONS, BUCKET_LIST_OPTIONS, BUCKET_SOURCE_OPTIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ protected Serializable[] serializableObjects() {
.setApiKey(API_KEY)
.setNoCredentials()
.build();
TranslateOptions otherOptions = options.toBuilder()
.setCredentials(null)
.build();
TranslateOptions otherOptions = options.toBuilder().build();
return new Serializable[]{DETECTION, TRANSLATION, TRANSLATE_EXCEPTION, LANGUAGE_LIST_OPTION,
TRANSLATE_OPTION, options, otherOptions};
}
Expand Down