当前位置: 首页>>代码示例>>Java>>正文


Java StorageScopes类代码示例

本文整理汇总了Java中com.google.api.services.storage.StorageScopes的典型用法代码示例。如果您正苦于以下问题:Java StorageScopes类的具体用法?Java StorageScopes怎么用?Java StorageScopes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StorageScopes类属于com.google.api.services.storage包,在下文中一共展示了StorageScopes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadCredentials

import com.google.api.services.storage.StorageScopes; //导入依赖的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;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:GoogleCloudStorageService.java

示例2: loadStorageCredential

import com.google.api.services.storage.StorageScopes; //导入依赖的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;
}
 
开发者ID:spinnaker,项目名称:halyard,代码行数:18,代码来源:GoogleStorage.java

示例3: getService

import com.google.api.services.storage.StorageScopes; //导入依赖的package包/类
/**
 * Method to create the service or get the service if is already created.
 *
 * @author <a href="mailto:[email protected]"> João Felipe de Medeiros Moreira </a>
 * @since 13/10/2015
 *
 * @return the Storage service already created.
 *
 * @throws IOException in case a IO problem.
 * @throws GeneralSecurityException in case a security problem.
 */
private static Storage getService() throws IOException, GeneralSecurityException {
  logger.finest("###### Getting the storage service");
  if (null == storageService) {
    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    GoogleCredential credential = GoogleCredential.getApplicationDefault();
    // Depending on the environment that provides the default credentials (e.g. 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()) {
      credential = credential.createScoped(StorageScopes.all());
    }
    storageService = new Storage.Builder(httpTransport, JSON_FACTORY, credential)
        .setApplicationName(APPLICATION_NAME).build();
  }
  return storageService;
}
 
开发者ID:ciandt-dev,项目名称:tech-gallery,代码行数:28,代码来源:StorageHandler.java

示例4: getServiceAccountCredential

import com.google.api.services.storage.StorageScopes; //导入依赖的package包/类
/**
 * @see https://developers.google.com/accounts/docs/OAuth2ServiceAccount#authorizingrequests
 */
private GoogleCredential getServiceAccountCredential() throws IOException, GeneralSecurityException
{
    // @see https://cloud.google.com/compute/docs/api/how-tos/authorization
    // @see https://developers.google.com/resources/api-libraries/documentation/storage/v1/java/latest/com/google/api/services/storage/STORAGE_SCOPE.html
    // @see https://developers.google.com/resources/api-libraries/documentation/bigquery/v2/java/latest/com/google/api/services/bigquery/BigqueryScopes.html
    return new GoogleCredential.Builder()
            .setTransport(httpTransport)
            .setJsonFactory(jsonFactory)
            .setServiceAccountId(serviceAccountEmail.orNull())
            .setServiceAccountScopes(
                    ImmutableList.of(
                            StorageScopes.DEVSTORAGE_READ_WRITE
                    )
            )
            .setServiceAccountPrivateKeyFromP12File(new File(p12KeyFilePath.get()))
            .build();
}
 
开发者ID:embulk,项目名称:embulk-output-gcs,代码行数:21,代码来源:GcsAuthentication.java

示例5: buildService

import com.google.api.services.storage.StorageScopes; //导入依赖的package包/类
private static Storage buildService() throws IOException, GeneralSecurityException {
  HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
  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> scopes = StorageScopes.all();
    credential = credential.createScoped(scopes);
  }

  return new Storage.Builder(transport, jsonFactory, credential)
      .setApplicationName("GCS Samples")
      .build();
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:19,代码来源:StorageFactory.java

示例6: getService

import com.google.api.services.storage.StorageScopes; //导入依赖的package包/类
private static Storage getService(String credentialsPath, int connectTimeoutMs, int readTimeoutMs) throws Exception {
    if (mStorageService == null) {
        HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();

        GoogleCredential credential;
        try {
            // Lookup if configured path from the properties; otherwise fallback to Google Application default
            if (credentialsPath != null && !credentialsPath.isEmpty()) {
                credential = GoogleCredential
                        .fromStream(new FileInputStream(credentialsPath), httpTransport, JSON_FACTORY)
                        .createScoped(Collections.singleton(StorageScopes.CLOUD_PLATFORM));
            } else {
                credential = GoogleCredential.getApplicationDefault(httpTransport, JSON_FACTORY);
            }
        } catch (IOException e) {
            throw new RuntimeException("Failed to load Google credentials : " + credentialsPath, e);
        }

        mStorageService = new Storage.Builder(httpTransport, JSON_FACTORY,
                setHttpBackoffTimeout(credential, connectTimeoutMs, readTimeoutMs))
                .setApplicationName("com.pinterest.secor")
                .build();
    }
    return mStorageService;
}
 
开发者ID:pinterest,项目名称:secor,代码行数:26,代码来源:GsUploadManager.java

示例7: constructStorageApiStub

import com.google.api.services.storage.StorageScopes; //导入依赖的package包/类
private static Storage constructStorageApiStub() throws GeneralSecurityException, IOException {
  JsonFactory jsonFactory = new JacksonFactory();
  HttpTransport transport;
  transport = GoogleNetHttpTransport.newTrustedTransport();
  GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
  if (credential.createScopedRequired()) {
    Collection<String> scopes = StorageScopes.all();
    credential = credential.createScoped(scopes);
  }
  return new Storage.Builder(transport, jsonFactory, credential)
      .setApplicationName("GCS Samples")
      .build();
}
 
开发者ID:GoogleCloudPlatform,项目名称:policyscanner,代码行数:14,代码来源:GCSFilesSource.java

示例8: buildService

import com.google.api.services.storage.StorageScopes; //导入依赖的package包/类
private static Storage buildService() throws IOException, GeneralSecurityException {
    HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();
    JsonFactory jsonFactory = new JacksonFactory();
    GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);

    if (credential.createScopedRequired()) {
        Collection<String> bigqueryScopes = StorageScopes.all();
        credential = credential.createScoped(bigqueryScopes);
    }

    return new Storage.Builder(transport, jsonFactory, credential)
            .setApplicationName("MCSFS")
            .build();
}
 
开发者ID:darshanmaiya,项目名称:MCSFS,代码行数:15,代码来源:StorageFactory.java

示例9: loadCredential

import com.google.api.services.storage.StorageScopes; //导入依赖的package包/类
private GoogleCredential loadCredential(HttpTransport transport, JsonFactory factory, String jsonPath) throws IOException {
  GoogleCredential credential;
  if (!jsonPath.isEmpty()) {
    FileInputStream stream = new FileInputStream(jsonPath);
    credential = GoogleCredential.fromStream(stream, transport, factory)
        .createScoped(Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL));
    log.info("Loaded credentials from " + jsonPath);
  } else {
    log.info("Using default application credentials.");
    credential = GoogleCredential.getApplicationDefault();
  }
  return credential;
}
 
开发者ID:spinnaker,项目名称:halyard,代码行数:14,代码来源:GoogleWriteableProfileRegistry.java

示例10: readStorageFile

import com.google.api.services.storage.StorageScopes; //导入依赖的package包/类
public InputStream readStorageFile(String file) throws IOException, GeneralSecurityException {
	httpTransport = GoogleNetHttpTransport.newTrustedTransport();

	Set<String> scopes = new HashSet<String>();
	scopes.add(StorageScopes.DEVSTORAGE_FULL_CONTROL);
	scopes.add(StorageScopes.DEVSTORAGE_READ_ONLY);
	scopes.add(StorageScopes.DEVSTORAGE_READ_WRITE);

	GoogleCredential credential = null;
	try {
		credential = new GoogleCredential.Builder()
				.setTransport(httpTransport)
				.setJsonFactory(JSON_FACTORY)
				.setServiceAccountId(Constants.GCP_ACCOUNT_ID)
				.setServiceAccountScopes(scopes)
				.setServiceAccountPrivateKeyFromP12File(new File(Constants.GCP_ACCOUNT_KEY))
				.build();
	} catch (GeneralSecurityException e) {
		e.printStackTrace();
	}

	Storage storage = new Storage.Builder(httpTransport, JSON_FACTORY, credential)
			.setApplicationName(Constants.APPLICATION_NAME).build();

	Storage.Objects.Get get = storage.objects().get(Constants.GCP_STORAGE_BUCKET, file);
	// OutputStream stream = new OutputStream(file);
	InputStream is = get.executeMediaAsInputStream();
	return is;
}
 
开发者ID:saurabhkaushik,项目名称:googpredictapp,代码行数:30,代码来源:PredictionEngine.java

示例11: createClient

import com.google.api.services.storage.StorageScopes; //导入依赖的package包/类
private Storage createClient() throws IOException, GeneralSecurityException {
    GoogleCredential credential = GoogleCredential.fromStream(
            new ByteArrayInputStream(settings.serviceAccount.getBytes(StandardCharsets.UTF_8)))
                                                  .createScoped(Collections.singleton(StorageScopes.CLOUD_PLATFORM));

    NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
    return new Storage.Builder(
            httpTransport, JSON_FACTORY, null).setApplicationName(APPLICATION_NAME)
                                              .setHttpRequestInitializer(credential).build();
}
 
开发者ID:simpleci,项目名称:simpleci,代码行数:12,代码来源:GoogleStorageCacheManager.java

示例12: authorize

import com.google.api.services.storage.StorageScopes; //导入依赖的package包/类
/**
 * Authorizes the installed application to access user's protected data.
 */
public static Credential authorize() throws IOException {
    // Load client secrets.
    final byte[] bytes = Files.toByteArray(new File(clientSecretFile));
    final GoogleClientSecrets clientSecrets = GoogleClientSecrets
        .load(JSON_FACTORY, new InputStreamReader(new ByteArrayInputStream(bytes)));
    if (clientSecrets.getDetails().getClientId() == null
        || clientSecrets.getDetails().getClientSecret() == null) {
        throw new IllegalStateException("client_secrets not well formed.");
    }


    // Set up authorization code flow.
    // Ask for only the permissions you need. Asking for more permissions will
    // reduce the number of users who finish the process for giving you access
    // to their accounts. It will also increase the amount of effort you will
    // have to spend explaining to users what you are doing with their data.
    // Here we are listing all of the available scopes. You should remove scopes
    // that you are not actually using.
    final Set<String> scopes = new HashSet<String>();
    scopes.add(StorageScopes.DEVSTORAGE_FULL_CONTROL);
    scopes.add(StorageScopes.DEVSTORAGE_READ_ONLY);
    scopes.add(StorageScopes.DEVSTORAGE_READ_WRITE);

    final GoogleAuthorizationCodeFlow flow =
        new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets,
            scopes).setDataStoreFactory(dataStoreFactory).build();
    // Authorize.
    final VerificationCodeReceiver receiver =
        AUTH_LOCAL_WEBSERVER ? new LocalServerReceiver() : new GooglePromptReceiver();
    return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
 
开发者ID:DevOps-TangoMe,项目名称:gcloud-storage-speedtest,代码行数:35,代码来源:CredentialsManager.java

示例13: getServiceAccountCredentialFromJsonFile

import com.google.api.services.storage.StorageScopes; //导入依赖的package包/类
private GoogleCredential getServiceAccountCredentialFromJsonFile() throws IOException
{
    FileInputStream stream = new FileInputStream(jsonKeyFilePath.get());

    return GoogleCredential.fromStream(stream, httpTransport, jsonFactory)
            .createScoped(Collections.singleton(StorageScopes.DEVSTORAGE_READ_WRITE));
}
 
开发者ID:embulk,项目名称:embulk-output-gcs,代码行数:8,代码来源:GcsAuthentication.java

示例14: gcsClient

import com.google.api.services.storage.StorageScopes; //导入依赖的package包/类
private Storage gcsClient(GoogleCredential credential)
{
    if (credential.createScopedRequired()) {
        credential = credential.createScoped(StorageScopes.all());
    }
    return new Storage.Builder(transport, jsonFactory, credential)
            .setApplicationName("digdag-test")
            .build();
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:10,代码来源:BigQueryIT.java

示例15: createCredentials

import com.google.api.services.storage.StorageScopes; //导入依赖的package包/类
private Credential createCredentials(Config configuration) throws IOException {
  final String credentialsPath = GcsContext.getCredentialsPath(configuration);
  if (!Strings.isNullOrEmpty(credentialsPath)) {
    LOG.info("Using credentials from file: " + credentialsPath);
    return GoogleCredential
        .fromStream(new FileInputStream(credentialsPath))
        .createScoped(StorageScopes.all());
  }

  // if a credentials path is not provided try using the application default one.
  LOG.info("Using default application credentials");
  return GoogleCredential.getApplicationDefault().createScoped(StorageScopes.all());
}
 
开发者ID:twitter,项目名称:heron,代码行数:14,代码来源:GcsUploader.java


注:本文中的com.google.api.services.storage.StorageScopes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。