Search in sources :

Example 6 with Credentials

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);
}
Also used : Credentials(org.jclouds.domain.Credentials)

Example 7 with Credentials

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();
}
Also used : GoogleCredentialsFromJson(org.jclouds.googlecloud.GoogleCredentialsFromJson) File(java.io.File) Credentials(org.jclouds.domain.Credentials)

Example 8 with Credentials

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);
}
Also used : Credentials(org.jclouds.domain.Credentials)

Example 9 with Credentials

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);
}
Also used : NodeState(org.jclouds.compute.domain.NodeState) NodeMetadataImpl(org.jclouds.compute.domain.internal.NodeMetadataImpl) Image(org.jclouds.compute.domain.Image) URI(java.net.URI) Credentials(org.jclouds.domain.Credentials) Location(org.jclouds.domain.Location)

Example 10 with 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);
    }
}
Also used : SessionCredentials(org.jclouds.aws.domain.SessionCredentials) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) Supplier(shaded.com.google.common.base.Supplier) IOException(java.io.IOException) SessionCredentials(org.jclouds.aws.domain.SessionCredentials) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) Credentials(org.jclouds.domain.Credentials) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

Credentials (org.jclouds.domain.Credentials)20 Cluster (org.apache.whirr.Cluster)7 Location (org.jclouds.domain.Location)3 LoginCredentials (org.jclouds.domain.LoginCredentials)3 AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)2 NoSuchElementException (java.util.NoSuchElementException)2 Properties (java.util.Properties)2 PostConstruct (javax.annotation.PostConstruct)2 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 SessionCredentials (org.jclouds.aws.domain.SessionCredentials)2 LocationBuilder (org.jclouds.domain.LocationBuilder)2 HttpResponseException (org.jclouds.http.HttpResponseException)2 AuthorizationException (org.jclouds.rest.AuthorizationException)2 Before (org.junit.Before)2 Test (org.junit.Test)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)1 Module (com.google.inject.Module)1 File (java.io.File)1