static { final BasicAWSCredentials credentials = new BasicAWSCredentials( AppGlobals.USER_NAME, AppGlobals.PASSWORD); s3 = new AmazonS3Client(credentials); s3.setRegion(Region.getRegion(Regions.AP_SOUTHEAST_1)); s3.setEndpoint("s3-ap-southeast-1.amazonaws.com"); }
public void processArgs(final String[] args) { final AmazonS3 s3 = setup(args, 1, "bucketName"); final String bucketName = args[0]; try { s3.createBucket(bucketName); } catch (final IOException e) { System.out.println("There was an error creating the bucket."); e.printStackTrace(); } }
public void processArgs(final String[] args) { final AmazonS3 s3 = setup(args, 2, "bucketName name where name is has a '*' prefix or suffix, or both"); final String bucketName = args[0]; final String regEx = args[1]; try { s3.deleteStar(bucketName, regEx); } catch (final IOException e) { System.out.println("Could not delete regex: " + regEx); e.printStackTrace(); } }
@Override public void createContainer(String container, Config config) { super.createContainer(container, config); try { if (!client.doesBucketExist(container)) { client.createBucket(container); } } catch (Exception e) { throw new StorageException(e); } }
public void processArgs(final String[] args) { final AmazonS3 s3 = setup(args, 2, "bucketName fileName"); final String bucketName = args[0]; final String fileName = args[1]; final File target = new File(fileName); try { s3.getPrivateFile(bucketName, fileName, target); } catch (final IOException e) { System.out.println("There was an error getting the file."); e.printStackTrace(); System.exit(1); } }
@Override public void deleteContainer(String container, Config config) { super.deleteContainer(container, config); try { if (client.doesBucketExist(container)) { client.deleteBucket(container); } } catch (AmazonS3Exception awse) { if (awse.getStatusCode() != HttpStatus.SC_NOT_FOUND) { throw new StorageException(awse); } } catch (Exception e) { throw new StorageException(e); } }
TransportAmazonS3(final Repository local, final URIish uri) throws NotSupportedException { super(local, uri); Properties props = null; File propsFile = new File(local.getDirectory(), uri.getUser()); if (!propsFile.isFile()) propsFile = new File(FS.userHome(), uri.getUser()); if (propsFile.isFile()) { try { props = AmazonS3.properties(propsFile); } catch (IOException e) { throw new NotSupportedException("cannot read " + propsFile, e); } } else { props = new Properties(); props.setProperty("accesskey", uri.getUser()); props.setProperty("secretkey", uri.getPass()); } s3 = new AmazonS3(props); bucket = uri.getHost(); String p = uri.getPath(); if (p.startsWith("/")) p = p.substring(1); if (p.endsWith("/")) p = p.substring(0, p.length() - 1); keyPrefix = p; }
public void processArgs(final String[] args) { final AmazonS3 s3 = setup(args, 2, "bucketName directoryPath"); final String bucketName = args[0]; final File dir = new File(args[1]); if (!dir.isDirectory()) { System.out.println(dir + " does not appear to be a valid directory."); return; } try { s3.putPublicDir(bucketName, dir); } catch (IOException e) { System.out.println("Could not put all files."); e.printStackTrace(); } }
public void processArgs(final String[] args) { final AmazonS3 s3 = setup(args, 2, "bucketName fileName"); final String bucketName = args[0]; createBucket(bucketName, s3); final String fileString = args[1]; final File file = new File(fileString); if (!file.isFile()) { System.out.println("File not found: " + fileString); return; } try { s3.putPublicFile(bucketName, file); } catch (final IOException e) { System.out.println("Could not upload file. Error was: "); e.printStackTrace(); System.exit(1); } }
@Override public void init(Config config, Logger logger) { super.init(config, logger); timeout = config.getInt(CONN_TIMEOUT_KEY, CONN_TIMEOUT_DEFAULT); parms.put(CONN_TIMEOUT_KEY, timeout); endpoint = config.get(ENDPOINT_KEY, ENDPOINT_DEFAULT); accessKey = config.get(AUTH_USERNAME_KEY, AUTH_USERNAME_DEFAULT); secretKey = config.get(AUTH_PASSWORD_KEY, AUTH_PASSWORD_DEFAULT); boolean pathStyleAccess = config.getBoolean(PATH_STYLE_ACCESS_KEY, PATH_STYLE_ACCESS_DEFAULT); String proxyHost = config.get(PROXY_HOST_KEY, ""); String proxyPort = config.get(PROXY_PORT_KEY, ""); parms.put(ENDPOINT_KEY, endpoint); parms.put(AUTH_USERNAME_KEY, accessKey); parms.put(AUTH_PASSWORD_KEY, secretKey); parms.put(PATH_STYLE_ACCESS_KEY, pathStyleAccess); parms.put(PROXY_HOST_KEY, proxyHost); parms.put(PROXY_PORT_KEY, proxyPort); logger.debug("using storage config: {}", parms); ClientConfiguration clientConf = new ClientConfiguration(); clientConf.setConnectionTimeout(timeout); clientConf.setSocketTimeout(timeout); clientConf.withUseExpectContinue(false); clientConf.withSignerOverride("S3SignerType"); // clientConf.setProtocol(Protocol.HTTP); if ((!proxyHost.equals("")) && (!proxyPort.equals(""))) { clientConf.setProxyHost(proxyHost); clientConf.setProxyPort(Integer.parseInt(proxyPort)); } AWSCredentials myCredentials = new BasicAWSCredentials(accessKey, secretKey); client = new AmazonS3Client(myCredentials, clientConf); client.setEndpoint(endpoint); client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(pathStyleAccess)); logger.debug("S3 client has been initialized"); }
public void processArgs(final String[] args) { final AmazonS3 s3 = setup(args, 0, "bucketName"); if (args.length == 0) { try { s3.listBuckets(); } catch (final IOException e) { System.out.println("There was an error listing the bucket."); e.printStackTrace(); } } else { final String bucketName = args[0]; try { s3.listBucket(bucketName); } catch (final IOException e) { System.out.println("There was an error listing the bucket."); e.printStackTrace(); } } }
@Override public void deleteObject(String container, String object, Config config) { super.deleteObject(container, object, config); try { client.deleteObject(container, object); } catch (AmazonS3Exception awse) { if (awse.getStatusCode() != HttpStatus.SC_NOT_FOUND) { throw new StorageException(awse); } } catch (Exception e) { throw new StorageException(e); } }
@Override public InputStream getObject(String container, String object, Config config) { super.getObject(container, object, config); InputStream stream; try { S3Object s3Obj = client.getObject(container, object); stream = s3Obj.getObjectContent(); } catch (Exception e) { throw new StorageException(e); } return stream; }
@Override public void createObject( String container, String object, InputStream data, long length, Config config) { super.createObject(container, object, data, length, config); try { ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(length); metadata.setContentType("application/octet-stream"); client.putObject(container, object, data, metadata); } catch (Exception e) { throw new StorageException(e); } }
private static void deleteBucket(final String bucketName, final AmazonS3 s3) { final Preferences prefs = Preferences.userRoot(); final String createdBuckets = prefs.get(BUCKETS_KEY, ""); try { s3.deleteBucket(bucketName); if (createdBuckets.contains("," + bucketName + ",")) { prefs.put(BUCKETS_KEY, createdBuckets.replace("," + bucketName + ",", ",")); } else if (createdBuckets.endsWith("," + bucketName)) { final String strippedBuckets = StringUtils.substringBeforeLast(createdBuckets, "," + bucketName); prefs.put(BUCKETS_KEY, strippedBuckets); } } catch (final IOException e) { System.out.println("Could not delete bucket."); e.printStackTrace(); } }
private static void createBucket(final String bucketName, final AmazonS3 s3) { try { if (AwsUtils.getUrlBase().contains("archive.org")) { System.out.println("Not creating bucket for URL base: " + AwsUtils.getUrlBase()); return; } } catch (final IOException e1) { e1.printStackTrace(); } final Preferences prefs = Preferences.userRoot(); final String createdBuckets = prefs.get(BUCKETS_KEY, ""); if (!createdBuckets.contains("," + bucketName + ",") && !createdBuckets.endsWith("," + bucketName)) { try { s3.createBucket(bucketName); prefs.put(BUCKETS_KEY, createdBuckets + "," + bucketName); } catch (final IOException e) { System.out.println("Could not create bucket. Already exists?"); e.printStackTrace(); } } }