Skip to content

Commit

Permalink
Merge branch 'milestone/v0.2.0' into sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
kreloaded committed Aug 30, 2023
2 parents 7ff2e5d + 10b0840 commit 3caac81
Show file tree
Hide file tree
Showing 193 changed files with 7,466 additions and 7,167 deletions.
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@
<version>2.20.132</version>
</dependency>

<dependency>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.39</version>
</dependency>

<dependency>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>owasp-java-html-sanitizer</artifactId>
Expand All @@ -178,6 +184,20 @@
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.39</version>
<executions>
<execution>
<goals>
<goal>validate</goal>
<goal>apply</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
17 changes: 14 additions & 3 deletions repo-docs/LOCAL_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ $ git submodule update --init

1. Copy the contents of `sample.secrets.json` to `secrets.json`.
2. Update the values of the environment variables in secrets.json:
- Copy Salesforce credentials from the Salesforce connected app and update `SALESFORCE_CLIENT_ID`, `SALESFORCE_CLIENT_SECRET`, `SALESFORCE_AUTH_URL`.
- Update `KMS_KEY_ID` with value `arn:aws:kms:'us-east-1':'111122223333':key/bc436485-5092-42b8-92a3-0aa8b93536dc`. This local Docker setup uses the [local-kms](https://hub.docker.com/r/nsmithuk/local-kms) Docker image, and the key is already configured using [seed](init/seed.yaml).
- Copy Salesforce credentials from the Salesforce connected app and update `SALESFORCE_CLIENT_ID`, `SALESFORCE_CLIENT_SECRET`, `SALESFORCE_AUTH_URL`.
- Update `KMS_KEY_ID` with value `arn:aws:kms:'us-east-1':'111122223333':key/bc436485-5092-42b8-92a3-0aa8b93536dc`. This local Docker setup uses the [local-kms](https://hub.docker.com/r/nsmithuk/local-kms) Docker image, and the key is already configured using [seed](init/seed.yaml).

### Start the API Server with Docker

Expand All @@ -44,11 +44,13 @@ $ docker-compose up api
#### Set Test-Related Environment Variables

1. Create a `test.secrets.json` file:

```sh
$ touch test.secrets.json
```

2. Add the following environment variables to `test.secrets.json`:

```json
{
"ENCRYPTION_KEY": "1234567890",
Expand All @@ -71,9 +73,18 @@ $ touch test.secrets.json
}
```

#### Apply Spring Java Format

Before committing the changes, it's good practice to apply the Spring Java format to your code to ensure it adheres to a consistent style.

```sh
$ ./mvnw spring-javaformat:apply
```

#### Run Test Cases

```sh
$ docker-compose up test
```
To view the test coverage, simply open the target/site/index.html file in a web browser.

To view the test coverage, simply open the target/site/index.html file in a web browser.
4 changes: 2 additions & 2 deletions src/main/java/com/salessparrow/api/SalesSparrowApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableAsync;


@SpringBootApplication(exclude= {UserDetailsServiceAutoConfiguration.class})
@SpringBootApplication(exclude = { UserDetailsServiceAutoConfiguration.class })
@EnableCaching // This enables caching
@EnableAsync // This enables asynchronous processing in Spring
public class SalesSparrowApi {

public static void main(String[] args) {
SpringApplication.run(SalesSparrowApi.class, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@

@ChangeLog
public class DatabaseChangelog {

Logger logger = LoggerFactory.getLogger(DatabaseChangelog.class);

@ChangeSet(order = "001", id = "001", author = "testAuthor")
public void createSalesforceOrganizationsTable(AmazonDynamoDB db) {
String tableName = DynamoDbTableNameConstants.salesforceOrganizationsTableName();
logger.info("Creating table: " + tableName);

CreateTableRequest request = new CreateTableRequest()
.withTableName(tableName)
.withAttributeDefinitions(
new AttributeDefinition("external_organization_id",
ScalarAttributeType.S))
.withKeySchema(
new KeySchemaElement("external_organization_id", KeyType.HASH))
.withBillingMode("PAY_PER_REQUEST");
CreateTableRequest request = new CreateTableRequest().withTableName(tableName)
.withAttributeDefinitions(new AttributeDefinition("external_organization_id", ScalarAttributeType.S))
.withKeySchema(new KeySchemaElement("external_organization_id", KeyType.HASH))
.withBillingMode("PAY_PER_REQUEST");

db.createTable(request);
logger.info("Done creating table: " + tableName);
Expand All @@ -40,13 +37,10 @@ public void createSalesforceOAuthTokensTable(AmazonDynamoDB db) {
String tableName = DynamoDbTableNameConstants.salesforceOauthTokensTableName();
logger.info("Creating table:" + tableName);

CreateTableRequest request = new CreateTableRequest()
.withTableName(tableName)
.withAttributeDefinitions(
new AttributeDefinition("external_user_id", ScalarAttributeType.S))
.withKeySchema(
new KeySchemaElement("external_user_id", KeyType.HASH))
.withBillingMode("PAY_PER_REQUEST");
CreateTableRequest request = new CreateTableRequest().withTableName(tableName)
.withAttributeDefinitions(new AttributeDefinition("external_user_id", ScalarAttributeType.S))
.withKeySchema(new KeySchemaElement("external_user_id", KeyType.HASH))
.withBillingMode("PAY_PER_REQUEST");

db.createTable(request);

Expand All @@ -58,16 +52,14 @@ public void createSalesforceUsersTable(AmazonDynamoDB db) {
String tableName = DynamoDbTableNameConstants.salesforceUsersTableName();
logger.info("Creating table:" + tableName);

CreateTableRequest request = new CreateTableRequest()
.withTableName(tableName)
.withAttributeDefinitions(
new AttributeDefinition("external_user_id", ScalarAttributeType.S))
.withKeySchema(
new KeySchemaElement("external_user_id", KeyType.HASH))
.withBillingMode("PAY_PER_REQUEST");
CreateTableRequest request = new CreateTableRequest().withTableName(tableName)
.withAttributeDefinitions(new AttributeDefinition("external_user_id", ScalarAttributeType.S))
.withKeySchema(new KeySchemaElement("external_user_id", KeyType.HASH))
.withBillingMode("PAY_PER_REQUEST");

db.createTable(request);

logger.info("Done creating table: " + tableName);
}

}
83 changes: 34 additions & 49 deletions src/main/java/com/salessparrow/api/config/AwsConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.salessparrow.api.config;

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.kms.AWSKMS;
import com.amazonaws.services.kms.AWSKMSClientBuilder;
Expand All @@ -11,60 +9,47 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Configuration class for AWS-related beans and settings.
*
*
*/
@Configuration
public class AwsConfig {

/**
* Returns an instance of the AWS Key Management Service (KMS)
* client based on the environment.
*
* @implNote - Client is configured to use the local KMS endpoint for following environments
* - development
* - test
* - local-test
* For test and production environments, the client is configured to use the AWS KMS endpoint
*
* @return An instance of the AWSKMS client configured
* for the appropriate environment.
*
*/
@Bean
public AWSKMS kmsClient() {
if (
CoreConstants.isDevEnvironment() ||
CoreConstants.isTestEnvironment() ||
CoreConstants.isLocalTestEnvironment()
) {

AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(
CoreConstants.localKmsEndpoint(),
CoreConstants.awsRegion()
);
/**
* Returns an instance of the AWS Key Management Service (KMS) client based on the
* environment.
*
* @implNote - Client is configured to use the local KMS endpoint for following
* environments - development - test - local-test For test and production
* environments, the client is configured to use the AWS KMS endpoint
* @return An instance of the AWSKMS client configured for the appropriate
* environment.
*
*/
@Bean
public AWSKMS kmsClient() {
if (CoreConstants.isDevEnvironment() || CoreConstants.isTestEnvironment()
|| CoreConstants.isLocalTestEnvironment()) {

AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(
CoreConstants.localKmsEndpoint(), CoreConstants.awsRegion());

return AWSKMSClientBuilder.standard().withEndpointConfiguration(endpointConfiguration).build();
}

return AWSKMSClientBuilder.standard()
.withEndpointConfiguration(endpointConfiguration)
.build();
}

return AWSKMSClientBuilder.standard()
.withRegion(CoreConstants.awsRegion())
.build();
}
return AWSKMSClientBuilder.standard().withRegion(CoreConstants.awsRegion()).build();
}

/**
* Creates and configures an AWS SES (Simple Email Service) client.
*
* @return An instance of AmazonSimpleEmailService that allows access to AWS SES operations.
*/
@Bean
public AmazonSimpleEmailService sesClient() {
return AmazonSimpleEmailServiceClientBuilder.standard()
.withRegion(CoreConstants.awsRegion())
.build();
}
/**
* Creates and configures an AWS SES (Simple Email Service) client.
* @return An instance of AmazonSimpleEmailService that allows access to AWS SES
* operations.
*/
@Bean
public AmazonSimpleEmailService sesClient() {
return AmazonSimpleEmailServiceClientBuilder.standard().withRegion(CoreConstants.awsRegion()).build();
}

}
Loading

0 comments on commit 3caac81

Please sign in to comment.