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

Add missing Application Default Credentials region tags. #238

Merged
merged 1 commit into from
May 12, 2016
Merged
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
11 changes: 8 additions & 3 deletions storage/json-api/src/main/java/StorageFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
/**
* This class manages the details of creating a Storage service, including auth.
*/
// [START authentication_application_default_credentials]
public class StorageFactory {

private static Storage instance = null;

public static synchronized Storage getService() throws IOException, GeneralSecurityException {
Expand All @@ -45,13 +45,18 @@ private static Storage buildService() throws IOException, GeneralSecurityExcepti
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);

// Depending on the environment that provides the default credentials (for
// example: Compute Engine, App Engine), the credentials may require us to
// specify the scopes we need explicitly. Check for this case, and inject
// the Cloud Storage scope if required.
if (credential.createScopedRequired()) {
Collection<String> bigqueryScopes = StorageScopes.all();
credential = credential.createScoped(bigqueryScopes);
Collection<String> scopes = StorageScopes.all();
credential = credential.createScoped(scopes);
}

return new Storage.Builder(transport, jsonFactory, credential)
.setApplicationName("GCS Samples")
.build();
}
}
// [END authentication_application_default_credentials]