List of usage examples for com.amazonaws.auth BasicAWSCredentials BasicAWSCredentials
public BasicAWSCredentials(String accessKey, String secretKey)
From source file:com.readystatesoftware.simpl3r.example.UploadService.java
License:Apache License
@Override public void onCreate() { super.onCreate(); s3Client = new AmazonS3Client( new BasicAWSCredentials(getString(R.string.s3_access_key), getString(R.string.s3_secret))); nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); IntentFilter f = new IntentFilter(); f.addAction(UPLOAD_CANCELLED_ACTION); registerReceiver(uploadCancelReceiver, f); }
From source file:com.rorrell.personrest.data.DynamoDbConnector.java
private DynamoDbConnector() { BasicAWSCredentials cred = new BasicAWSCredentials("AKIAIBHWKCCV7G6N3MEA", "DVtEDwvUSS7xFVH4ATY0JohxhQLesJjD2V4i25kC"); AmazonDynamoDBClient client = new AmazonDynamoDBClient(cred); client.setEndpoint("dynamodb.us-west-2.amazonaws.com"); db = new DynamoDBMapper(client); }
From source file:com.scoyo.tools.s3cacheenhancer.cli.CLI.java
License:Apache License
private static S3HeaderEnhancer buildS3HeaderEnhancer(HeaderEnhancerArguments arguments) { AWSCredentials credentials = new BasicAWSCredentials(arguments.awsAccessKey, arguments.awsSecretKey); AmazonS3 s3 = new AmazonS3Client(credentials); S3HeaderEnhancer enhancer = new S3HeaderEnhancer(s3, arguments.bucketName, arguments.prefix); if (arguments.maxAge != null) { enhancer.setMaxAge(arguments.maxAge); }/*from w w w. jav a2 s . c o m*/ if (arguments.maxThreads != null) { enhancer.setMaxThreads(arguments.maxThreads.intValue()); } return enhancer; }
From source file:com.shareplaylearn.models.UserItemManager.java
License:Open Source License
public Response getItem(String contentType, ItemSchema.PresentationType presentationType, String name, String encoding) {/* w w w . j a v a2 s.c o m*/ if (encoding != null && encoding.length() > 0 && !AvailableEncodings.isAvailable(encoding)) { return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE) .entity("Inner Encoding Type: " + encoding + " not available").build(); } AmazonS3Client s3Client = new AmazonS3Client( new BasicAWSCredentials(SecretsService.amazonClientId, SecretsService.amazonClientSecret)); try { S3Object object = s3Client.getObject(ItemSchema.S3_BUCKET, getItemLocation(name, contentType, presentationType)); try (S3ObjectInputStream inputStream = object.getObjectContent()) { long contentLength = object.getObjectMetadata().getContentLength(); if (contentLength > Limits.MAX_RETRIEVE_SIZE) { throw new IOException("Object is to large: " + contentLength + " bytes."); } int bufferSize = Math.min((int) contentLength, 10 * 8192); byte[] buffer = new byte[bufferSize]; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); int bytesRead = 0; int totalBytesRead = 0; while ((bytesRead = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, bytesRead); totalBytesRead += bytesRead; } log.debug("GET in file resource read: " + totalBytesRead + " bytes."); if (encoding == null || encoding.length() == 0 || encoding.equals(AvailableEncodings.IDENTITY)) { return Response.status(Response.Status.OK).entity(outputStream.toByteArray()).build(); } else if (encoding.equals(AvailableEncodings.BASE64)) { return Response.status(Response.Status.OK) .entity(Base64.encodeAsString(outputStream.toByteArray())).build(); } else { return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE) .entity("Inner Encoding Type: " + encoding + " not available").build(); } } } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("\nFailed to retrieve: " + name); e.printStackTrace(pw); log.warn("Failed to retrieve: " + name); log.info(Exceptions.asString(e)); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(sw.toString()).build(); } }
From source file:com.shareplaylearn.models.UserItemManager.java
License:Open Source License
/** * Writes items to S3, and item metadata to Redis *//*w w w. ja va2s . c o m*/ private void saveItem(String name, byte[] itemData, String contentType, ItemSchema.PresentationType presentationType) throws InternalErrorException { String itemLocation = this.getItemLocation(name, contentType, presentationType); AmazonS3Client s3Client = new AmazonS3Client( new BasicAWSCredentials(SecretsService.amazonClientId, SecretsService.amazonClientSecret)); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(itemData); ObjectMetadata metadata = this.makeBasicMetadata(itemData.length, false, name); metadata.addUserMetadata(UploadMetadataFields.CONTENT_TYPE, contentType); //TODO: save this metadata, along with location, to local Redis s3Client.putObject(ItemSchema.S3_BUCKET, itemLocation, byteArrayInputStream, metadata); }
From source file:com.shareplaylearn.models.UserItemManager.java
License:Open Source License
public HashMap<String, HashMap<ItemSchema.PresentationType, List<String>>> getItemLocations() { HashMap<String, HashMap<ItemSchema.PresentationType, List<String>>> itemLocations = new HashMap<>(); AmazonS3Client s3Client = new AmazonS3Client( new BasicAWSCredentials(SecretsService.amazonClientId, SecretsService.amazonClientSecret)); for (String contentType : ItemSchema.CONTENT_TYPES) { for (ItemSchema.PresentationType presentationType : ItemSchema.PRESENTATION_TYPES) { ObjectListing listing = s3Client.listObjects(ItemSchema.S3_BUCKET, this.getItemDirectory(contentType, presentationType)); HashSet<String> locations = getExternalItemListing(listing); String curDirectory = makeExternalLocation(getItemDirectory(contentType, presentationType)); for (String location : locations) { //it would be nice if s3 didn't return stuff that doesn't technically match the prefix //(due to trailing /), but it looks like it might if (curDirectory.endsWith(location)) { log.debug("Skipping location: " + location + " because it looks like a group (folder)" + ", not an object"); continue; }/*from ww w .j ava 2 s .c om*/ if (!itemLocations.containsKey(contentType)) { itemLocations.put(contentType, new HashMap<>()); } if (!itemLocations.get(contentType).containsKey(presentationType)) { itemLocations.get(contentType).put(presentationType, new ArrayList<>()); } itemLocations.get(contentType).get(presentationType).add(location); } } } return itemLocations; }
From source file:com.shareplaylearn.models.UserItemManager.java
License:Open Source License
private Response checkQuota() { AmazonS3Client s3Client = new AmazonS3Client( new BasicAWSCredentials(SecretsService.amazonClientId, SecretsService.amazonClientSecret)); ObjectListing curList = s3Client.listObjects(ItemSchema.S3_BUCKET, this.getUserDir()); Response listCheck;/*from w w w. jav a 2 s. co m*/ if ((listCheck = this.checkObjectListingSize(curList, Limits.MAX_NUM_FILES_PER_USER)) .getStatus() != Response.Status.OK.getStatusCode()) { return listCheck; } ObjectListing userList = s3Client.listObjects(ItemSchema.S3_BUCKET, "/"); if ((listCheck = this.checkObjectListingSize(userList, Limits.MAX_TOTAL_FILES)) .getStatus() != Response.Status.OK.getStatusCode()) { return listCheck; } return Response.status(Response.Status.OK).build(); }
From source file:com.shazam.dataengineering.pipelinebuilder.PipelineBuilder.java
License:Apache License
@Override public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { FilePath ws = build.getWorkspace();/* ww w .ja va 2 s . c o m*/ FilePath input = ws.child(file); PipelineProcessor processor = new PipelineProcessor(build, launcher, listener); if (configParams.length > 0) { processor.setEnvironments(configParams); } else { listener.getLogger().println("[WARN] No environments for AWS Data pipeline defined, skipping"); return true; } processor.setS3Prefix(s3Prefix); boolean result = processor.process(input); if (result) { build.addAction(new DeploymentAction(build, processor.getS3Urls(), new BasicAWSCredentials(getDescriptor().getAccessId(), getDescriptor().getSecretKey()))); } return result; }
From source file:com.sitewhere.aws.SqsOutboundEventProcessor.java
License:Open Source License
@Override public void start() throws SiteWhereException { super.start(); ClientConfiguration config = new ClientConfiguration(); config.setMaxConnections(250);/*from w ww . j a v a2 s . c o m*/ config.setMaxErrorRetry(5); if (getAccessKey() == null) { throw new SiteWhereException("Amazon access key not provided."); } if (getSecretKey() == null) { throw new SiteWhereException("Amazon secret key not provided."); } sqs = new AmazonSQSClient(new BasicAWSCredentials(getAccessKey(), getSecretKey()), config); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sqs.setRegion(usEast1); }
From source file:com.sitewhere.connectors.aws.sqs.SqsOutboundEventProcessor.java
License:Open Source License
@Override public void start(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.start(monitor); ClientConfiguration config = new ClientConfiguration(); config.setMaxConnections(250);/*from w ww . j a v a2 s. c om*/ config.setMaxErrorRetry(5); if (getAccessKey() == null) { throw new SiteWhereException("Amazon access key not provided."); } if (getSecretKey() == null) { throw new SiteWhereException("Amazon secret key not provided."); } sqs = new AmazonSQSClient(new BasicAWSCredentials(getAccessKey(), getSecretKey()), config); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sqs.setRegion(usEast1); }