Skip to content

Commit

Permalink
Refactoring param aspects to pull out shared code
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgerring committed Nov 29, 2023
1 parent 8e680f7 commit cb87a5c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
import org.aspectj.lang.reflect.FieldSignature;
import software.amazon.lambda.powertools.parameters.BaseParamAspect;

/**
* Provides the AppConfig parameter aspect. This aspect is responsible for injecting
* parameters from AppConfig into fields annotated with @AppConfigParam. See the
* README and Powertools for Lambda (Java) documentation for information on using this feature.
*/
@Aspect
public class AppConfigParametersAspect extends BaseParamAspect {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
import software.amazon.lambda.powertools.parameters.BaseParamAspect;
import software.amazon.lambda.powertools.parameters.BaseProvider;

/**
* Provides the DynamoDB parameter aspect. This aspect is responsible for injecting
* parameters from DynamoDB into fields annotated with @DynamoDbParam. See the
* README and Powertools for Lambda (Java) documentation for information on using this feature.
*/
@Aspect
public class DynamoDbParamAspect extends BaseParamAspect {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public class DynamoDbProviderBuilder {
private String table;
private CacheManager cacheManager;
private TransformationManager transformationManager;

// Allows the user to override default max age
private int maxAge;
private ChronoUnit unit;

static DynamoDbClient createClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
import org.aspectj.lang.reflect.FieldSignature;
import software.amazon.lambda.powertools.parameters.BaseParamAspect;

/**
* Provides the Secrets parameter aspect. This aspect is responsible for injecting
* parameters from Secrets Provider into fields annotated with @SecretsParam. See the
* README and Powertools for Lambda (Java) documentation for information on using this feature.
*/
@Aspect
public class SecretsParamAspect extends BaseParamAspect {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
import software.amazon.lambda.powertools.parameters.BaseParamAspect;
import software.amazon.lambda.powertools.parameters.BaseProvider;

/**
* Provides the SSM parameter store parameter aspect. This aspect is responsible for injecting
* parameters from SSM Parameter Store into fields annotated with @SSMParam. See the
* README and Powertools for Lambda (Java) documentation for information on using this feature.
*/
@Aspect
public class SSMParamAspect extends BaseParamAspect {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,24 @@
import org.aspectj.lang.reflect.FieldSignature;
import software.amazon.lambda.powertools.parameters.transform.Transformer;

public class BaseParamAspect {
/**
* Provides a common base for all parameter aspects. This lets us group functionality that
* we need to reimplement in each aspect. This class should be extended for each
* additional parameter aspect.
*/
public abstract class BaseParamAspect {

/**
* Gets the parameter value from the provider and transforms it if necessary. This transformation
* is generic across all parameter providers.
*
* @param key The key of the parameter to get
* @param transformer The transformer to use to transform the parameter value
* @param provider A concrete instance of the parameter provider to retrieve the value from
* @param fieldSignature The signature of the field that the parameter is being injected into
*
* @return The value of the parameter, transformed if necessary
*/
protected Object getAndTransform(String key, Class<? extends Transformer> transformer, BaseProvider provider,
FieldSignature fieldSignature) {
if (transformer.isInterface()) {
Expand Down

0 comments on commit cb87a5c

Please sign in to comment.