<commit_before>package uk.ac.wellcome.finatra.modules

import javax.inject.Singleton

import com.amazonaws.auth.{AWSStaticCredentialsProvider, BasicAWSCredentials}
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.google.inject.Provides
import com.twitter.inject.TwitterModule
import uk.ac.wellcome.models.aws.AWSConfig
import com.amazonaws.services.dynamodbv2._

object DynamoClientModule extends TwitterModule {
  override val modules = Seq(AWSConfigModule)
  private val dynamoDbEndpoint = flag[String](
    "aws.dynamoDb.endpoint",
    "",
    "Endpoint of AWS DynamoDB. if not present it will use the region")

  @Singleton
  @Provides
  def providesDynamoClient(awsConfig: AWSConfig): AmazonDynamoDB = {
    val standardDynamoDBClientBuilder = AmazonDynamoDBClientBuilder.standard
    if (dynamoDbEndpoint().isEmpty)
      standardDynamoDBClientBuilder
        .withRegion(awsConfig.region)
        .build()
    else
      standardDynamoDBClientBuilder
        .withEndpointConfiguration(
          new EndpointConfiguration(dynamoDbEndpoint(), awsConfig.region))
        .withCredentials(new AWSStaticCredentialsProvider(
          new BasicAWSCredentials(awsConfig.accessKey.get, awsConfig.secretKey.get)))
        .build()
  }

  @Singleton
  @Provides
  def providesDynamoStreamsClient(awsConfig: AWSConfig): AmazonDynamoDBStreams = {
    val standardDynamoStreamsClientBuilder = AmazonDynamoDBStreamsClientBuilder
        .standard()
    if (dynamoDbEndpoint().isEmpty)
      standardDynamoStreamsClientBuilder
        .withRegion(awsConfig.region)
        .build()
    else
      standardDynamoStreamsClientBuilder
        .withEndpointConfiguration(
          new EndpointConfiguration(dynamoDbEndpoint(), awsConfig.region))
        .withCredentials(new AWSStaticCredentialsProvider(
          new BasicAWSCredentials(awsConfig.accessKey.get, awsConfig.secretKey.get)))
        .build()
  }
}
<commit_msg>REadding DynamoAsyncClient cause actually it is used. Copying the logic for creating one with an endpoint or without<commit_after>package uk.ac.wellcome.finatra.modules

import javax.inject.Singleton

import com.amazonaws.auth.{AWSStaticCredentialsProvider, BasicAWSCredentials}
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.google.inject.Provides
import com.twitter.inject.TwitterModule
import uk.ac.wellcome.models.aws.AWSConfig
import com.amazonaws.services.dynamodbv2._

object DynamoClientModule extends TwitterModule {
  override val modules = Seq(AWSConfigModule)
  private val dynamoDbEndpoint = flag[String](
    "aws.dynamoDb.endpoint",
    "",
    "Endpoint of AWS DynamoDB. if not present it will use the region")

  @Singleton
  @Provides
  def providesDynamoClient(awsConfig: AWSConfig): AmazonDynamoDB = {
    val standardDynamoDBClientBuilder = AmazonDynamoDBClientBuilder.standard
    if (dynamoDbEndpoint().isEmpty)
      standardDynamoDBClientBuilder
        .withRegion(awsConfig.region)
        .build()
    else
      standardDynamoDBClientBuilder
        .withEndpointConfiguration(
          new EndpointConfiguration(dynamoDbEndpoint(), awsConfig.region))
        .withCredentials(new AWSStaticCredentialsProvider(
          new BasicAWSCredentials(awsConfig.accessKey.get, awsConfig.secretKey.get)))
        .build()
  }

  @Singleton
  @Provides
  def providesDynamoStreamsClient(awsConfig: AWSConfig): AmazonDynamoDBStreams = {
    val standardDynamoStreamsClientBuilder = AmazonDynamoDBStreamsClientBuilder
        .standard()
    if (dynamoDbEndpoint().isEmpty)
      standardDynamoStreamsClientBuilder
        .withRegion(awsConfig.region)
        .build()
    else
      standardDynamoStreamsClientBuilder
        .withEndpointConfiguration(
          new EndpointConfiguration(dynamoDbEndpoint(), awsConfig.region))
        .withCredentials(new AWSStaticCredentialsProvider(
          new BasicAWSCredentials(awsConfig.accessKey.get, awsConfig.secretKey.get)))
        .build()
  }

  @Singleton
  @Provides
  def providesDynamoAsyncClient(awsConfig: AWSConfig): AmazonDynamoDBAsync = {
    val standardDynamoDbAsyncClientBuilder = AmazonDynamoDBAsyncClientBuilder
      .standard()
    if (dynamoDbEndpoint().isEmpty)
      standardDynamoDbAsyncClientBuilder
        .withRegion(awsConfig.region)
        .build()
    else
      standardDynamoDbAsyncClientBuilder
        .withEndpointConfiguration(
          new EndpointConfiguration(dynamoDbEndpoint(), awsConfig.region))
        .withCredentials(new AWSStaticCredentialsProvider(
          new BasicAWSCredentials(awsConfig.accessKey.get, awsConfig.secretKey.get)))
        .build()
  }
}

{'fraction_non_alphanumeric': 0.07578676942838793, 'fraction_numerical': 0.00042817383857846286, 'mean_word_length': 4.078260869565217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1921379', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1327, 'n_words': 234}