Example usage for com.amazonaws SDKGlobalConfiguration SECRET_KEY_ENV_VAR

List of usage examples for com.amazonaws SDKGlobalConfiguration SECRET_KEY_ENV_VAR

Introduction

In this page you can find the example usage for com.amazonaws SDKGlobalConfiguration SECRET_KEY_ENV_VAR.

Prototype

String SECRET_KEY_ENV_VAR

To view the source code for com.amazonaws SDKGlobalConfiguration SECRET_KEY_ENV_VAR.

Click Source Link

Document

Environment variable name for the AWS secret key

Usage

From source file:org.apache.usergrid.persistence.queue.impl.UsergridAwsCredentials.java

License:Apache License

public String getAWSSecretKeyJson(Map<String, Object> jsonObject) {
    String secretKey = (String) jsonObject.get(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR);
    if (StringUtils.isEmpty(secretKey)) {
        secretKey = (String) jsonObject.get(SDKGlobalConfiguration.ALTERNATE_SECRET_KEY_ENV_VAR);
    }// w  ww .j a  v  a 2s .  c  o m
    if (StringUtils.isEmpty(secretKey)) {
        throw new AmazonClientException("Could not get aws secret key from json object.");
    }
    return StringUtils.trim(secretKey);
}

From source file:org.apache.usergrid.rest.applications.assets.aws.NoAWSCredsRule.java

License:Apache License

public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override/* w w  w .  j  a v  a  2 s  . c  o m*/
        public void evaluate() throws Throwable {
            String accessId;
            String secretKey;
            String bucketName;
            try {
                Map<String, Object> properties = getRemoteTestProperties();
                //TODO: GREY change this so that it checks for the properties, then if it doesn't have them, mark the tests as ignored.
                accessId = (String) System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR);
                secretKey = (String) System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR);
                bucketName = (String) properties.get("usergrid.binary.bucketname");

                if (accessId == null || secretKey == null || bucketName == null) {
                    throw new AwsPropertiesNotFoundException("Access Keys");
                }
                base.evaluate();

            } catch (Throwable t) {

                if (!isMissingCredsException(t)) {
                    throw t;
                }

                //do this so our test gets marked as ignored.  Not pretty, but it works
                Assume.assumeTrue(false);

            }
        }
    };
}

From source file:org.apache.usergrid.rest.applications.assets.AwsAssetResourceIT.java

License:Apache License

@Test
public void errorCheckingInvalidProperties() throws Exception {
    Map<String, Object> errorTestProperties;
    errorTestProperties = getRemoteTestProperties();
    //test that we fail gracefully if we have missing properties
    setTestProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR, "xxx");
    setTestProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, "xxx");
    setTestProperty("usergrid.binary.bucketname", "xxx");

    try {//from  ww w  .j a va2  s. co m

        Map<String, String> payload = hashMap("name", "assetname");
        ApiResponse postResponse = pathResource(getOrgAppPath("foos")).post(payload);
        UUID assetId = postResponse.getEntities().get(0).getUuid();
        assertNotNull(assetId);

        // post a binary asset to that entity

        byte[] data = IOUtils.toByteArray(getClass().getResourceAsStream("/cassandra_eye.jpg"));
        ApiResponse putResponse = pathResource(getOrgAppPath("foos/" + assetId)).put(data,
                MediaType.APPLICATION_OCTET_STREAM_TYPE);

    } catch (AwsPropertiesNotFoundException e) {
        fail("Shouldn't interrupt runtime if access key isnt found.");
    } catch (InternalServerErrorException uie) {
        assertEquals(500, uie.getResponse().getStatus());
    } finally {
        setTestProperties(errorTestProperties);
    }
}

From source file:org.apache.usergrid.rest.applications.assets.AwsAssetResourceIT.java

License:Apache License

@Test
public void errorCheckingInvalidPropertiesMultipartUpload() throws Exception {
    Map<String, Object> errorTestProperties;
    errorTestProperties = getRemoteTestProperties();
    //test that we fail gracefully if we have missing properties
    setTestProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR, "xxx");
    setTestProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, "xxx");
    setTestProperty("usergrid.binary.bucketname", "xxx");

    try {//from  w w  w  .jav  a 2  s  .c  o m

        byte[] data = IOUtils.toByteArray(this.getClass().getResourceAsStream("/file-bigger-than-5M"));
        FormDataMultiPart form = new FormDataMultiPart().field("file", data,
                MediaType.MULTIPART_FORM_DATA_TYPE);
        ApiResponse postResponse = pathResource(getOrgAppPath("foos")).post(form);
        UUID assetId = postResponse.getEntities().get(0).getUuid();
        logger.info("Waiting for upload to finish...");
        Thread.sleep(5000);

        // check that entire file was uploaded

        ApiResponse getResponse = pathResource(getOrgAppPath("foos/" + assetId)).get(ApiResponse.class);
        logger.info("Upload complete!");
        InputStream is = pathResource(getOrgAppPath("foos/" + assetId)).getAssetAsStream();
        byte[] foundData = IOUtils.toByteArray(is);
        assertEquals(data.length, foundData.length);

        // delete file

        pathResource(getOrgAppPath("foos/" + assetId)).delete();

    } catch (AwsPropertiesNotFoundException e) {
        fail("Shouldn't interrupt runtime if access key isnt found.");
    } catch (ForbiddenException fe) {
        assertEquals(403, fe.getResponse().getStatus());
    } finally {
        setTestProperties(errorTestProperties);
    }
}

From source file:org.apache.usergrid.rest.applications.assets.rules.NoAWSCredsRule.java

License:Apache License

public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override//from   w w  w.j av  a 2 s.  c  o m
        public void evaluate() throws Throwable {

            try {

                final Map<String, Object> properties = getRemoteTestProperties();
                final String bucketName = (String) properties.get("usergrid.binary.bucketname");

                //TODO: GREY change this so that it checks for the properties, then if it doesn't have them, mark the tests as ignored.
                final String accessId = System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR);
                final String secretKey = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR);

                if (accessId == null || secretKey == null || bucketName == null) {
                    throw new AwsPropertiesNotFoundException("Access Keys");
                }

                base.evaluate();

            } catch (Throwable t) {

                if (!isMissingCredsException(t)) {
                    throw t;
                }

                //do this so our test gets marked as ignored.  Not pretty, but it works
                Assume.assumeTrue(false);

            }
        }
    };
}

From source file:org.apache.usergrid.rest.management.ImportResourceIT.java

License:Apache License

@Before
public void before() {
    configured = !StringUtils.isEmpty(System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR))
            && !StringUtils.isEmpty(System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR))
            && !StringUtils.isEmpty(System.getProperty("bucketName"));

    if (!configured) {
        logger.warn(/*from w  w  w  .  j  a v a  2s .c om*/
                "Skipping test because {}, {} and bucketName not "
                        + "specified as system properties, e.g. in your Maven settings.xml file.",
                new Object[] { "s3_key", "s3_access_id" });
    }

    //        if (!StringUtils.isEmpty(bucketPrefix)) {
    //            deleteBucketsWithPrefix();
    //        }

    bucketName = bucketPrefix + RandomStringUtils.randomAlphanumeric(10).toLowerCase();
}

From source file:org.apache.usergrid.rest.management.ImportResourceIT.java

License:Apache License

/**
 * TODO: Test that importing bad JSON will result in an informative error message.
 *///from  ww  w.j  a  v  a2s  .  c  o m
@Test
public void testImportGoodJson() throws Exception {
    // import from a bad JSON file
    Assume.assumeTrue(configured);

    String org = clientSetup.getOrganizationName();
    String app = clientSetup.getAppName();

    String basePath = System.getProperty("target.directory") + File.separator + "test-classes" + File.separator;

    List<String> filenames = new ArrayList<>(1);
    filenames.add(basePath + "testimport-correct-testcol.1.json");

    // create 10 applications each with collection of 10 things, export all to S3
    S3Upload s3Upload = new S3Upload();
    s3Upload.copyToS3(System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR),
            System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR), bucketName, filenames);

    // import all those exports from S3 into the default test application

    Entity importEntity = importCollection();

    Entity importGet = this.management().orgs().org(org).app().addToPath(app).addToPath("imports")
            .addToPath(importEntity.getUuid().toString()).get();

    refreshIndex();

    Entity importGetIncludes = this.management().orgs().org(org).app().addToPath(app).addToPath("imports")
            .addToPath(importEntity.getUuid().toString()).addToPath("files").get();

    ApiResponse importGetIncludesResponse = importGetIncludes.getResponse();

    assertNotNull(importGet);
    assertNotNull(importGetIncludes);
    assertEquals(1, importGetIncludesResponse.getEntityCount());

    final Entity includesEntity = importGetIncludesResponse.getEntities().get(0);

    assertTrue(includesEntity.getAsString("fileName").endsWith("testimport-correct-testcol.1.json"));

    assertEquals(1, includesEntity.get("importedConnectionCount"));
    assertEquals(1, includesEntity.get("importedEntityCount"));

    assertEquals("FINISHED", importGet.get("state"));
    assertEquals(1, importGet.get("fileCount"));

    Collection collection = this.app().collection("things").get();

    assertNotNull(collection);
    assertEquals(1, collection.getNumOfEntities());
    assertEquals("thing0", collection.getResponse().getEntities().get(0).get("name"));

    //TODO: make sure it checks the actual imported entities. And the progress they have made.

}

From source file:org.apache.usergrid.rest.management.ImportResourceIT.java

License:Apache License

/**
 * TODO: Test that importing bad JSON will result in an informative error message.
 *///from  ww w  . j av a2  s .  co  m
@Test
public void testImportOneGoodOneBad() throws Exception {

    // import from a bad JSON file
    Assume.assumeTrue(configured);

    String org = clientSetup.getOrganizationName();
    String app = clientSetup.getAppName();

    String basePath = System.getProperty("target.directory") + File.separator + "test-classes" + File.separator;

    List<String> filenames = new ArrayList<>(2);
    filenames.add(basePath + "testimport-correct-testcol.1.json");
    filenames.add(basePath + "testImport.testApplication.2.json");

    // create 10 applications each with collection of 10 things, export all to S3
    S3Upload s3Upload = new S3Upload();
    s3Upload.copyToS3(System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR),
            System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR), bucketName, filenames);

    // import all those exports from S3 into the default test application

    Entity importEntity = importCollection();

    Entity importGet = this.management().orgs().org(org).app().addToPath(app).addToPath("imports")
            .addToPath(importEntity.getUuid().toString()).get();

    assertNotNull(importGet);

    assertEquals("FAILED", importGet.get("state"));
    assertEquals(2, importGet.get("fileCount"));

    Collection collection = this.app().collection("things").get();

    assertNotNull(collection);
    assertEquals(1, collection.getNumOfEntities());
    assertEquals("thing0", collection.getResponse().getEntities().get(0).get("name"));
}

From source file:org.apache.usergrid.rest.management.ImportResourceIT.java

License:Apache License

/**
 * TODO: Test that importing bad JSON will result in an informative error message.
 *//*from  w w  w .j av a  2s  . c  o  m*/
@Test
public void testImportOneBadFile() throws Exception {
    // import from a bad JSON file
    Assume.assumeTrue(configured);

    String org = clientSetup.getOrganizationName();
    String app = clientSetup.getAppName();

    String basePath = System.getProperty("target.directory") + File.separator + "test-classes" + File.separator;

    List<String> filenames = new ArrayList<>(1);
    filenames.add(basePath + "testimport-bad-json.json");

    // create 10 applications each with collection of 10 things, export all to S3
    S3Upload s3Upload = new S3Upload();
    s3Upload.copyToS3(System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR),
            System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR), bucketName, filenames);

    // import all those exports from S3 into the default test application

    Entity importEntity = importCollection();

    Entity importGet = this.management().orgs().org(org).app().addToPath(app).addToPath("imports")
            .addToPath(importEntity.getUuid().toString()).get();

    assertNotNull(importGet);

    assertEquals("FAILED", importGet.get("state"));
    assertEquals(1, importGet.get("fileCount"));

    Collection collection = this.app().collection("things").get();

    assertNotNull(collection);
    assertEquals(0, collection.getNumOfEntities());

}

From source file:org.apache.usergrid.rest.management.ImportResourceIT.java

License:Apache License

/**
 * TODO: Test that importing bad JSON will result in an informative error message.
 *//*  w  w  w .jav  a  2 s. co  m*/
@Test
public void testImportBadJson() throws Exception {

    // import from a bad JSON file
    Assume.assumeTrue(configured);

    String org = clientSetup.getOrganizationName();
    String app = clientSetup.getAppName();

    String basePath = System.getProperty("target.directory") + File.separator + "test-classes" + File.separator;

    List<String> filenames = new ArrayList<>(1);
    filenames.add(basePath + "testimport-bad-json-testapp.3.json");

    // create 10 applications each with collection of 10 things, export all to S3
    S3Upload s3Upload = new S3Upload();
    s3Upload.copyToS3(System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR),
            System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR), bucketName, filenames);

    // import all those exports from S3 into the default test application

    Entity importEntity = importCollection();

    // we should now have 100 Entities in the default app

    Entity importGet = this.management().orgs().org(org).app().addToPath(app).addToPath("imports")
            .addToPath(importEntity.getUuid().toString()).get();

    Entity importGetIncludes = this.management().orgs().org(org).app().addToPath(app).addToPath("imports")
            .addToPath(importEntity.getUuid().toString()).addToPath("files").get();

    assertNotNull(importGet);

    //TODO: needs better error checking
    assertNotNull(importGetIncludes);

    // check that error message indicates JSON parsing error
}