本文整理汇总了Java中org.jclouds.domain.Credentials类的典型用法代码示例。如果您正苦于以下问题:Java Credentials类的具体用法?Java Credentials怎么用?Java Credentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Credentials类属于org.jclouds.domain包,在下文中一共展示了Credentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.jclouds.domain.Credentials; //导入依赖的package包/类
@Override
public Credentials get() {
if (getIdentity() == null || getIdentity().trim().isEmpty() || getCredential() == null || getCredential().trim().isEmpty()) {
DefaultAWSCredentialsProviderChain chain = new DefaultAWSCredentialsProviderChain();
AWSCredentials cred = chain.getCredentials();
if (cred instanceof BasicSessionCredentials) {
BasicSessionCredentials sesCred = (BasicSessionCredentials)cred;
return new SessionCredentials.Builder()
.identity(sesCred.getAWSAccessKeyId())
.credential(sesCred.getAWSSecretKey())
.sessionToken(sesCred.getSessionToken())
.build();
} else {
return new Credentials.Builder<>()
.identity(cred.getAWSAccessKeyId())
.credential(cred.getAWSSecretKey())
.build();
}
}
return super.get();
}
示例2: DimensionDataCloudControllerComputeService
import org.jclouds.domain.Credentials; //导入依赖的package包/类
@Inject
protected DimensionDataCloudControllerComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
GetImageStrategy getImageStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy startNodeStrategy,
SuspendNodeStrategy stopNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
@Named("DEFAULT") Provider<TemplateOptions> templateOptionsProvider,
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
@Named(TIMEOUT_NODE_TERMINATED) Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
@Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
CleanupServer cleanupServer,
Optional<ImageExtension> imageExtension,
Optional<SecurityGroupExtension> securityGroupExtension) {
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getImageStrategy,
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
startNodeStrategy, stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning,
nodeTerminated, nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory,
persistNodeCredentials, timeouts, userExecutor, imageExtension, securityGroupExtension);
this.cleanupServer = checkNotNull(cleanupServer, "cleanupServer");
}
示例3: updateGceCredentialsIfValid
import org.jclouds.domain.Credentials; //导入依赖的package包/类
@Override
public boolean updateGceCredentialsIfValid(String jsonFilePath) throws KaramelException {
if (jsonFilePath.isEmpty() || jsonFilePath == null) {
return false;
}
try {
Credentials credentials = GceLauncher.readCredentials(jsonFilePath);
GceContext context = GceLauncher.validateCredentials(credentials);
Confs confs = Confs.loadKaramelConfs();
confs.put(Settings.GCE_JSON_KEY_FILE_PATH, jsonFilePath);
confs.writeKaramelConfs();
clusterService.registerGceContext(context);
} catch (Throwable ex) {
throw new KaramelException(ex.getMessage());
}
return true;
}
示例4: getCredentialFromFile
import org.jclouds.domain.Credentials; //导入依赖的package包/类
/**
* Reads credential info from {@link #credentialPath} and returns in a string format.
*
* @return Credential in {@code String} representation.
* @throws IgniteSpiException In case of error.
*/
private String getCredentialFromFile() throws IgniteSpiException {
try {
String fileContents = Files.toString(new File(credentialPath), Charsets.UTF_8);
if (provider.equals("google-compute-engine")) {
Supplier<Credentials> credentialSupplier = new GoogleCredentialsFromJson(fileContents);
return credentialSupplier.get().credential;
}
return fileContents;
}
catch (IOException e) {
throw new IgniteSpiException("Failed to retrieve the private key from the file: " + credentialPath, e);
}
}
示例5: AWSEC2CreateNodesInGroupThenAddToSet
import org.jclouds.domain.Credentials; //导入依赖的package包/类
@Inject
protected AWSEC2CreateNodesInGroupThenAddToSet(
AWSEC2Api client,
@Named("ELASTICIP") LoadingCache<RegionAndName, String> elasticIpCache,
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
@Named(PROPERTY_EC2_GENERATE_INSTANCE_NAMES) boolean generateInstanceNames,
CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize,
PresentSpotRequestsAndInstances instancePresent,
Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
LoadingCache<RunningInstance, Optional<LoginCredentials>> instanceToCredentials,
Map<String, Credentials> credentialStore, ComputeUtils utils,
SpotInstanceRequestToAWSRunningInstance spotConverter) {
super(client, elasticIpCache, nodeRunning, createKeyPairAndSecurityGroupsAsNeededAndReturncustomize,
instancePresent, runningInstanceToNodeMetadata, instanceToCredentials, credentialStore, utils);
this.client = checkNotNull(client, "client");
this.spotConverter = checkNotNull(spotConverter, "spotConverter");
}
示例6: OSSApiImpl
import org.jclouds.domain.Credentials; //导入依赖的package包/类
@Inject
public OSSApiImpl(
@Provider final Supplier<Credentials> creds,
RegionIdsSupplier regions) {
this.identity = creds.get().identity;
this.credential = creds.get().credential;
this.regions = regions.get();
}
示例7: ECSComputeService
import org.jclouds.domain.Credentials; //导入依赖的package包/类
@Inject
protected ECSComputeService(
ComputeServiceContext context,
ECSComputeServiceAdapter client,
Map<String, Credentials> credentialStore,
@Memoized Supplier<Set<? extends Image>> images,
Supplier<Set<? extends Hardware>> hardwareProfiles,
@Memoized Supplier<Set<? extends Location>> locations,
ListNodesStrategy listNodesStrategy,
GetImageStrategy getImageStrategy,
GetNodeMetadataStrategy getNodeMetadataStrategy,
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy,
DestroyNodeStrategy destroyNodeStrategy,
ResumeNodeStrategy resumeNodeStrategy,
SuspendNodeStrategy suspendNodeStrategy,
@Named("ECS") Provider<TemplateBuilder> templateBuilderProvider,
@Named("ECS") Provider<TemplateOptions> templateOptionsProvider,
@Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
@Named(TIMEOUT_NODE_TERMINATED) Predicate<AtomicReference<NodeMetadata>> nodeTerminated,
@Named(TIMEOUT_NODE_SUSPENDED) Predicate<AtomicReference<NodeMetadata>> nodeSuspended,
Factory initScriptRunnerFactory,
InitAdminAccess initAdminAccess,
org.jclouds.compute.callables.RunScriptOnNode.Factory runScriptOnNodeFactory,
PersistNodeCredentials persistNodeCredentials,
Timeouts timeouts,
@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
Optional<ImageExtension> imageExtension,
Optional<SecurityGroupExtension> securityGroupExtension) {
super(context, credentialStore, images, hardwareProfiles, locations, listNodesStrategy, getImageStrategy,
getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, resumeNodeStrategy,
suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated, nodeSuspended,
initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory, persistNodeCredentials, timeouts, userExecutor,
imageExtension, securityGroupExtension);
this.client = client;
}
示例8: ServerWithNatRuleToNodeMetadata
import org.jclouds.domain.Credentials; //导入依赖的package包/类
@Inject
ServerWithNatRuleToNodeMetadata(@Memoized Supplier<Set<? extends Location>> locations,
GroupNamingConvention.Factory namingConvention, OsImageToImage osImageToImage,
OsImageToHardware osImageToHardware, Map<String, Credentials> credentialStore) {
this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix();
this.locations = checkNotNull(locations, "locations");
this.osImageToImage = checkNotNull(osImageToImage, "osImageToImage");
this.osImageToHardware = checkNotNull(osImageToHardware, "osImageToHardware");
this.credentialStore = checkNotNull(credentialStore, "credentialStore cannot be null");
}
示例9: getCredentialFromFile
import org.jclouds.domain.Credentials; //导入依赖的package包/类
public String getCredentialFromFile(String provider, String credentialPath) throws IllegalArgumentException {
try {
String fileContents = Files.toString(new File(credentialPath), Charsets.UTF_8);
if (provider.equals(GOOGLE_COMPUTE_ENGINE)) {
Supplier<Credentials> credentialSupplier = new GoogleCredentialsFromJson(fileContents);
return credentialSupplier.get().credential;
}
return fileContents;
} catch (IOException e) {
throw new InvalidConfigurationException("Failed to retrieve the private key from the file: " + credentialPath, e);
}
}
示例10: newContextBuilder
import org.jclouds.domain.Credentials; //导入依赖的package包/类
public ContextBuilder newContextBuilder(final String cloudProvider, final String identity,
final String credential, final String roleName) {
try {
if (roleName != null && (identity != null || credential != null)) {
throw new InvalidConfigurationException("IAM role is configured,"
+ " identity or credential property is not allowed.");
}
if (roleName != null && !cloudProvider.equals(AWS_EC2)) {
throw new InvalidConfigurationException("IAM role is only supported with aws-ec2,"
+ " your cloud provider is " + cloudProvider);
}
if (cloudProvider.equals(AWS_EC2) && roleName != null) {
Supplier<Credentials> credentialsSupplier = new Supplier<Credentials>() {
@Override
public Credentials get() {
return new IAMRoleCredentialSupplierBuilder().
withRoleName(roleName).build();
}
};
return ContextBuilder.newBuilder(cloudProvider).credentialsSupplier(credentialsSupplier);
} else {
checkNotNull(identity, "Cloud provider identity is not set");
checkNotNull(credential, "Cloud provider credential is not set");
return ContextBuilder.newBuilder(cloudProvider).credentials(identity, credential);
}
} catch (NoSuchElementException e) {
throw new InvalidConfigurationException("Unrecognized cloud-provider [" + cloudProvider + "]");
}
}
示例11: CreateAndConnectVSphereClient
import org.jclouds.domain.Credentials; //导入依赖的package包/类
@Inject
public CreateAndConnectVSphereClient(Function<Supplier<NodeMetadata>, ServiceInstance> providerContextToCloud,
Factory runScriptOnNodeFactory,
@Provider Supplier<URI> providerSupplier,
@Provider Supplier<Credentials> credentials) {
this.credentials = checkNotNull(credentials, "credentials is needed");
this.providerSupplier = checkNotNull(providerSupplier, "endpoint to vSphere node or vCenter server is needed");
}
示例12: getTenantId
import org.jclouds.domain.Credentials; //导入依赖的package包/类
public String getTenantId(VimInstance vimInstance) throws VimDriverException {
log.debug(
"Finding TenantID for Tenant with name: "
+ vimInstance.getTenant()
+ " on VimInstance with name: "
+ vimInstance.getName());
try {
ContextBuilder contextBuilder =
ContextBuilder.newBuilder("openstack-nova")
.credentials(vimInstance.getUsername(), vimInstance.getPassword())
.endpoint(vimInstance.getAuthUrl());
ComputeServiceContext context = contextBuilder.buildView(ComputeServiceContext.class);
Function<Credentials, Access> auth =
context
.utils()
.injector()
.getInstance(Key.get(new TypeLiteral<Function<Credentials, Access>>() {}));
//Get Access and all information
Access access =
auth.apply(
new Credentials.Builder<Credentials>()
.identity(vimInstance.getTenant() + ":" + vimInstance.getUsername())
.credential(vimInstance.getPassword())
.build());
//Get Tenant ID of user
String tenant_id = access.getToken().getTenant().get().getId();
log.info(
"Found TenantID for Tenant with name: "
+ vimInstance.getTenant()
+ " on VimInstance with name: "
+ vimInstance.getName()
+ " -> TenantID: "
+ tenant_id);
return tenant_id;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new VimDriverException(e.getMessage());
}
}
示例13: loadGceCredentialsIfExist
import org.jclouds.domain.Credentials; //导入依赖的package包/类
@Override
public String loadGceCredentialsIfExist() throws KaramelException {
Confs confs = Confs.loadKaramelConfs();
String path = confs.getProperty(Settings.GCE_JSON_KEY_FILE_PATH);
if (path != null) {
Credentials credentials = GceLauncher.readCredentials(path);
if (credentials != null) {
return path;
}
}
return null;
}
示例14: GceContext
import org.jclouds.domain.Credentials; //导入依赖的package包/类
public GceContext(Credentials credentials) {
ComputeServiceContext context = ContextBuilder.newBuilder("google-compute-engine")
.modules(Arrays.asList(
new SshjSshClientModule(),
new EnterpriseConfigurationModule(),
new SLF4JLoggingModule()))
.credentials(credentials.identity, credentials.credential)
.buildView(ComputeServiceContext.class);
computeService = context.getComputeService();
gceApi = context.unwrapApi(GoogleComputeEngineApi.class);
fireWallApi = gceApi.firewalls();
networkApi = gceApi.networks();
routeApi = gceApi.routes();
this.credentials = credentials;
}
示例15: readCredentials
import org.jclouds.domain.Credentials; //导入依赖的package包/类
/**
*
* @param jsonKeyPath
* @return
*/
public static Credentials readCredentials(String jsonKeyPath) {
Credentials credentials = null;
if (jsonKeyPath != null && !jsonKeyPath.isEmpty()) {
try {
String fileContents = Files.toString(new File(jsonKeyPath), Charset.defaultCharset());
Supplier<Credentials> credentialSupplier = new GoogleCredentialsFromJson(fileContents);
credentials = credentialSupplier.get();
} catch (IOException ex) {
logger.error("Error Reading the Json key file. Please check the provided path is correct.", ex);
}
}
return credentials;
}