use of org.jclouds.domain.Credentials in project dhis2-core by dhis2.
the class JCloudsFileResourceContentStore method configureForProvider.
private Pair<Credentials, Properties> configureForProvider(String provider, String identity, String secret) {
Properties overrides = new Properties();
Credentials credentials = new Credentials("Unused", "Unused");
if (provider.equals(JCLOUDS_PROVIDER_KEY_FILESYSTEM) && locationManager.externalDirectorySet()) {
overrides.setProperty(FilesystemConstants.PROPERTY_BASEDIR, locationManager.getExternalDirectoryPath());
} else if (provider.equals(JCLOUDS_PROVIDER_KEY_AWS_S3)) {
credentials = new Credentials(identity, secret);
overrides.setProperty(S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false");
if (credentials.identity.isEmpty() || credentials.credential.isEmpty()) {
log.warn("AWS S3 store configured without credentials, authentication not possible.");
}
}
return Pair.of(credentials, overrides);
}
use of org.jclouds.domain.Credentials in project hive by apache.
the class CloudComputeService method getCredentialsFromJsonKeyFile.
public static Credentials getCredentialsFromJsonKeyFile(String filename) throws IOException {
String fileContents = Files.toString(new File(filename), UTF_8);
Supplier<Credentials> credentialSupplier = new GoogleCredentialsFromJson(fileContents);
return credentialSupplier.get();
}
use of org.jclouds.domain.Credentials in project hive by apache.
the class CloudExecutionContextProvider method createGceService.
private static CloudComputeService createGceService(final Context context) throws IOException {
String gceJsonFile = Preconditions.checkNotNull(context.getString(GCE_JSON_CREDS_FILE), GCE_JSON_CREDS_FILE + " is required");
String imageId = Preconditions.checkNotNull(context.getString(IMAGE_ID), IMAGE_ID + " is required");
String securityGroup = Preconditions.checkNotNull(context.getString(SECURITY_GROUP), SECURITY_GROUP + " is required");
String instanceType = Preconditions.checkNotNull(context.getString(INSTANCE_TYPE, ""), INSTANCE_TYPE + " is required");
String groupName = context.getString(GROUP_NAME, "hive-ptest-slaves");
CloudComputeService.CloudComputeConfig config = new CloudComputeService.CloudComputeConfig(CloudComputeService.CloudComputeConfig.CloudComputeProvider.GCE);
Credentials creds = CloudComputeService.getCredentialsFromJsonKeyFile(gceJsonFile);
config.setCredentials(creds.identity, creds.credential);
config.setInstanceType(instanceType);
config.setGroupName(groupName);
config.setImageId(imageId);
config.setSecurityGroup(securityGroup);
config.setUserMetaData(context.getSubProperties(USER_METADATA + "."));
return new CloudComputeService(config);
}
use of org.jclouds.domain.Credentials in project whirr by apache.
the class RunningInstanceToNodeMetadata method apply.
@Override
public NodeMetadata apply(final RunningInstance instance) {
String id = checkNotNull(instance, "instance").getId();
// user doesn't determine a node name;
String name = null;
// no uri to get rest access to host info
URI uri = null;
String tag = getTagForInstace(instance);
Credentials credentials = getCredentialsForInstanceWithTag(instance, tag);
Map<String, String> userMetadata = ImmutableMap.<String, String>of();
NodeState state = instanceToNodeState.get(instance.getInstanceState());
Set<String> publicAddresses = nullSafeSet(instance.getIpAddress());
Set<String> privateAddresses = nullSafeSet(instance.getPrivateIpAddress());
Map<String, String> extra = getExtra(instance);
Location location = getLocationForAvailabilityZone(instance);
Image image = resolveImageForInstanceInLocation(instance, location);
return new NodeMetadataImpl(id, name, instance.getRegion() + "/" + instance.getId(), location, uri, userMetadata, tag, image, state, publicAddresses, privateAddresses, extra, credentials);
}
use of org.jclouds.domain.Credentials in project artifact-manager-s3-plugin by jenkinsci.
the class JCloudsArtifactManager method getContext.
private static BlobStoreContext getContext(String blobContainer) throws IOException {
// TODO allow configuration
// get user credentials from env vars, profiles,...
AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
try {
builder.build().doesBucketExistV2(blobContainer);
} catch (RuntimeException x) {
throw new IOException(x);
}
// Assume we are using session credentials
AWSSessionCredentials awsCredentials = (AWSSessionCredentials) builder.getCredentials().getCredentials();
if (awsCredentials == null) {
throw new IOException("Unable to detect AWS session credentials");
}
SessionCredentials sessionCredentials = SessionCredentials.builder().accessKeyId(//
awsCredentials.getAWSAccessKeyId()).secretAccessKey(//
awsCredentials.getAWSSecretKey()).sessionToken(//
awsCredentials.getSessionToken()).build();
Supplier<Credentials> credentialsSupplier = new Supplier<Credentials>() {
@Override
public Credentials get() {
return sessionCredentials;
}
};
ProviderRegistry.registerProvider(AWSS3ProviderMetadata.builder().build());
try {
return ContextBuilder.newBuilder("aws-s3").credentialsSupplier(credentialsSupplier).buildView(BlobStoreContext.class);
} catch (NoSuchElementException x) {
throw new IOException(x);
}
}
Aggregations