本文整理汇总了Java中com.google.auth.Credentials类的典型用法代码示例。如果您正苦于以下问题:Java Credentials类的具体用法?Java Credentials怎么用?Java Credentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Credentials类属于com.google.auth包,在下文中一共展示了Credentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.google.auth.Credentials; //导入依赖的package包/类
@Before
public void setUp() {
this.gcpConfigProperties = mock(GcpConfigPropertiesProvider.class);
when(this.gcpConfigProperties.getName()).thenReturn("test");
when(this.gcpConfigProperties.isEnabled()).thenReturn(true);
org.springframework.cloud.gcp.core.Credentials configCredentials =
mock(org.springframework.cloud.gcp.core.Credentials.class);
when(this.gcpConfigProperties.getCredentials()).thenReturn(configCredentials);
when(this.gcpConfigProperties.getProfile()).thenReturn("default");
this.expectedProperties = new HashMap<>();
this.expectedProperties.put("property-int", 10);
this.expectedProperties.put("property-bool", true);
this.projectIdProvider = () -> "projectid";
this.credentialsProvider = () -> mock(Credentials.class);
}
示例2: newCloudResourceManagerClient
import com.google.auth.Credentials; //导入依赖的package包/类
/**
* Returns a CloudResourceManager client builder using the specified
* {@link CloudResourceManagerOptions}.
*/
@VisibleForTesting
static CloudResourceManager.Builder newCloudResourceManagerClient(
CloudResourceManagerOptions options) {
Credentials credentials = options.getGcpCredential();
if (credentials == null) {
NullCredentialInitializer.throwNullCredentialException();
}
return new CloudResourceManager.Builder(Transport.getTransport(), Transport.getJsonFactory(),
chainHttpRequestInitializer(
credentials,
// Do not log 404. It clutters the output and is possibly even required by the caller.
new RetryHttpRequestInitializer(ImmutableList.of(404))))
.setApplicationName(options.getAppName())
.setGoogleClientRequestInitializer(options.getGoogleApiTrace());
}
示例3: ChannelOptions
import com.google.auth.Credentials; //导入依赖的package包/类
/**
* Construct a ChannelOptions object
* @param credential A credential to use, may be null.
* @param authority The authority to be passed in the HTTP/2 headers, or {@code null}
* to use the default.
* @param callTimingReportPath A client-local file to which a report of call timings
* will be appended
* @param callStatusReportPath A client-local file to which a report of call statuses
* will be appended
* @param unaryCallRetryOptions Options for how to handle retriable failed UnaryCalls.
* @param scheduledExecutorService ScheduledExecutorService on which to retry RPCs.
*/
public ChannelOptions(Credentials credential,
String authority,
String callTimingReportPath,
String callStatusReportPath,
RetryOptions unaryCallRetryOptions,
ScheduledExecutorService scheduledExecutorService,
long timeoutMs,
int channelCount) {
this.credential = credential;
this.authority = authority;
this.callTimingReportPath = callTimingReportPath;
this.callStatusReportPath = callStatusReportPath;
this.scheduledExecutorService = scheduledExecutorService;
this.unaryCallRetryOptions = unaryCallRetryOptions;
this.timeoutMs = timeoutMs;
this.channelCount = channelCount;
}
示例4: PubSubClient
import com.google.auth.Credentials; //导入依赖的package包/类
public PubSubClient(PubSubDatastoreProperties datastore) {
Credentials credentials = null;
if (datastore.serviceAccountFile.getValue() == null) {
try {
credentials = GoogleCredentials.getApplicationDefault().createScoped(PubsubScopes.all());
} catch (IOException e) {
throw TalendRuntimeException.createUnexpectedException(e);
}
} else {
credentials = createCredentials(datastore);
}
this.PROJECT_NAME = datastore.projectName.getValue();
this.client = new Pubsub.Builder(Transport.getTransport(), Transport.getJsonFactory(),
chainHttpRequestInitializer(credentials,
// Do not log 404. It clutters the output and is possibly even required by the caller.
new RetryHttpRequestInitializer(ImmutableList.of(404)))).build();
}
示例5: newCredentials
import com.google.auth.Credentials; //导入依赖的package包/类
/**
* Create a new {@link Credentials} object.
*
* @throws IOException in case the credentials can't be constructed.
*/
public static Credentials newCredentials(AuthAndTLSOptions options) throws IOException {
if (options.googleCredentials != null) {
// Credentials from file
try (InputStream authFile = new FileInputStream(options.googleCredentials)) {
return newCredentials(authFile, options.googleAuthScopes);
} catch (FileNotFoundException e) {
String message =
String.format(
"Could not open auth credentials file '%s': %s",
options.googleCredentials, e.getMessage());
throw new IOException(message, e);
}
} else if (options.useGoogleDefaultCredentials) {
return newCredentials(
null /* Google Application Default Credentials */, options.googleAuthScopes);
}
return null;
}
示例6: setUp
import com.google.auth.Credentials; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
Credentials mock = (Credentials) invocation.getMock();
URI uri = (URI) invocation.getArguments()[0];
RequestMetadataCallback callback = (RequestMetadataCallback) invocation.getArguments()[2];
Map<String, List<String>> metadata;
try {
// Default to calling the blocking method, since it is easier to mock
metadata = mock.getRequestMetadata(uri);
} catch (Exception ex) {
callback.onFailure(ex);
return null;
}
callback.onSuccess(metadata);
return null;
}
}).when(credentials).getRequestMetadata(
any(URI.class),
any(Executor.class),
any(RequestMetadataCallback.class));
}
示例7: GoogleConfigPropertySourceLocator
import com.google.auth.Credentials; //导入依赖的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");
}
}
示例8: getCredentials
import com.google.auth.Credentials; //导入依赖的package包/类
/** Returns a set of {@link Credentials} which can be used to authenticate requests. */
public Credentials getCredentials() {
if (oauthConfig.getCredentialsCase() == CredentialsCase.ACCESS_TOKEN_CREDENTIALS) {
return createAccessTokenCredentials(oauthConfig.getAccessTokenCredentials());
} else if (oauthConfig.getCredentialsCase() == CredentialsCase.REFRESH_TOKEN_CREDENTIALS) {
return createRefreshTokenCredentials(oauthConfig.getRefreshTokenCredentials());
} else {
throw new IllegalArgumentException(
"Unknown oauth credential type: " + oauthConfig.getCredentialsCase());
}
}
示例9: createAccessTokenCredentials
import com.google.auth.Credentials; //导入依赖的package包/类
private Credentials createAccessTokenCredentials(AccessTokenCredentials accessTokenCreds) {
AccessToken accessToken = new AccessToken(
readFile(Paths.get(accessTokenCreds.getAccessTokenPath())), null);
logger.info("Using access token credentials");
return new OAuth2Credentials(accessToken);
}
示例10: createRefreshTokenCredentials
import com.google.auth.Credentials; //导入依赖的package包/类
private Credentials createRefreshTokenCredentials(
OauthConfiguration.RefreshTokenCredentials refreshTokenCreds) {
String exchangeUrl = oauthConfig.getRefreshTokenCredentials().getTokenEndpointUrl();
String refreshToken = readFile(
Paths.get(oauthConfig.getRefreshTokenCredentials().getRefreshTokenPath()));
OauthClient oauthClient = oauthConfig.getRefreshTokenCredentials().getClient();
logger.info("Using refresh token credentials");
return RefreshTokenCredentials.create(oauthClient, refreshToken, exchangeUrl);
}
示例11: getCredentials
import com.google.auth.Credentials; //导入依赖的package包/类
/**
* Creates and returns the credentials from the given connection parameters.
*
* @param parameters
* the connection parameters
* @return the credentials for authenticating with the Datastore service.
* @throws IOException
* if any error occurs such as not able to read the credentials file.
*/
private static Credentials getCredentials(ConnectionParameters parameters) throws IOException {
if (parameters.isEmulator()) {
return NoCredentials.getInstance();
}
InputStream jsonCredentialsStream = parameters.getJsonCredentialsStream();
if (jsonCredentialsStream != null) {
return ServiceAccountCredentials.fromStream(jsonCredentialsStream);
}
File jsonCredentialsFile = parameters.getJsonCredentialsFile();
if (jsonCredentialsFile != null) {
return ServiceAccountCredentials.fromStream(new FileInputStream(jsonCredentialsFile));
}
return ServiceAccountCredentials.getApplicationDefault();
}
示例12: createInternal
import com.google.auth.Credentials; //导入依赖的package包/类
private static void createInternal(
@Nullable Credentials credentials,
@Nullable String projectId,
@Nullable Duration exportInterval,
@Nullable MonitoredResource monitoredResource)
throws IOException {
projectId = projectId == null ? ServiceOptions.getDefaultProjectId() : projectId;
exportInterval = exportInterval == null ? DEFAULT_INTERVAL : exportInterval;
monitoredResource = monitoredResource == null ? DEFAULT_RESOURCE : monitoredResource;
synchronized (monitor) {
checkState(exporter == null, "Stackdriver stats exporter is already created.");
MetricServiceClient metricServiceClient;
// Initialize MetricServiceClient inside lock to avoid creating multiple clients.
if (credentials == null) {
metricServiceClient = MetricServiceClient.create();
} else {
metricServiceClient =
MetricServiceClient.create(
MetricServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
.build());
}
exporter =
new StackdriverStatsExporter(
projectId,
metricServiceClient,
exportInterval,
Stats.getViewManager(),
monitoredResource);
exporter.workerThread.start();
}
}
示例13: createWithCredentials
import com.google.auth.Credentials; //导入依赖的package包/类
static StackdriverV2ExporterHandler createWithCredentials(
Credentials credentials, String projectId) throws IOException {
checkNotNull(credentials, "credentials");
TraceServiceSettings traceServiceSettings =
TraceServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credentials))
.build();
return new StackdriverV2ExporterHandler(
projectId, TraceServiceClient.create(traceServiceSettings));
}
示例14: chainHttpRequestInitializer
import com.google.auth.Credentials; //导入依赖的package包/类
private static HttpRequestInitializer chainHttpRequestInitializer(
Credentials credential, HttpRequestInitializer httpRequestInitializer) {
if (credential == null) {
return new ChainingHttpRequestInitializer(
new NullCredentialInitializer(), httpRequestInitializer);
} else {
return new ChainingHttpRequestInitializer(
new HttpCredentialsAdapter(credential),
httpRequestInitializer);
}
}
示例15: getGcpCredential
import com.google.auth.Credentials; //导入依赖的package包/类
/**
* The credential instance that should be used to authenticate against GCP services.
* If no credential has been set explicitly, the default is to use the instance factory
* that constructs a credential based upon the currently set credentialFactoryClass.
*/
@JsonIgnore
@Description("The credential instance that should be used to authenticate against GCP services. "
+ "If no credential has been set explicitly, the default is to use the instance factory "
+ "that constructs a credential based upon the currently set credentialFactoryClass.")
@Default.InstanceFactory(GcpUserCredentialsFactory.class)
Credentials getGcpCredential();