com.amazonaws.services.s3.model.BucketVersioningConfiguration Java Examples

The following examples show how to use com.amazonaws.services.s3.model.BucketVersioningConfiguration. 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: CheckMFADeleteEnabledRuleTest.java    From pacbot with Apache License 2.0 5 votes vote down vote up
@Test
public void test()throws Exception{
    Collection<String> li = new ArrayList<>();
    li.add("123");
    BucketVersioningConfiguration configuration = new BucketVersioningConfiguration();
    configuration.setMfaDeleteEnabled(false);
    
    mockStatic(PacmanUtils.class);
    when(PacmanUtils.doesAllHaveValue(anyString(),anyString())).thenReturn(
            true);
    
    Map<String,Object>map=new HashMap<String, Object>();
    map.put("client", awsS3Client);
    CheckMFADeleteEnabledRule spy = Mockito.spy(new CheckMFADeleteEnabledRule());
    
    Mockito.doReturn(map).when((BaseRule)spy).getClientFor(anyObject(), anyString(), anyObject());
    
    when(awsS3Client.getBucketVersioningConfiguration(anyString())).thenReturn(configuration);
    spy.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "));
    
    assertThat(checkMFADeleteEnabledRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getEmptyMapString()), is(notNullValue()));
    
    when(awsS3Client.getBucketVersioningConfiguration(anyString())).thenThrow(new RuleExecutionFailedExeption());
    assertThatThrownBy( 
            () -> checkMFADeleteEnabledRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "))).isInstanceOf(InvalidInputException.class);
    
    
    when(PacmanUtils.doesAllHaveValue(anyString(),anyString())).thenReturn(
            false);
    assertThatThrownBy(
            () -> checkMFADeleteEnabledRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "))).isInstanceOf(InvalidInputException.class);
}
 
Example #2
Source File: BucketVH.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #3
Source File: InventoryUtilTest.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch S 3 info test.
 *
 * @throws Exception the exception
 */
@SuppressWarnings({ "static-access"})
@Test
public void fetchS3InfoTest() 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())).thenReturn("bucketLocation");
    mockStatic(com.amazonaws.services.s3.model.Region.class);
    com.amazonaws.services.s3.model.Region value = null;
    when(com.amazonaws.services.s3.model.Region.fromValue(anyString())).thenReturn(value.US_West);
    when(value.US_West.toAWSRegion()).thenReturn(getRegions().get(0));
    when(amazonS3Client.getBucketVersioningConfiguration(anyString())).thenReturn(new BucketVersioningConfiguration());
    BucketTaggingConfiguration tagConfig = new BucketTaggingConfiguration();
    List<TagSet> tagSets = new ArrayList<>();
    TagSet tagSet = new TagSet();
    tagSet.setTag("key", "value");
    tagSets.add(tagSet);
    tagSets.add(tagSet);
    tagConfig.setTagSets(tagSets);
    when(amazonS3Client.getBucketTaggingConfiguration(anyString())).thenReturn(tagConfig);
    
    assertThat(inventoryUtil.fetchS3Info(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), 
            "skipRegions", "account","accountName").size(), is(1));
}
 
Example #4
Source File: CodeBuilderValidation.java    From aws-codebuild-jenkins-plugin with Apache License 2.0 4 votes vote down vote up
public static boolean checkBucketIsVersioned(String bucketName, AWSClientFactory awsClientFactory) {
    final BucketVersioningConfiguration bucketVersioningConfig = awsClientFactory.getS3Client().getBucketVersioningConfiguration(bucketName);
    return bucketVersioningConfig.getStatus().equals(BucketVersioningConfiguration.ENABLED);
}
 
Example #5
Source File: DummyS3Client.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** Unsupported Operation. */
@Override public BucketVersioningConfiguration getBucketVersioningConfiguration(
    String bucketName) throws SdkClientException {
    throw new UnsupportedOperationException("Operation not supported");
}
 
Example #6
Source File: DummyS3Client.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** Unsupported Operation. */
@Override public BucketVersioningConfiguration getBucketVersioningConfiguration(
    GetBucketVersioningConfigurationRequest getBucketVersioningConfigurationReq) throws SdkClientException {
    throw new UnsupportedOperationException("Operation not supported");
}
 
Example #7
Source File: AmazonS3Mock.java    From Scribengin with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public BucketVersioningConfiguration getBucketVersioningConfiguration(String bucketName)
    throws AmazonClientException, AmazonServiceException {
  // TODO Auto-generated method stub
  return null;
}
 
Example #8
Source File: CrossRegionReplication.java    From aws-doc-sdk-examples with Apache License 2.0 3 votes vote down vote up
private static void createBucket(AmazonS3 s3Client, Regions region, String bucketName) {
    CreateBucketRequest request = new CreateBucketRequest(bucketName, region.getName());
    s3Client.createBucket(request);
    BucketVersioningConfiguration configuration = new BucketVersioningConfiguration().withStatus(BucketVersioningConfiguration.ENABLED);

    SetBucketVersioningConfigurationRequest enableVersioningRequest = new SetBucketVersioningConfigurationRequest(bucketName, configuration);
    s3Client.setBucketVersioningConfiguration(enableVersioningRequest);


}