com.amazonaws.services.s3.model.Bucket Java Examples
The following examples show how to use
com.amazonaws.services.s3.model.Bucket.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LambdaConfig.java From github-bucket with ISC License | 6 votes |
private LambdaConfig() { try (InputStream is = getClass().getClassLoader().getResourceAsStream("env.properties")) { this.props.load(is); this.repository = new FileRepository(new File(System.getProperty("java.io.tmpdir"), "s3")); } catch (IOException e) { throw new IllegalArgumentException(e); } overwriteWithSystemProperty(ENV_BRANCH); overwriteWithSystemProperty(ENV_BUCKET); overwriteWithSystemProperty(ENV_GITHUB); this.remote = new Remote(Constants.DEFAULT_REMOTE_NAME); this.branch = new Branch(props.getProperty(ENV_BRANCH, Constants.MASTER)); this.authentication = new SecureShellAuthentication(new Bucket(props.getProperty(ENV_BUCKET)), client); }
Example #2
Source File: S3.java From s3-cf-service-broker with Apache License 2.0 | 6 votes |
public Bucket createBucketForInstance(String instanceId, ServiceDefinition service, String planId, String organizationGuid, String spaceGuid) { String bucketName = getBucketNameForInstance(instanceId); logger.info("Creating bucket '{}' for serviceInstanceId '{}'", bucketName, instanceId); Bucket bucket = s3.createBucket(bucketName, Region.fromValue(region)); // TODO allow for additional, custom tagging options BucketTaggingConfiguration bucketTaggingConfiguration = new BucketTaggingConfiguration(); TagSet tagSet = new TagSet(); tagSet.setTag("serviceInstanceId", instanceId); tagSet.setTag("serviceDefinitionId", service.getId()); tagSet.setTag("planId", planId); tagSet.setTag("organizationGuid", organizationGuid); tagSet.setTag("spaceGuid", spaceGuid); bucketTaggingConfiguration.withTagSets(tagSet); s3.setBucketTaggingConfiguration(bucket.getName(), bucketTaggingConfiguration); return bucket; }
Example #3
Source File: S3BucketsTableProvider.java From aws-athena-query-federation with Apache License 2.0 | 6 votes |
/** * Maps a DBInstance into a row in our Apache Arrow response block(s). * * @param bucket The S3 Bucket to map. * @param spiller The BlockSpiller to use when we want to write a matching row to the response. * @note The current implementation is rather naive in how it maps fields. It leverages a static * list of fields that we'd like to provide and then explicitly filters and converts each field. */ private void toRow(Bucket bucket, BlockSpiller spiller) { spiller.writeRows((Block block, int row) -> { boolean matched = true; matched &= block.offerValue("bucket_name", row, bucket.getName()); matched &= block.offerValue("create_date", row, bucket.getCreationDate()); Owner owner = bucket.getOwner(); if (owner != null) { matched &= block.offerValue("owner_name", row, bucket.getOwner().getDisplayName()); matched &= block.offerValue("owner_id", row, bucket.getOwner().getId()); } return matched ? 1 : 0; }); }
Example #4
Source File: CreateBucket.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) { final String USAGE = "\n" + "CreateBucket - create an S3 bucket\n\n" + "Usage: CreateBucket <bucketname>\n\n" + "Where:\n" + " bucketname - the name of the bucket to create.\n\n" + "The bucket name must be unique, or an error will result.\n"; if (args.length < 1) { System.out.println(USAGE); System.exit(1); } String bucket_name = args[0]; System.out.format("\nCreating S3 bucket: %s\n", bucket_name); Bucket b = createBucket(bucket_name); if (b == null) { System.out.println("Error creating bucket!\n"); } else { System.out.println("Done!\n"); } }
Example #5
Source File: ContentHelper.java From aws-photosharing-example with Apache License 2.0 | 6 votes |
public synchronized void createS3BucketIfNotExists(String p_bucket_name) { _logger.debug("Searching for bucket " + p_bucket_name); if (!s3Client.doesBucketExist(p_bucket_name)) { Bucket bucket = s3Client.createBucket(p_bucket_name); _logger.info("Created bucket: " + bucket.getName()); } else { _logger.debug("Bucket detected. Verifying permissions."); try { s3Client.getBucketAcl(p_bucket_name); } catch (AmazonClientException ex) { _logger.warn("Permission check failed. Randomizing."); ConfigFacade.set(Configuration.S3_BUCKET_FORMAT, p_bucket_name + "-" + Security.getRandomHash(8)); _logger.debug("Reiterating with: " + p_bucket_name); createS3BucketIfNotExists(getConfiguredBucketName()); } } }
Example #6
Source File: S3CommonFileObject.java From hop with Apache License 2.0 | 6 votes |
protected List<String> getS3ObjectsFromVirtualFolder( String key, String bucketName ) { List<String> childrenList = new ArrayList<>(); // fix cases where the path doesn't include the final delimiter String realKey = key; if ( !realKey.endsWith( DELIMITER ) ) { realKey += DELIMITER; } if ( "".equals( key ) && "".equals( bucketName ) ) { //Getting buckets in root folder List<Bucket> bucketList = fileSystem.getS3Client().listBuckets(); for ( Bucket bucket : bucketList ) { childrenList.add( bucket.getName() + DELIMITER ); } } else { getObjectsFromNonRootFolder( key, bucketName, childrenList, realKey ); } return childrenList; }
Example #7
Source File: LambdaConfig.java From github-bucket with ISC License | 6 votes |
private LambdaConfig() { try (InputStream is = getClass().getClassLoader().getResourceAsStream("env.properties")) { this.props.load(is); this.repository = new FileRepository(new File(System.getProperty("java.io.tmpdir"), "s3")); } catch (IOException e) { throw new IllegalArgumentException(e); } overwriteWithSystemProperty(ENV_BRANCH); overwriteWithSystemProperty(ENV_BUCKET); overwriteWithSystemProperty(ENV_GITHUB); this.remote = new Remote(Constants.DEFAULT_REMOTE_NAME); this.branch = new Branch(props.getProperty(ENV_BRANCH, Constants.MASTER)); this.authentication = new SecureShellAuthentication(new Bucket(props.getProperty(ENV_BUCKET)), client); }
Example #8
Source File: LocalstackContainerTest.java From testcontainers-java with MIT License | 6 votes |
@Test public void s3TestOverBridgeNetwork() throws IOException { AmazonS3 s3 = AmazonS3ClientBuilder .standard() .withEndpointConfiguration(localstack.getEndpointConfiguration(S3)) .withCredentials(localstack.getDefaultCredentialsProvider()) .build(); final String bucketName = "foo"; s3.createBucket(bucketName); s3.putObject(bucketName, "bar", "baz"); final List<Bucket> buckets = s3.listBuckets(); final Optional<Bucket> maybeBucket = buckets.stream().filter(b -> b.getName().equals(bucketName)).findFirst(); assertTrue("The created bucket is present", maybeBucket.isPresent()); final Bucket bucket = maybeBucket.get(); assertEquals("The created bucket has the right name", bucketName, bucket.getName()); final ObjectListing objectListing = s3.listObjects(bucketName); assertEquals("The created bucket has 1 item in it", 1, objectListing.getObjectSummaries().size()); final S3Object object = s3.getObject(bucketName, "bar"); final String content = IOUtils.toString(object.getObjectContent(), Charset.forName("UTF-8")); assertEquals("The object can be retrieved", "baz", content); }
Example #9
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
private static String fetchS3EncryptInfo(Bucket bucket, AmazonS3 s3Client) { String bucketEncryp = null; try{ GetBucketEncryptionResult buckectEncry = s3Client.getBucketEncryption(bucket.getName()); if (buckectEncry != null) { ServerSideEncryptionConfiguration sseBucketEncryp = buckectEncry.getServerSideEncryptionConfiguration(); if (sseBucketEncryp != null && sseBucketEncryp.getRules() != null) { bucketEncryp = sseBucketEncryp.getRules().get(0).getApplyServerSideEncryptionByDefault() .getSSEAlgorithm(); } } }catch(Exception e){ // Exception thrown when there is no bucket encryption available. } return bucketEncryp; }
Example #10
Source File: InventoryUtilTest.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch S 3 info test test exception. * * @throws Exception the exception */ @SuppressWarnings("static-access") @Test public void fetchS3InfoTestTest_Exception() throws Exception { mockStatic(AmazonS3ClientBuilder.class); AmazonS3 amazonS3Client = PowerMockito.mock(AmazonS3.class); AmazonS3ClientBuilder amazonRDSClientBuilder = PowerMockito.mock(AmazonS3ClientBuilder.class); AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class); PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider); when(amazonRDSClientBuilder.standard()).thenReturn(amazonRDSClientBuilder); when(amazonRDSClientBuilder.withCredentials(anyObject())).thenReturn(amazonRDSClientBuilder); when(amazonRDSClientBuilder.withRegion(anyString())).thenReturn(amazonRDSClientBuilder); when(amazonRDSClientBuilder.build()).thenReturn(amazonS3Client); List<Bucket> s3buckets = new ArrayList<>(); Bucket bucket = new Bucket(); bucket.setName("name"); s3buckets.add(bucket); when(amazonS3Client.listBuckets()).thenReturn(s3buckets); when(amazonS3Client.getBucketLocation(anyString())).thenThrow(new AmazonServiceException("Error")); assertThat(inventoryUtil.fetchS3Info(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "skipRegions", "account","accountName").size(), is(0)); }
Example #11
Source File: S3SiteListResolver.java From engine with GNU General Public License v3.0 | 6 votes |
protected Collection<String> getSiteListFromBucketNames(String bucketNameRegex) { List<String> siteNames = new ArrayList<>(); AmazonS3 client = clientBuilder.getClient(); List<Bucket> buckets = client.listBuckets(); if (CollectionUtils.isNotEmpty(buckets)) { for (Bucket bucket : buckets) { Matcher bucketNameMatcher = Pattern.compile(bucketNameRegex).matcher(bucket.getName()); if (bucketNameMatcher.matches()) { siteNames.add(bucketNameMatcher.group(1)); } } } return siteNames; }
Example #12
Source File: App.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
private static void ListMyBuckets() { List<Bucket> buckets = s3.listBuckets(); System.out.println("My buckets now are:"); for (Bucket b : buckets) { System.out.println(b.getName()); } }
Example #13
Source File: TypeaheadS3BucketRequest.java From h2o-2 with Apache License 2.0 | 5 votes |
@Override protected JsonArray serve(String filter, int limit) { JsonArray array = new JsonArray(); try { AmazonS3 s3 = PersistS3.getClient(); filter = Strings.nullToEmpty(filter); for( Bucket b : s3.listBuckets() ) { if( b.getName().startsWith(filter) ) array.add(new JsonPrimitive(b.getName())); if( array.size() == limit) break; } } catch( IllegalArgumentException xe ) { } return array; }
Example #14
Source File: TypeaheadFileRequest.java From h2o-2 with Apache License 2.0 | 5 votes |
protected JsonArray serveS3(String filter, int limit){ JsonArray array = new JsonArray(); try { AmazonS3 s3 = PersistS3.getClient(); filter = Strings.nullToEmpty(filter); for( Bucket b : s3.listBuckets() ) { if( b.getName().startsWith(filter) ) array.add(new JsonPrimitive(b.getName())); if( array.size() == limit) break; } } catch( IllegalArgumentException xe ) { } return array; }
Example #15
Source File: ListGcsBuckets.java From java-docs-samples with Apache License 2.0 | 5 votes |
public static void listGcsBuckets(String googleAccessKeyId, String googleAccessKeySecret) { // String googleAccessKeyId = "your-google-access-key-id"; // String googleAccessKeySecret = "your-google-access-key-secret"; // Create a BasicAWSCredentials using Cloud Storage HMAC credentials. BasicAWSCredentials googleCreds = new BasicAWSCredentials(googleAccessKeyId, googleAccessKeySecret); // Create a new client and do the following: // 1. Change the endpoint URL to use the Google Cloud Storage XML API endpoint. // 2. Use Cloud Storage HMAC Credentials. AmazonS3 interopClient = AmazonS3ClientBuilder.standard() .withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration( "https://storage.googleapis.com", "auto")) .withCredentials(new AWSStaticCredentialsProvider(googleCreds)) .build(); // Call GCS to list current buckets List<Bucket> buckets = interopClient.listBuckets(); // Print bucket names System.out.println("Buckets:"); for (Bucket bucket : buckets) { System.out.println(bucket.getName()); } // Explicitly clean up client resources. interopClient.shutdown(); }
Example #16
Source File: SpillLocationVerifierTest.java From aws-athena-query-federation with Apache License 2.0 | 5 votes |
@Before public void setup() { logger.info("setUpBefore - enter"); bucketNames = Arrays.asList("bucket1", "bucket2", "bucket3"); List<Bucket> buckets = createBuckets(bucketNames); AmazonS3 mockS3 = createMockS3(buckets); spyVerifier = spy(new SpillLocationVerifier(mockS3)); logger.info("setUpBefore - exit"); }
Example #17
Source File: ListBuckets.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build(); List<Bucket> buckets = s3.listBuckets(); System.out.println("Your Amazon S3 buckets are:"); for (Bucket b : buckets) { System.out.println("* " + b.getName()); } }
Example #18
Source File: CreateBucket.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static Bucket createBucket(String bucket_name) { final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build(); Bucket b = null; if (s3.doesBucketExistV2(bucket_name)) { System.out.format("Bucket %s already exists.\n", bucket_name); b = getBucket(bucket_name); } else { try { b = s3.createBucket(bucket_name); } catch (AmazonS3Exception e) { System.err.println(e.getErrorMessage()); } } return b; }
Example #19
Source File: BucketVH.java From pacbot with Apache License 2.0 | 5 votes |
/** * Instantiates a new bucket VH. * * @param bucket the bucket * @param location the location * @param versionConfig the version config * @param tags the tags */ public BucketVH(Bucket bucket,String location,BucketVersioningConfiguration versionConfig, List<Tag> tags, String bucketEncryp, boolean websiteConfiguration,BucketLoggingConfiguration bucketLoggingConfiguration){ this.bucket = bucket; this.location = location; this.versionStatus = versionConfig==null?"":versionConfig.getStatus(); this.mfaDelete = versionConfig==null?null:versionConfig.isMfaDeleteEnabled(); this.tags = tags; this.bucketEncryp = bucketEncryp; this.websiteConfiguration = websiteConfiguration; this.isLoggingEnabled = bucketLoggingConfiguration==null?null:bucketLoggingConfiguration.isLoggingEnabled(); this.destinationBucketName = bucketLoggingConfiguration==null?"":bucketLoggingConfiguration.getDestinationBucketName(); this.logFilePrefix = bucketLoggingConfiguration==null?"":bucketLoggingConfiguration.getLogFilePrefix(); }
Example #20
Source File: DummyS3Client.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public Bucket createBucket(String bucketName) throws SdkClientException { if (doesBucketExist(bucketName)) throw new AmazonS3Exception("The specified bucket already exist"); else { objMap.put(bucketName, new HashSet<>()); return new Bucket(); } }
Example #21
Source File: S3FeaturesDemoTest.java From Scribengin with GNU Affero General Public License v3.0 | 5 votes |
public void listBuckets() { System.out.println("Listing buckets: "); List<Bucket> buckets = s3Client.listBuckets(); for (Bucket bucket : buckets) { System.out.println(" - " + bucket.getName()); } }
Example #22
Source File: ListBuckets.java From openbd-core with GNU General Public License v3.0 | 5 votes |
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException{ AmazonKey amazonKey = getAmazonKey(_session, argStruct); AmazonS3 s3Client = getAmazonS3(amazonKey); try { //Create the results cfQueryResultData qD = new cfQueryResultData( new String[]{"bucket","createdate"}, null ); qD.setQuerySource( "AmazonS3." + amazonKey.getDataSource() ); List<Bucket> bucketList = s3Client.listBuckets(); for ( Iterator<Bucket> it = bucketList.iterator(); it.hasNext(); ){ Bucket bucket = it.next(); qD.addRow(1); qD.setCurrentRow( qD.getSize() ); qD.setCell( 1, new cfStringData( bucket.getName() ) ); qD.setCell( 2, new cfDateData( bucket.getCreationDate() ) ); } return qD; } catch (Exception e) { throwException(_session, "AmazonS3: " + e.getMessage() ); return cfBooleanData.FALSE; } }
Example #23
Source File: AwsSdkTest.java From s3proxy with Apache License 2.0 | 5 votes |
@Test public void testListBuckets() throws Exception { ImmutableList.Builder<String> builder = ImmutableList.builder(); for (Bucket bucket : client.listBuckets()) { builder.add(bucket.getName()); } assertThat(builder.build()).contains(containerName); }
Example #24
Source File: S3UploadTask.java From aws-mobile-self-paced-labs-samples with Apache License 2.0 | 5 votes |
private boolean createBucket(String bucketname) { Bucket newBucket = manager.getAmazonS3Client().createBucket(AWSClientManager.S3_BUCKET_NAME); if (newBucket != null) return true; else { return false; } }
Example #25
Source File: S3ProxyRuleTest.java From s3proxy with Apache License 2.0 | 5 votes |
@Test public final void listBucket() { List<Bucket> buckets = s3Client.listBuckets(); assertThat(buckets).hasSize(1); assertThat(buckets.get(0).getName()) .isEqualTo(MY_TEST_BUCKET); }
Example #26
Source File: AmazonS3MockUnitTest.java From Scribengin with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testCreateBucket() { AmazonS3Mock s3sinkMock = new AmazonS3Mock(); Bucket bucket = s3sinkMock.createBucket("test"); assertTrue(bucket.getName().equals("test")); }
Example #27
Source File: PathMatchingSimpleStorageResourcePatternResolver.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
private List<String> findMatchingBuckets(String bucketPattern) { List<Bucket> buckets = this.amazonS3.listBuckets(); List<String> matchingBuckets = new ArrayList<>(); for (Bucket bucket : buckets) { this.amazonS3.getBucketLocation(bucket.getName()); if (this.pathMatcher.match(bucketPattern, bucket.getName())) { matchingBuckets.add(bucket.getName()); } } return matchingBuckets; }
Example #28
Source File: PathMatchingSimpleStorageResourcePatternResolverTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
private AmazonS3 prepareMockForTestWildcardInBucketName() { AmazonS3 amazonS3 = mock(AmazonS3.class); when(amazonS3.listBuckets()).thenReturn( Arrays.asList(new Bucket("myBucketOne"), new Bucket("myBucketTwo"), new Bucket("anotherBucket"), new Bucket("myBuckez"))); // Mocks for the '**' case ObjectListing objectListingWithOneFile = createObjectListingMock( Collections.singletonList(createS3ObjectSummaryWithKey("test.txt")), Collections.emptyList(), false); ObjectListing emptyObjectListing = createObjectListingMock( Collections.emptyList(), Collections.emptyList(), false); when(amazonS3.listObjects( argThat(new ListObjectsRequestMatcher("myBucketOne", null, null)))) .thenReturn(objectListingWithOneFile); when(amazonS3.listObjects( argThat(new ListObjectsRequestMatcher("myBucketTwo", null, null)))) .thenReturn(emptyObjectListing); when(amazonS3.listObjects( argThat(new ListObjectsRequestMatcher("anotherBucket", null, null)))) .thenReturn(objectListingWithOneFile); when(amazonS3.listObjects( argThat(new ListObjectsRequestMatcher("myBuckez", null, null)))) .thenReturn(emptyObjectListing); when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class))) .thenReturn(new ObjectMetadata()); return amazonS3; }
Example #29
Source File: S3.java From s3-cf-service-broker with Apache License 2.0 | 5 votes |
public List<ServiceInstance> getAllServiceInstances() { List<ServiceInstance> serviceInstances = Lists.newArrayList(); for (Bucket bucket : s3.listBuckets()) { BucketTaggingConfiguration taggingConfiguration = s3.getBucketTaggingConfiguration(bucket.getName()); ServiceInstance serviceInstance = createServiceInstance(taggingConfiguration); serviceInstances.add(serviceInstance); } return serviceInstances; }
Example #30
Source File: BasicPlan.java From s3-cf-service-broker with Apache License 2.0 | 5 votes |
public ServiceInstance createServiceInstance(ServiceDefinition service, String serviceInstanceId, String planId, String organizationGuid, String spaceGuid) { Bucket bucket = s3.createBucketForInstance(serviceInstanceId, service, planId, organizationGuid, spaceGuid); iam.createGroupForInstance(serviceInstanceId, bucket.getName()); iam.applyGroupPolicyForInstance(serviceInstanceId, bucket.getName()); return new ServiceInstance(serviceInstanceId, service.getId(), planId, organizationGuid, spaceGuid, null); }