Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom DynamoDB mapper with AttributeTransformer #91

Closed
micw opened this issue Sep 21, 2017 · 10 comments
Closed

Allow custom DynamoDB mapper with AttributeTransformer #91

micw opened this issue Sep 21, 2017 · 10 comments
Milestone

Comments

@micw
Copy link

micw commented Sep 21, 2017

In my use-case I need to encrypt all data in DynamoDB. Fortunately there's a ready-to-use tool from AWS that implements encryption using an AttributeTransformer.
A DynamoDBMapper can be constructed with an AttributeTransformer that is used then. Since spring-data-dynamodb can use a user-provided DynamoDBTemplate it'spossible to inject it at this point.
The problem is that DynamoDBTemplate has no way to set DynamoDBTemplate programmatically nor has it a way to pass an AttributeTransformer. I "fix" this by using reflection but that's not how it should work.

@derjust
Copy link
Owner

derjust commented Nov 3, 2017

Closed as merged

@derjust derjust closed this as completed Nov 3, 2017
@ryonday
Copy link

ryonday commented Dec 15, 2017

Is there a chance we can get this ported to the 4.5.x line and a 4.5.1 released? We are on Spring Boot 1.5.9, and therefore have to use 4.5.0 at the moment. I am in need of using AttributeTransformer and would rather not have to resort to reflection.

Thank you!

@derjust
Copy link
Owner

derjust commented Dec 20, 2017

@gauravbrills yes this is part of the 5.0.x line

@gauravbrills
Copy link

Yes found it thanks

derjust pushed a commit that referenced this issue Dec 20, 2017
derjust added a commit that referenced this issue Dec 20, 2017
@derjust
Copy link
Owner

derjust commented Dec 20, 2017

v.4.5.1 is right now publishing to Maven Central

@gauravbrills
Copy link

@derjust when running the same get the below error I guess cause of the assert for the dynamoDbMapper , do we need the assert if we supplying the dynamodb mapper with the new constructor provided ?

Caused by: java.lang.AssertionError: null
	at org.socialsignin.spring.data.dynamodb.core.DynamoDBTemplate.<init>(DynamoDBTemplate.java:60)
	at org.socialsignin.spring.data.dynamodb.core.DynamoDBTemplate.<init>(DynamoDBTemplate.java:46)
	at com.wellmanage.wfg.fdps.DynamoDBTestConfig.dynamoDbOperations(DynamoDBTestConfig.java:83)

@gauravbrills
Copy link

gauravbrills commented Dec 21, 2017

For now created a custom Dynamodbtemplate to solve this and passing it as a dynamodboperationRef .. had to make the following changes to skip the assert check in DynamoDbTemplate

DynamoDBTemplate(AmazonDynamoDB amazonDynamoDB, DynamoDBMapperConfig dynamoDBMapperConfig,
         DynamoDBMapper dynamoDBMapper)
   {
      this.amazonDynamoDB = amazonDynamoDB;
      if (dynamoDBMapper == null && dynamoDBMapperConfig == null)
      {
         this.dynamoDBMapperConfig = DynamoDBMapperConfig.DEFAULT;
         this.dynamoDBMapper = new DynamoDBMapper(amazonDynamoDB);
        // Mapper must be null as it could not have been constructed without a Config
            assert dynamoDBMapper == null;
      }
      else
      {
         this.dynamoDBMapperConfig = dynamoDBMapperConfig;
         if (dynamoDBMapper == null)
         {
            this.dynamoDBMapper = new DynamoDBMapper(amazonDynamoDB, dynamoDBMapperConfig);
         }
         else
         {
            this.dynamoDBMapper = dynamoDBMapper;
         }
      }
   }

do review this , I guess it needs to be changed or will do a PR . For now have created a custom DybamoDbTemplate with the above code to fix the same

@derjust
Copy link
Owner

derjust commented Dec 24, 2017

#105 cherry-picked & added unit tests (and fixed a typo) 👍

Thanks & happy holidays 🎄 @gauravbrills

@derjust derjust closed this as completed Dec 24, 2017
@gauravbrills
Copy link

Great..Happy holidays 🎄 to you too @derjust 😊

@kpcsuh
Copy link

kpcsuh commented Dec 28, 2017

In my case I need both Dynamo Table prefix like (DEV_, QA_, etc) and encrypt all data in DynamoDB.
Right now, DynamoDBTemplate constructor takes either DynamoDBMapperConfig or DynamoDBMapper but not both. Any solution for my problem?

I think below constructor should be public as well? I may be wrong.

DynamoDBTemplate(AmazonDynamoDB amazonDynamoDB, DynamoDBMapperConfig dynamoDBMapperConfig, DynamoDBMapper dynamoDBMapper)

@derjust derjust added this to the v5.0.1 milestone Jan 5, 2018
@derjust derjust modified the milestones: v5.0.1, v4.5.3, v5.0.2 Jan 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants