本文整理匯總了Java中com.google.api.client.googleapis.auth.oauth2.GoogleCredential.fromStream方法的典型用法代碼示例。如果您正苦於以下問題:Java GoogleCredential.fromStream方法的具體用法?Java GoogleCredential.fromStream怎麽用?Java GoogleCredential.fromStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.api.client.googleapis.auth.oauth2.GoogleCredential
的用法示例。
在下文中一共展示了GoogleCredential.fromStream方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadCredentials
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
/**
* HTTP request initializer that loads credentials from the service account file
* and manages authentication for HTTP requests
*/
private GoogleCredential loadCredentials(String serviceAccount) throws IOException {
if (serviceAccount == null) {
throw new ElasticsearchException("Cannot load Google Cloud Storage service account file from a null path");
}
Path account = environment.configFile().resolve(serviceAccount);
if (Files.exists(account) == false) {
throw new ElasticsearchException("Unable to find service account file [" + serviceAccount
+ "] defined for repository");
}
try (InputStream is = Files.newInputStream(account)) {
GoogleCredential credential = GoogleCredential.fromStream(is);
if (credential.createScopedRequired()) {
credential = credential.createScoped(Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL));
}
return credential;
}
}
示例2: loadStorageCredential
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private static GoogleCredential loadStorageCredential(HttpTransport transport, JsonFactory factory, String jsonPath) throws IOException {
GoogleCredential credential;
if (!jsonPath.isEmpty()) {
FileInputStream stream = new FileInputStream(jsonPath);
credential = GoogleCredential.fromStream(stream, transport, factory);
log.info("Loaded storage credentials from " + jsonPath);
} else {
log.info("Using storage default application credentials.");
credential = GoogleCredential.getApplicationDefault();
}
if (credential.createScopedRequired()) {
credential = credential.createScoped(StorageScopes.all());
}
return credential;
}
示例3: loadKmsCredential
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private static GoogleCredential loadKmsCredential(HttpTransport transport, JsonFactory factory, String jsonPath) throws IOException {
GoogleCredential credential;
if (!jsonPath.isEmpty()) {
FileInputStream stream = new FileInputStream(jsonPath);
credential = GoogleCredential.fromStream(stream, transport, factory);
log.info("Loaded kms credentials from " + jsonPath);
} else {
log.info("Using kms default application credentials.");
credential = GoogleCredential.getApplicationDefault();
}
if (credential.createScopedRequired()) {
credential = credential.createScoped(CloudKMSScopes.all());
}
return credential;
}
示例4: isClusterCollected
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private boolean isClusterCollected(SpydraArgument arguments)
throws IOException, GeneralSecurityException {
GoogleCredential credential = GoogleCredential.fromStream(
new ByteArrayInputStream(gcpUtils.credentialJsonFromEnv().getBytes()));
if (credential.createScopedRequired()) {
credential =
credential.createScoped(
Collections.singletonList("https://www.googleapis.com/auth/cloud-platform"));
}
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
Dataproc dataprocService =
new Dataproc.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("Google Cloud Platform Sample")
.build();
Dataproc.Projects.Regions.Clusters.List request =
dataprocService.projects().regions().clusters().list(
arguments.getCluster().getOptions().get(SpydraArgument.OPTION_PROJECT),
arguments.getRegion());
ListClustersResponse response;
do {
response = request.execute();
if (response.getClusters() == null) continue;
String clusterName = arguments.getCluster().getName();
for (Cluster cluster : response.getClusters()) {
if (cluster.getClusterName().equals(clusterName)) {
String status = cluster.getStatus().getState();
LOGGER.info("Cluster state is" + status);
return status.equals("DELETING");
}
}
request.setPageToken(response.getNextPageToken());
} while (response.getNextPageToken() != null);
return true;
}
示例5: getGoogleCredential
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private GoogleCredential getGoogleCredential() {
try {
if (StringUtils.isNotEmpty(config.getCredentialPath())) {
return GoogleCredential.fromStream(new FileInputStream(config.getCredentialPath()));
} else {
return GoogleCredential.getApplicationDefault();
}
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
示例6: loadCredential
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private synchronized void loadCredential() throws IOException {
if (credential != null) {
return;
}
final InputStream credentialStream =
getCredentialStreamFromResource(Resources.getResource(resourceName));
credential = GoogleCredential.fromStream(credentialStream);
}
示例7: init
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
public static AndroidPublisher init(Context context, String fileName) throws IOException {
Preconditions.checkArgument(!Strings.isNullOrEmpty(context.getPackageName()), "applicationId cannot be null or empty!");
newTrustedTransport();
GoogleCredential credential = GoogleCredential.fromStream(context.getAssets().open(fileName), HTTP_TRANSPORT, JSON_FACTORY);
credential = credential.createScoped(Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER));
return new AndroidPublisher.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
.setApplicationName(context.getPackageName())
.build();
}
示例8: pubSubCloud
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
@Bean
@Profile("cloud")
public PubSub pubSubCloud(Environment environment) throws Exception {
String vcapServicesEnv = environment.getProperty("VCAP_SERVICES");
JsonParser parser = JsonParserFactory.getJsonParser();
Map<String, Object> services = parser.parseMap(vcapServicesEnv);
List<Map<String, Object>> googlePubsub = (List<Map<String, Object>>) services.get("google-pubsub");
Map<String, Object> credentials = (Map<String, Object>) googlePubsub.get(0).get("credentials");
String privateKeyData = (String) credentials.get("PrivateKeyData");
GoogleCredential googleCredential = GoogleCredential.fromStream(new ByteArrayInputStream(Base64.decodeBase64(privateKeyData)));
return PubSubOptions.newBuilder().setAuthCredentials(AuthCredentials.createFor(googleCredential.getServiceAccountId(),
googleCredential.getServiceAccountPrivateKey()))
.setProjectId(pubSubBinderConfigurationProperties.getProjectName()).build().getService();
}
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-binder-google-pubsub,代碼行數:16,代碼來源:PubSubServiceAutoConfiguration.java
示例9: googleCredential
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
private GoogleCredential googleCredential(String credential)
{
try {
return GoogleCredential.fromStream(new ByteArrayInputStream(credential.getBytes(UTF_8)));
}
catch (IOException e) {
throw new TaskExecutionException(e, buildExceptionErrorConfig(e));
}
}
示例10: provideGoogleCredential
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; //導入方法依賴的package包/類
@Provides
@Singleton
static GoogleCredential provideGoogleCredential(
NetHttpTransport netHttpTransport,
JsonFactory jsonFactory,
@Key("jsonCredential") String jsonCredential) {
try {
return GoogleCredential.fromStream(
new ByteArrayInputStream(jsonCredential.getBytes(UTF_8)),
netHttpTransport,
jsonFactory);
} catch (IOException e) {
throw new RuntimeException(e);
}
}