List of usage examples for com.amazonaws SDKGlobalConfiguration SECRET_KEY_ENV_VAR
String SECRET_KEY_ENV_VAR
To view the source code for com.amazonaws SDKGlobalConfiguration SECRET_KEY_ENV_VAR.
Click Source Link
From source file:com.kirana.utils.GeneratePresignedUrlAndUploadObject.java
public static void main(String[] args) throws IOException { System.setProperty(SDKGlobalConfiguration.ENABLE_S3_SIGV4_SYSTEM_PROPERTY, "true"); System.setProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR, "AKIAJ666LALJZHA6THGQ"); System.setProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, "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"); // AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider("kirana")); ProfilesConfigFile profile = new ProfilesConfigFile("AwsCredentials.properties"); AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider()); s3client.setRegion(Region.getRegion(Regions.AP_SOUTHEAST_1)); try {/* ww w. java2 s .c o m*/ System.out.println("Generating pre-signed URL."); java.util.Date expiration = new java.util.Date(); long milliSeconds = expiration.getTime(); milliSeconds += 1000 * 60 * 60; // Add 1 hour. expiration.setTime(milliSeconds); GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, objectKey); generatePresignedUrlRequest.setMethod(HttpMethod.PUT); generatePresignedUrlRequest.setExpiration(expiration); // s3client.putObject(bucketName, objectKey, null); URL url = s3client.generatePresignedUrl(generatePresignedUrlRequest); UploadObject(url); System.out.println("Pre-Signed URL = " + url.toString()); } catch (AmazonServiceException exception) { System.out.println("Caught an AmazonServiceException, " + "which means your request made it " + "to Amazon S3, but was rejected with an error response " + "for some reason."); System.out.println("Error Message: " + exception.getMessage()); System.out.println("HTTP Code: " + exception.getStatusCode()); System.out.println("AWS Error Code:" + exception.getErrorCode()); System.out.println("Error Type: " + exception.getErrorType()); System.out.println("Request ID: " + exception.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, " + "which means the client encountered " + "an internal error while trying to communicate" + " with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:org.apache.usergrid.management.export.ExportServiceIT.java
License:Apache License
@Before public void before() { boolean 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(// ww w.jav a 2 s. co m "Skipping test because {}, {} and bucketName not " + "specified as system properties, e.g. in your Maven settings.xml file.", new Object[] { SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR }); } Assume.assumeTrue(configured); adminUser = newOrgAppAdminRule.getAdminInfo(); organization = newOrgAppAdminRule.getOrganizationInfo(); applicationId = newOrgAppAdminRule.getApplicationInfo().getId(); bucketPrefix = System.getProperty("bucketName"); bucketName = bucketPrefix + RandomStringUtils.randomAlphanumeric(10).toLowerCase(); }
From source file:org.apache.usergrid.management.export.ExportServiceIT.java
License:Apache License
@Test @Ignore("Pending merge of export-feature branch") public void testIntegration100EntitiesOn() throws Exception { if (logger.isDebugEnabled()) { logger.debug("testIntegration100EntitiesOn(): starting..."); }//w ww.ja va 2s .c om ExportService exportService = setup.getExportService(); String appName = newOrgAppAdminRule.getApplicationInfo().getName(); HashMap<String, Object> payload = payloadBuilder(appName); payload.put("organizationId", organization.getUuid()); payload.put("applicationId", applicationId); // create five applications each with collection of five entities for (int i = 0; i < 5; i++) { ApplicationInfo appMade = setup.getMgmtSvc().createApplication(organization.getUuid(), "superapp" + i); EntityManager appEm = setup.getEmf().getEntityManager(appMade.getId()); String collName = "superappCol" + i; appEm.createApplicationCollection(collName); Map<String, Object> entityLevelProperties = null; Entity[] entNotCopied; entNotCopied = new Entity[5]; for (int index = 0; index < 5; index++) { entityLevelProperties = new LinkedHashMap<String, Object>(); entityLevelProperties.put("username", "bobso" + index); entityLevelProperties.put("email", "derp" + index + "@anuff.com"); entNotCopied[index] = appEm.create(collName, entityLevelProperties); } } // export the organization containing those apps and collections UUID exportUUID = exportService.schedule(payload); int maxRetries = 100; int retries = 0; while (!exportService.getState(exportUUID).equals("FINISHED") && retries++ < maxRetries) { Thread.sleep(100); } String accessId = System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR); String secretKey = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR); Properties overrides = new Properties(); overrides.setProperty("s3" + ".identity", accessId); overrides.setProperty("s3" + ".credential", secretKey); // test that we can find the file that were exported to S3 BlobStore blobStore = null; try { final Iterable<? extends Module> MODULES = ImmutableSet.of( new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(), new NettyPayloadModule()); BlobStoreContext context = ContextBuilder.newBuilder("s3").credentials(accessId, secretKey) .modules(MODULES).overrides(overrides).buildView(BlobStoreContext.class); String expectedFileName = ((ExportServiceImpl) exportService) .prepareOutputFileName(organization.getName(), "applications"); blobStore = context.getBlobStore(); if (!blobStore.blobExists(bucketName, expectedFileName)) { blobStore.deleteContainer(bucketName); Assert.fail("Blob does not exist: " + expectedFileName); } Blob bo = blobStore.getBlob(bucketName, expectedFileName); Long numOfFiles = blobStore.countBlobs(bucketName); Long numWeWant = 1L; blobStore.deleteContainer(bucketName); assertEquals(numOfFiles, numWeWant); assertNotNull(bo); } finally { blobStore.deleteContainer(bucketName); } }
From source file:org.apache.usergrid.management.export.ExportServiceIT.java
License:Apache License
@Test @Ignore("Pending merge of export-feature branch") public void testIntegration100EntitiesForAllApps() throws Exception { S3Export s3Export = new S3ExportImpl(); ExportService exportService = setup.getExportService(); String appName = newOrgAppAdminRule.getApplicationInfo().getName(); HashMap<String, Object> payload = payloadBuilder(appName); OrganizationInfo orgMade = null;/*from ww w . java 2 s .co m*/ ApplicationInfo appMade = null; for (int i = 0; i < 5; i++) { orgMade = setup.getMgmtSvc().createOrganization("minorboss" + i, adminUser, true); for (int j = 0; j < 5; j++) { appMade = setup.getMgmtSvc().createApplication(orgMade.getUuid(), "superapp" + j); EntityManager customMaker = setup.getEmf().getEntityManager(appMade.getId()); customMaker.createApplicationCollection("superappCol" + j); //intialize user object to be posted Map<String, Object> entityLevelProperties = null; Entity[] entNotCopied; entNotCopied = new Entity[1]; //creates entities for (int index = 0; index < 1; index++) { entityLevelProperties = new LinkedHashMap<String, Object>(); entityLevelProperties.put("derp", "bacon"); entNotCopied[index] = customMaker.create("superappCol" + j, entityLevelProperties); } } } payload.put("organizationId", orgMade.getUuid()); UUID exportUUID = exportService.schedule(payload); assertNotNull(exportUUID); Thread.sleep(3000); String accessId = System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR); String secretKey = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR); Properties overrides = new Properties(); overrides.setProperty("s3" + ".identity", accessId); overrides.setProperty("s3" + ".credential", secretKey); BlobStore blobStore = null; try { final Iterable<? extends Module> MODULES = ImmutableSet.of( new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(), new NettyPayloadModule()); BlobStoreContext context = ContextBuilder.newBuilder("s3").credentials(accessId, secretKey) .modules(MODULES).overrides(overrides).buildView(BlobStoreContext.class); blobStore = context.getBlobStore(); //Grab Number of files Long numOfFiles = blobStore.countBlobs(bucketName); String expectedFileName = ((ExportServiceImpl) exportService) .prepareOutputFileName(organization.getName(), "applications"); //delete container containing said files Blob bo = blobStore.getBlob(bucketName, expectedFileName); Long numWeWant = 5L; blobStore.deleteContainer(bucketName); //asserts that the correct number of files was transferred over assertEquals(numWeWant, numOfFiles); } finally { blobStore.deleteContainer(bucketName); } }
From source file:org.apache.usergrid.management.export.ExportServiceIT.java
License:Apache License
@Test @Ignore("Pending merge of export-feature branch") public void testIntegration100EntitiesOnOneOrg() throws Exception { S3Export s3Export = new S3ExportImpl(); ExportService exportService = setup.getExportService(); String appName = newOrgAppAdminRule.getApplicationInfo().getName(); HashMap<String, Object> payload = payloadBuilder(appName); payload.put("organizationId", organization.getUuid()); payload.put("applicationId", applicationId); OrganizationInfo orgMade = null;//from w ww . j av a2 s . c o m ApplicationInfo appMade = null; for (int i = 0; i < 100; i++) { orgMade = setup.getMgmtSvc().createOrganization("largerboss" + i, adminUser, true); appMade = setup.getMgmtSvc().createApplication(orgMade.getUuid(), "superapp" + i); EntityManager customMaker = setup.getEmf().getEntityManager(appMade.getId()); customMaker.createApplicationCollection("superappCol" + i); //intialize user object to be posted Map<String, Object> entityLevelProperties = null; Entity[] entNotCopied; entNotCopied = new Entity[20]; //creates entities for (int index = 0; index < 20; index++) { entityLevelProperties = new LinkedHashMap<String, Object>(); entityLevelProperties.put("username", "bobso" + index); entityLevelProperties.put("email", "derp" + index + "@anuff.com"); entNotCopied[index] = customMaker.create("superappCol", entityLevelProperties); } } EntityManager em = setup.getEmf().getEntityManager(applicationId); //intialize user object to be posted Map<String, Object> userProperties = null; Entity[] entity; entity = new Entity[100]; //creates entities for (int i = 0; i < 100; i++) { userProperties = new LinkedHashMap<String, Object>(); userProperties.put("username", "bido" + i); userProperties.put("email", "bido" + i + "@anuff.com"); entity[i] = em.create("user", userProperties); } UUID exportUUID = exportService.schedule(payload); while (!exportService.getState(exportUUID).equals("FINISHED")) { } String accessId = System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR); String secretKey = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR); Properties overrides = new Properties(); overrides.setProperty("s3" + ".identity", accessId); overrides.setProperty("s3" + ".credential", secretKey); Blob bo = null; BlobStore blobStore = null; try { final Iterable<? extends Module> MODULES = ImmutableSet.of( new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(), new NettyPayloadModule()); BlobStoreContext context = ContextBuilder.newBuilder("s3").credentials(accessId, secretKey) .modules(MODULES).overrides(overrides).buildView(BlobStoreContext.class); String expectedFileName = ((ExportServiceImpl) exportService) .prepareOutputFileName(organization.getName(), "applications"); blobStore = context.getBlobStore(); if (!blobStore.blobExists(bucketName, expectedFileName)) { assert (false); } Long numOfFiles = blobStore.countBlobs(bucketName); Long numWeWant = Long.valueOf(1); assertEquals(numOfFiles, numWeWant); bo = blobStore.getBlob(bucketName, expectedFileName); } catch (Exception e) { assert (false); } assertNotNull(bo); blobStore.deleteContainer(bucketName); }
From source file:org.apache.usergrid.management.export.ExportServiceIT.java
License:Apache License
public HashMap<String, Object> payloadBuilder(String orgOrAppName) { HashMap<String, Object> payload = new HashMap<String, Object>(); Map<String, Object> properties = new HashMap<String, Object>(); Map<String, Object> storage_info = new HashMap<String, Object>(); storage_info.put(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR)); storage_info.put(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR, System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR)); storage_info.put("bucket_location", bucketName); properties.put("storage_provider", "s3"); properties.put("storage_info", storage_info); payload.put("path", orgOrAppName); payload.put("properties", properties); return payload; }
From source file:org.apache.usergrid.management.importer.ImportServiceIT.java
License:Apache License
@Before public void before() { boolean 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 www .j a v a 2 s . co m "Skipping test because {}, {} and bucketName not " + "specified as system properties, e.g. in your Maven settings.xml file.", new Object[] { SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR }); } Assume.assumeTrue(configured); }
From source file:org.apache.usergrid.management.importer.ImportServiceIT.java
License:Apache License
public HashMap<String, Object> payloadBuilder() { HashMap<String, Object> payload = new HashMap<String, Object>(); Map<String, Object> properties = new HashMap<String, Object>(); Map<String, Object> storage_info = new HashMap<String, Object>(); storage_info.put("bucket_location", bucketName); storage_info.put(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR)); storage_info.put(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR, System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR)); properties.put("storage_provider", "s3"); properties.put("storage_info", storage_info); payload.put("path", "test-organization/test-app"); payload.put("properties", properties); return payload; }
From source file:org.apache.usergrid.management.importer.ImportServiceIT.java
License:Apache License
public void deleteBucket() { String accessId = System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR); String secretKey = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR); Properties overrides = new Properties(); overrides.setProperty("s3" + ".identity", accessId); overrides.setProperty("s3" + ".credential", secretKey); Blob bo = null;/*from ww w. j a v a 2s. com*/ BlobStore blobStore = null; final Iterable<? extends Module> MODULES = ImmutableSet.of(new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(), new NettyPayloadModule()); BlobStoreContext context = ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES) .overrides(overrides).buildView(BlobStoreContext.class); blobStore = context.getBlobStore(); blobStore.deleteContainer(bucketName); }
From source file:org.apache.usergrid.persistence.queue.impl.UsergridAwsCredentials.java
License:Apache License
@Override public String getAWSSecretKey() { String secret = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR); if (StringUtils.isEmpty(secret)) { secret = System.getProperty(SDKGlobalConfiguration.ALTERNATE_SECRET_KEY_ENV_VAR); }/* w w w. j a v a 2s . c om*/ return StringUtils.trim(secret); }