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


Java CredentialsProvider类代码示例

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

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

示例1: GcpPubSubAutoConfiguration

import com.google.api.gax.core.CredentialsProvider; //导入依赖的package包/类
public GcpPubSubAutoConfiguration(GcpPubSubProperties gcpPubSubProperties,
		GcpProjectIdProvider gcpProjectIdProvider,
		CredentialsProvider credentialsProvider) throws IOException {
	this.gcpPubSubProperties = gcpPubSubProperties;
	this.finalProjectIdProvider = gcpPubSubProperties.getProjectId() != null
			? gcpPubSubProperties::getProjectId
			: gcpProjectIdProvider;
	this.finalCredentialsProvider = gcpPubSubProperties.getCredentials().getLocation() != null
			? FixedCredentialsProvider.create(
					GoogleCredentials.fromStream(
							gcpPubSubProperties.getCredentials().getLocation().getInputStream())
							.createScoped(gcpPubSubProperties.getCredentials().getScopes()))
			: credentialsProvider;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:15,代码来源:GcpPubSubAutoConfiguration.java


示例2: StackdriverTraceAutoConfiguration

import com.google.api.gax.core.CredentialsProvider; //导入依赖的package包/类
public StackdriverTraceAutoConfiguration(GcpProjectIdProvider gcpProjectIdProvider,
		CredentialsProvider credentialsProvider,
		GcpTraceProperties gcpTraceProperties) throws IOException {
	this.finalProjectIdProvider = gcpTraceProperties.getProjectId() != null
			? gcpTraceProperties::getProjectId
			: gcpProjectIdProvider;
	this.finalCredentialsProvider = gcpTraceProperties.getCredentials().getLocation() != null
			? FixedCredentialsProvider.create(GoogleCredentials.fromStream(
					gcpTraceProperties.getCredentials().getLocation().getInputStream())
			.createScoped(gcpTraceProperties.getCredentials().getScopes()))
			: credentialsProvider;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:13,代码来源:StackdriverTraceAutoConfiguration.java


示例3: storage

import com.google.api.gax.core.CredentialsProvider; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public static Storage storage(CredentialsProvider credentialsProvider,
		GcpStorageProperties gcpStorageProperties) throws IOException {
	return StorageOptions.newBuilder()
			.setCredentials(gcpStorageProperties.getCredentials().getLocation() != null
					? GoogleCredentials
							.fromStream(gcpStorageProperties.getCredentials()
									.getLocation().getInputStream())
							.createScoped(gcpStorageProperties.getCredentials().getScopes())
					: credentialsProvider.getCredentials())
			.build().getService();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:14,代码来源:StorageAutoConfiguration.java


示例4: PubSubAdmin

import com.google.api.gax.core.CredentialsProvider; //导入依赖的package包/类
/**
 * This constructor instantiates TopicAdminClient and SubscriptionAdminClient with all their
 * defaults and the provided credentials provider.
 */
public PubSubAdmin(GcpProjectIdProvider projectIdProvider,
		CredentialsProvider credentialsProvider) throws IOException {
	this(projectIdProvider,
			TopicAdminClient.create(
					TopicAdminSettings.newBuilder()
							.setCredentialsProvider(credentialsProvider)
							.build()),
			SubscriptionAdminClient.create(
					SubscriptionAdminSettings.newBuilder()
					.setCredentialsProvider(credentialsProvider)
					.build()));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:17,代码来源:PubSubAdmin.java


示例5: GoogleConfigPropertySourceLocator

import com.google.api.gax.core.CredentialsProvider; //导入依赖的package包/类
public GoogleConfigPropertySourceLocator(GcpProjectIdProvider projectIdProvider,
		CredentialsProvider credentialsProvider,
		GcpConfigPropertiesProvider gcpConfigPropertiesProvider) throws IOException {
	Assert.notNull(gcpConfigPropertiesProvider, "Google Config properties must not be null");

	if (gcpConfigPropertiesProvider.isEnabled()) {
		Assert.notNull(credentialsProvider, "Credentials provider cannot be null");
		Assert.notNull(projectIdProvider, "Project ID provider cannot be null");
		org.springframework.cloud.gcp.core.Credentials configCredentials =
				gcpConfigPropertiesProvider.getCredentials();
		this.credentials = configCredentials != null && configCredentials.getLocation() != null
				? GoogleCredentials.fromStream(
						gcpConfigPropertiesProvider.getCredentials().getLocation().getInputStream())
				.createScoped(gcpConfigPropertiesProvider.getCredentials().getScopes())
				: credentialsProvider.getCredentials();
		this.projectId = gcpConfigPropertiesProvider.getProjectId() != null
				? gcpConfigPropertiesProvider.getProjectId()
				: projectIdProvider.getProjectId();
		Assert.notNull(this.credentials, "Credentials must not be null");

		Assert.notNull(this.projectId, "Project ID must not be null");

		this.timeout = gcpConfigPropertiesProvider.getTimeoutMillis();
		this.name = gcpConfigPropertiesProvider.getName();
		this.profile = gcpConfigPropertiesProvider.getProfile();
		this.enabled = gcpConfigPropertiesProvider.isEnabled();
		Assert.notNull(this.name, "Config name must not be null");
		Assert.notNull(this.profile, "Config profile must not be null");
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:31,代码来源:GoogleConfigPropertySourceLocator.java


示例6: googleCredentials

import com.google.api.gax.core.CredentialsProvider; //导入依赖的package包/类
@Bean
public CredentialsProvider googleCredentials() {
	return () -> mock(Credentials.class);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:5,代码来源:GcpCloudSqlTestConfiguration.java


示例7: setCredentialsProvider

import com.google.api.gax.core.CredentialsProvider; //导入依赖的package包/类
/**
 * Set the provider for the GCP credentials to be used by the publisher on every API calls it makes.
 */
public void setCredentialsProvider(CredentialsProvider credentialsProvider) {
	this.credentialsProvider = credentialsProvider;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:7,代码来源:DefaultPublisherFactory.java


示例8: setCredentialsProvider

import com.google.api.gax.core.CredentialsProvider; //导入依赖的package包/类
/**
 * Set the provider for the GCP credentials to be used by the subscribers' API calls.
 */
public void setCredentialsProvider(CredentialsProvider credentialsProvider) {
	this.credentialsProvider = credentialsProvider;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:7,代码来源:DefaultSubscriberFactory.java


示例9: googleCredentials

import com.google.api.gax.core.CredentialsProvider; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public CredentialsProvider googleCredentials() throws Exception {
	CredentialsProvider credentialsProvider;

	Credentials propertyCredentials = this.gcpProperties.getCredentials();

	List<String> scopes = resolveScopes();

	if (!StringUtils.isEmpty(propertyCredentials.getLocation())) {
		credentialsProvider = FixedCredentialsProvider
				.create(GoogleCredentials.fromStream(
						propertyCredentials.getLocation().getInputStream())
				.createScoped(scopes));
	}
	else {
		credentialsProvider = GoogleCredentialsProvider.newBuilder()
				.setScopesToApply(scopes)
				.build();
	}

	try {
		com.google.auth.Credentials credentials = credentialsProvider.getCredentials();

		if (LOGGER.isInfoEnabled()) {
			if (credentials instanceof UserCredentials) {
				LOGGER.info("Default credentials provider for user "
						+ ((UserCredentials) credentials).getClientId());
			}
			else if (credentials instanceof ServiceAccountCredentials) {
				LOGGER.info("Default credentials provider for service account "
						+ ((ServiceAccountCredentials) credentials).getClientEmail());
			}
			else if (credentials instanceof ComputeEngineCredentials) {
				LOGGER.info("Default credentials provider for Google Compute Engine.");
			}
			LOGGER.info("Scopes in use by default credentials: " + scopes.toString());
		}
	}
	catch (IOException ioe) {
		LOGGER.error("No credentials were found.", ioe);
	}

	return credentialsProvider;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:46,代码来源:GcpContextAutoConfiguration.java


示例10: TestApp

import com.google.api.gax.core.CredentialsProvider; //导入依赖的package包/类
public TestApp()  {

    String projectId = ServiceOptions.getDefaultProjectId();
	try {

		//export GRPC_PROXY_EXP=localhost:3128
		HttpHost proxy = new HttpHost("127.0.0.1",3128);
		DefaultHttpClient httpClient = new DefaultHttpClient();
		httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
					
		httpClient.addRequestInterceptor(new HttpRequestInterceptor(){            
			@Override
			public void process(org.apache.http.HttpRequest request, HttpContext context) throws HttpException, IOException {
					//if (request.getRequestLine().getMethod().equals("CONNECT"))                 
					//   request.addHeader(new BasicHeader("Proxy-Authorization","Basic dXNlcjE6dXNlcjE="));
				}
			});
		
		mHttpTransport =  new ApacheHttpTransport(httpClient);		

		HttpTransportFactory hf = new HttpTransportFactory(){
			@Override
			public HttpTransport create() {
				return mHttpTransport;
			}
		};            
		
		credential = GoogleCredentials.getApplicationDefault(hf);

		CredentialsProvider credentialsProvider =  new GoogleCredentialsProvider(){
			public List<String> getScopesToApply(){
				return Arrays.asList("https://www.googleapis.com/auth/pubsub");
			   }

			public Credentials getCredentials()  {
				return credential;
			}
		};

		TopicAdminSettings topicAdminSettings =
		     TopicAdminSettings.newBuilder().setCredentialsProvider(credentialsProvider)
				 .build();
				 
		 TopicAdminClient topicAdminClient =
		     TopicAdminClient.create(topicAdminSettings);
		
		//TopicAdminClient topicAdminClient = TopicAdminClient.create();
		ProjectName project = ProjectName.create(projectId);
		for (Topic element : topicAdminClient.listTopics(project).iterateAll()) 
	  		System.out.println(element.getName());
	
	} catch (Exception ex) 
	{
		System.out.println("ERROR " + ex);
	}
  }
 
开发者ID:salrashid123,项目名称:gcpsamples,代码行数:57,代码来源:TestApp.java



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