Search in sources :

Example 1 with Credentials

use of org.jclouds.domain.Credentials in project SimianArmy by Netflix.

the class AWSClient method getJcloudsComputeService.

/**
 * {@inheritDoc}
 */
@Override
public ComputeService getJcloudsComputeService() {
    if (jcloudsComputeService == null) {
        synchronized (this) {
            if (jcloudsComputeService == null) {
                AWSCredentials awsCredentials = awsCredentialsProvider.getCredentials();
                String username = awsCredentials.getAWSAccessKeyId();
                String password = awsCredentials.getAWSSecretKey();
                Credentials credentials;
                if (awsCredentials instanceof AWSSessionCredentials) {
                    AWSSessionCredentials awsSessionCredentials = (AWSSessionCredentials) awsCredentials;
                    credentials = SessionCredentials.builder().accessKeyId(username).secretAccessKey(password).sessionToken(awsSessionCredentials.getSessionToken()).build();
                } else {
                    credentials = new Credentials(username, password);
                }
                ComputeServiceContext jcloudsContext = ContextBuilder.newBuilder("aws-ec2").credentialsSupplier(Suppliers.ofInstance(credentials)).modules(ImmutableSet.<Module>of(new SLF4JLoggingModule(), new JschSshClientModule())).buildView(ComputeServiceContext.class);
                this.jcloudsComputeService = jcloudsContext.getComputeService();
            }
        }
    }
    return jcloudsComputeService;
}
Also used : SLF4JLoggingModule(org.jclouds.logging.slf4j.config.SLF4JLoggingModule) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) JschSshClientModule(org.jclouds.ssh.jsch.config.JschSshClientModule) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) Module(com.google.inject.Module) SLF4JLoggingModule(org.jclouds.logging.slf4j.config.SLF4JLoggingModule) JschSshClientModule(org.jclouds.ssh.jsch.config.JschSshClientModule) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) Credentials(org.jclouds.domain.Credentials) SessionCredentials(org.jclouds.aws.domain.SessionCredentials) LoginCredentials(org.jclouds.domain.LoginCredentials)

Example 2 with Credentials

use of org.jclouds.domain.Credentials in project whirr by apache.

the class CreateSitePpAndApplyRolesTest method testWithAttribs.

@Test
public void testWithAttribs() throws IOException {
    Configuration conf = new PropertiesConfiguration();
    conf.setProperty("puppet.nginx.module", "git://github.com/puppetlabs/puppetlabs-nginx.git");
    conf.setProperty("nginx.server.hostname", "foohost");
    CreateSitePpAndApplyRoles nginx = new CreateSitePpAndApplyRoles(ImmutableSet.of("nginx::server"), ImmutableSet.of(new Cluster.Instance(new Credentials("dummy", "dummy"), Sets.newHashSet("puppet:nginx::server"), "127.0.0.1", "127.0.0.1", "id-1", null)), conf);
    assertEquals(CharStreams.toString(Resources.newReaderSupplier(Resources.getResource("nginx-with-attribs.txt"), Charsets.UTF_8)), nginx.render(OsFamily.UNIX));
}
Also used : Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Credentials(org.jclouds.domain.Credentials) Test(org.junit.Test)

Example 3 with Credentials

use of org.jclouds.domain.Credentials in project whirr by apache.

the class FirewallManagerTest method setUpClass.

@Before
public void setUpClass() throws Exception {
    clusterSpec = getTestClusterSpec();
    context = ComputeCache.INSTANCE.apply(clusterSpec);
    /* create a dummy instance for testing */
    instances = Sets.newHashSet(new Cluster.Instance(new Credentials("dummy", "dummy"), Sets.newHashSet("dummy-role"), "50.0.0.1", "10.0.0.1", region + "/i-dummy", null));
    manager = new FirewallManager(context, clusterSpec, new Cluster(instances));
}
Also used : FirewallManager(org.apache.whirr.service.FirewallManager) Cluster(org.apache.whirr.Cluster) Credentials(org.jclouds.domain.Credentials) Before(org.junit.Before)

Example 4 with Credentials

use of org.jclouds.domain.Credentials in project whirr by apache.

the class TemplateUtilsTest method testProcessTemplate.

@Test
public void testProcessTemplate() throws Exception {
    Credentials credentials = new Credentials("dummy", "dummy");
    Cluster.Instance instance = new Cluster.Instance(credentials, Sets.newHashSet("foo"), "127.0.0.1", "127.0.0.1", "id-0", null);
    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(new PropertiesConfiguration("whirr-core-test.properties"));
    Cluster cluster = new Cluster(Sets.newHashSet(instance));
    VelocityEngine ve = TemplateUtils.newVelocityEngine();
    String result = TemplateUtils.processTemplate(ve, "template-test.txt.vm", clusterSpec, cluster);
    Assert.assertEquals("instance ip: 127.0.0.1", result);
}
Also used : VelocityEngine(org.apache.velocity.app.VelocityEngine) Cluster(org.apache.whirr.Cluster) ClusterSpec(org.apache.whirr.ClusterSpec) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Credentials(org.jclouds.domain.Credentials) Test(org.junit.Test)

Example 5 with Credentials

use of org.jclouds.domain.Credentials in project dhis2-core by dhis2.

the class JCloudsFileResourceContentStore method init.

// -------------------------------------------------------------------------
// Life cycle management
// -------------------------------------------------------------------------
@PostConstruct
public void init() {
    // ---------------------------------------------------------------------
    // Bootstrap config
    // ---------------------------------------------------------------------
    config = new BlobStoreProperties(configurationProvider.getProperty(ConfigurationKey.FILESTORE_PROVIDER), configurationProvider.getProperty(ConfigurationKey.FILESTORE_LOCATION), configurationProvider.getProperty(ConfigurationKey.FILESTORE_CONTAINER));
    Pair<Credentials, Properties> providerConfig = configureForProvider(config.provider, configurationProvider.getProperty(ConfigurationKey.FILESTORE_IDENTITY), configurationProvider.getProperty(ConfigurationKey.FILESTORE_SECRET));
    // ---------------------------------------------------------------------
    // Set up JClouds context
    // ---------------------------------------------------------------------
    blobStoreContext = ContextBuilder.newBuilder(config.provider).credentials(providerConfig.getLeft().identity, providerConfig.getLeft().credential).overrides(providerConfig.getRight()).build(BlobStoreContext.class);
    blobStore = blobStoreContext.getBlobStore();
    Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id(config.provider).description(config.provider).build();
    try {
        blobStore.createContainerInLocation(createRegionLocation(config, provider), config.container);
        log.info(String.format("File store configured with provider: '%s', container: '%s' and location: '%s'.", config.provider, config.container, config.location));
    } catch (HttpResponseException ex) {
        log.error(String.format("Could not configure file store with provider '%s' and container '%s'.\n" + "File storage will not be available.", config.provider, config.container), ex);
    } catch (AuthorizationException ex) {
        log.error(String.format("Could not authenticate with file store provider '%s' and container '%s'. " + "File storage will not be available.", config.provider, config.location), ex);
    }
}
Also used : LocationBuilder(org.jclouds.domain.LocationBuilder) AuthorizationException(org.jclouds.rest.AuthorizationException) HttpResponseException(org.jclouds.http.HttpResponseException) Credentials(org.jclouds.domain.Credentials) Location(org.jclouds.domain.Location) PostConstruct(javax.annotation.PostConstruct)

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