S3Configuration.java

1
package org.cardanofoundation.explorer.api.config;
2
3
import org.springframework.beans.factory.annotation.Value;
4
import org.springframework.context.annotation.Bean;
5
import org.springframework.context.annotation.Configuration;
6
import org.springframework.context.annotation.Profile;
7
8
import com.amazonaws.auth.AWSStaticCredentialsProvider;
9
import com.amazonaws.auth.BasicAWSCredentials;
10
import com.amazonaws.client.builder.AwsClientBuilder;
11
import com.amazonaws.services.s3.AmazonS3;
12
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
13
14
@Configuration
15
public class S3Configuration {
16
17
  @Bean
18
  @Profile("minio")
19
  public AmazonS3 amazonS3Clone(
20
      @Value("${cloud.aws.s3.endpoint}") String serviceEndpoint,
21
      @Value("${cloud.aws.s3.path-style.enabled}") Boolean pathStyleAccessEnabled,
22
      @Value("${cloud.aws.credentials.access-key}") String accessKey,
23
      @Value("${cloud.aws.credentials.secret-key}") String secretKey,
24
      @Value("${cloud.aws.region.static}") String region,
25
      @Value("${cloud.aws.s3.bucket.name}") String bucketName) {
26
    final AmazonS3 amazonS3 =
27
        AmazonS3ClientBuilder.standard()
28
            .withEndpointConfiguration(
29
                new AwsClientBuilder.EndpointConfiguration(serviceEndpoint, region))
30
            .withPathStyleAccessEnabled(pathStyleAccessEnabled)
31
            .withCredentials(
32
                new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
33
            .build();
34
35 1 1. amazonS3Clone : negated conditional → NO_COVERAGE
    if (!amazonS3.doesBucketExistV2(bucketName)) {
36
      amazonS3.createBucket(bucketName);
37
    }
38 1 1. amazonS3Clone : replaced return value with null for org/cardanofoundation/explorer/api/config/S3Configuration::amazonS3Clone → NO_COVERAGE
    return amazonS3;
39
  }
40
41
  @Bean
42
  @Profile("s3")
43
  public AmazonS3 amazonS3(
44
      @Value("${cloud.aws.credentials.access-key}") String accessKey,
45
      @Value("${cloud.aws.credentials.secret-key}") String secretKey,
46
      @Value("${cloud.aws.region.static}") String region,
47
      @Value("${cloud.aws.s3.bucket.name}") String bucketName) {
48
    final AmazonS3 amazonS3 =
49
        AmazonS3ClientBuilder.standard()
50
            .withRegion(region)
51
            .withCredentials(
52
                new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
53
            .build();
54
55 1 1. amazonS3 : negated conditional → NO_COVERAGE
    if (!amazonS3.doesBucketExistV2(bucketName)) {
56
      amazonS3.createBucket(bucketName);
57
    }
58 1 1. amazonS3 : replaced return value with null for org/cardanofoundation/explorer/api/config/S3Configuration::amazonS3 → NO_COVERAGE
    return amazonS3;
59
  }
60
}

Mutations

35

1.1
Location : amazonS3Clone
Killed by : none
negated conditional → NO_COVERAGE

38

1.1
Location : amazonS3Clone
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/config/S3Configuration::amazonS3Clone → NO_COVERAGE

55

1.1
Location : amazonS3
Killed by : none
negated conditional → NO_COVERAGE

58

1.1
Location : amazonS3
Killed by : none
replaced return value with null for org/cardanofoundation/explorer/api/config/S3Configuration::amazonS3 → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.14.2