Recipient rule set to put emails into dynamic s3 bucket Amazon - java

I am trying to set up amazon SES recipient rule set for putting emails into an s3 bucket. I have created an s3 bucket and I want these mails to sent into folders according to the email id. For example if an email is coming to 1#mydomain.com it should go into mytestbucket/1 and if it is coming to 2#mydomain.com it should go into mytestbucket/2.
AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonSimpleEmailServiceClient sesClient = new AmazonSimpleEmailServiceClient(awsCredentials);
;
if (sesClient != null) {
CreateReceiptRuleRequest req = new CreateReceiptRuleRequest();
req.withRuleSetName(ruleSetName);
ReceiptRule rule = new ReceiptRule();
rule.setEnabled(true);
rule.setName(customerIdString + "-email");
rule.withRecipients(customerIdString + "#" + mydomain.com);
List<ReceiptAction> actions = new ArrayList<ReceiptAction>();
ReceiptAction action = new ReceiptAction();
S3Action s3Action = new S3Action();
s3Action.setBucketName(mytestbucket);
s3Action.setObjectKeyPrefix(customerIdString);
action.setS3Action(s3Action);
actions.add(action);
rule.setActions(actions);
req.setRule(rule);
CreateReceiptRuleResult response = sesClient.createReceiptRule(req);
return true;
}
Whenever I add a customer I was calling this method to create a rule to my active ruleset. But it looks like only 100 rules can be added. My usecase will be for at least 100 000. How can I achieve this?
Something I am expecting to do is
Have a single recipient rule which says any email comes to mysubdomain invoke a lambda function
Lambda function should put the email into subfolders of s3

Follow these steps to achieve what you desire...
Create a single SES rule to place ALL emails into a single S3 folder unsorted_emails (you can call it anything).
Create a Lambda function that places emails into their proper folders.
Set unsorted_emails as an event source to trigger your lambda function.
Now, whenever new emails are added to unsorted_emails, your lambda function will be triggered and move the email into a proper folder.
Let me know if these steps make sense, if you have any questions, or if I can clarify more.

Related

How to Set BucketLifeCycleRule in Minio?

After creating a Minio bucket, I set the bucket's lifecycle rules. The LifeCycleRule takes up the expiration variable that is set for just 1 day. When checking the status of my bucket through minio client (mc), mc ilm ls mycloud/bucketName , I notice that the Lifecycle rule was successfully applied on to the designated bucket. However, when checking back on Minio after 1 day, the bucket is still there. Is there something else that I need to add to the LifeCycleRule in order to delete Minio Bucket properly?
Note, I've been using Minio SDKs Java Client API as reference.
fun createBucket(bucketName: String){
client.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build())
setBucketLifeCycle(bucketName)
}
private fun setBucketLifeCycle(bucketName: String){
// Setting the expiration for one day.
val expiration = Expiration(null as ZonedDateTime?, 1, null)
var lifeCycleRuleList = mutableListOf<LifecycleRule>()
val lifecycleRuleExpiry = LifecycleRule(
Status.ENABLED,
null,
expiration,
RuleFilter("expiry/logs"),
"rule 1",
null,
null,
null)
lifecycleRuleList.add(lifecycleRuleExpiry)
var lifecycleConfig = LifecycleConfiguration(lifecycleRuleList)
// Applies the lifecycleConfig on to target bucket.
client.setBucketLifecycle(SetBucketLifecycleArgs.buider()
.bucket(bucketName).config(lifecycleConfig).build())
}
Questions
Am I missing something more on my LifeCycleRule?
Could it be that the bucket does not get automatically deleted because it has objects inside of it?
I did notice on the minio client that when the bucket has items on it, mc rb mycloud/bucketName will fail to remove the the bucket, but forcing it with mc rb -force mycloud/bucketName will successfully remove it. Is there a way to speficy "force" on the lifecycle parameters?
Lifecycle rules apply to objects within a bucket, not to the bucket itself.
An S3 Lifecycle configuration is a set of rules that define actions that Amazon S3 applies to a group of objects.
(ref: https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html)
So, this bucket will not be deleted (even) when all the objects in it are expired via ILM policies.

Firestore; add user email identifier without creating a collection

I'm planning to create a web page (lets say for admin) to add user identifier only which is using email and create a temporary password for user without creating a collection.
I'm considering to either use python or java language but I couldn't find any answer whether this can be done or not with cloud firestore. does anyone have any idea?
You can create users for your firebase app without adding them to a collection.
Firestore Admin SDK supports Node.js, Java, Python, Go, C# and .NET it really depends on what language you wish to use for your web server. It could really be either that you choose or you could not use an SDK and instead use something completely different because you can also use firestore with javascript. It really depends on your requirements.
Here is more information on how to set up your environment for which ever option you may need.
To create a user with an email and a password you can use this code in:
javascript
firebase.auth().createUserWithEmailAndPassword(email, password)
.then((userCredential) => {
// Signed in
var user = userCredential.user;
// ...
})
.catch((error) => {
var errorCode = error.code;
var errorMessage = error.message;
// ..
});
Python
user = auth.create_user(
uid='some-uid', email='user#example.com', phone_number='+15555550100')
print('Sucessfully created new user: {0}'.format(user.uid))
Java
CreateRequest request = new CreateRequest()
.setUid("some-uid")
.setEmail("user#example.com")
.setPhoneNumber("+11234567890");
UserRecord userRecord = FirebaseAuth.getInstance().createUser(request); System.out.println("Successfully created new user: " + userRecord.getUid());
More information on creating users with email Here

Java Reactor - if/else chaining (filtering)

I am rewriting my Discord bot from Discord4J v2 to v3 that's based on Reactor. I am new to reactive programming and Java Reactor in particular. I'd like to implement a commands system with commands of three types:
DM commands — commands that users send as direct messages to the bot,
public guild commands — commands that users send in a special channel #bot-commands in my Discord server — everyone with some particular role X can use these commands, and
admin guild commands — similar to public, but users must have some role Y (which is higher than X).
If a user tries to execute some particular command but they haven't got the role required for it, the bot should tell them about that. Otherwise the command should be executed (taking into account the sender (message author), the channel this command was sent, and the command itself (the message)).
I am not sure how to implement this all reactively, and I couldn't find the necessary information on the Discord4J wiki. This is what I currently have:
private final Set<DiscordCommand> discordGuildCommands = new HashSet<>();
private final Set<DiscordCommand> discordDmCommands = new HashSet<>();
// ...
gateway = DiscordClient.create(discordToken).login().block();
// ...
gateway.getEventDispatcher()
.on(MessageCreateEvent.class)
.filter(event -> !(event.getMessage().getChannel().block() instanceof PrivateChannel))
.filterWhen(event -> event.getMember().get().hasHigherRoles(Roles.REFLEXBOT_CTRL_SINGLETON))
.flatMap(event -> Mono.just(event.getMessage().getContent())
.flatMap(content -> Flux.fromIterable(discordGuildCommands)
.filter(cmd -> content.startsWith(DISCORD_COMMANDS_PREFIX + cmd.getName()))
.flatMap(cmd -> cmd.process(event))
.next()
)
)
.subscribe();
This code appears to work fine and allows me to process admin guild commands, that is, commands sent in my Discord server's text channels by members whose "permission level" (highest role level) is at least one I specified.
But how do I implement the rest of the commands properly (reactively and nicely)? I haven't found anything like if/else chaining in Reactor, and I don't really want to duplicate the above code several times with only 1-2 filter(...) lines changed.
I'm not familiar with Discord4J, but I think you should inverse flow and add some settings for your commands.
Add hash map [command name => channel/private]
Add hash map [command name => minimum role]
Add hash map [command name => command]
Then build your flow:
Get command from first map (or return error "I dont know that command")
Using first map check if command matches with request type (private/channel) (or return error "I dont know that command")
Using second map check user role (or return error "Access denied")
Get command instance from third map
Run the command

List of Places using Platform SDK

Background
My application connects to the Genesys Interaction Server in order to receive events for actions performed on the Interaction Workspace. I am using the Platform SDK 8.5 for Java.
I make the connection to the Interaction Server using the method described in the API reference.
InteractionServerProtocol interactionServerProtocol =
new InteractionServerProtocol(
new Endpoint(
endpointName,
interactionServerHost,
interactionServerPort));
interactionServerProtocol.setClientType(InteractionClient.AgentApplication);
interactionServerProtocol.open();
Next, I need to register a listener for each Place I wish to receive events for.
RequestStartPlaceAgentStateReporting requestStartPlaceAgentStateReporting = RequestStartPlaceAgentStateReporting.create();
requestStartPlaceAgentStateReporting.setPlaceId("PlaceOfGold");
requestStartPlaceAgentStateReporting.setTenantId(101);
isProtocol.send(requestStartPlaceAgentStateReporting);
The way it is now, my application requires the user to manually specify each Place he wishes to observe. This requires him to know the names of all the Places, which he may not necessarily have [easy] access to.
Question
How do I programmatically obtain a list of Places available? Preferably from the Interaction Server to limit the number of connections needed.
There is a method you can use. If you check methods of applicationblocks you will see cfg and query objects. You can use it for get list of all DNs. When building query, try blank DBID,name and number.
there is a .net code similar to java code(actually exatly the same)
List<CfgDN> list = new List<CfgDN>();
List<DN> dnlist = new List<Dn>();
CfgDNQuery query = new CfgDNQuery(m_ConfService);
list = m_ConfService.RetrieveMultipleObjects<CfgDN>(query).ToList();
foreach (CfgDN item in list)
{
foo = (DN) item.DBID;
......
dnlist.Add(foo);
}
Note : DN is my class which contains some property from platform SDK.
KeyValueCollection tenantList = new KeyValueCollection();
tenantList.addString("tenant", "Resources");
RequestStartPlaceAgentStateReportingAll all = RequestStartPlaceAgentStateReportingAll.create(tenantList);
interactionServerProtocol.send(all);

Android JWT parsing payload/claims when signed

I have a signed JWT String that i get from the server. I do not know the key or rather I don't want to put the key on the client/device.
When using this site with my token: https://jwt.io/ I get the desired result it tells me the Header and payload information.
I cannot find a library on android that does what this website does and i have tried all of them that i could find. The most recognized one to use is: https://github.com/jwtk/jjwt
But this gives me an exception that i cannot parse a signed token which as proven by the other website above is false. another resource i have used is: https://bitbucket.org/b_c/jose4j/wiki/Home
This one at least gave me the header information which is the furthest i have been able to get.
To give context why it is the way it is, the payload contains an expiration time and on the device when the token is about to expire i should prompt the user to re enter their credentials to get a new token. Now this might seem like a security threat because a hacker could manipulate the token on the device, but the server checks the token to make sure it is authentic which is why i do not want the key on the device because this can be mined by a hacker, and make the entire application vulnerable.
If you wanna parse signatured text without using signature :
1- add below dependency :
//JWT
compile 'io.jsonwebtoken:jjwt:0.7.0'
2 - Add below imports :
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Header;
import io.jsonwebtoken.Jwt;
import io.jsonwebtoken.Jwts;
3- Use below code block :
//ref : https://github.com/jwtk/jjwt/issues/135
//you can put your signatured text instead of jws variable.
String jws = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ";
int i = jws.lastIndexOf('.')
String withoutSignature = jws.substring(0, i+1);
Jwt<Header,Claims> untrusted = Jwts.parser().parseClaimsJwt(withoutSignature);
/*untrusted.getBody().getSubject();
untrusted.getBody().getExpiration();
etc.
*/
Well the answer was pretty simple although in my opinion should be in the framework. But a simple non signed JWT still has the 2 required periods in it but there is nothing after the last one, so i split my JWT on the periods and combined the first and second one with periods and put a period at the end.
String[] splitToken = result.Value.Content.AuthorizationJWTToken.split("\\.");
Jwt parsedToken = Jwts.parser().parse(splitToken[0] + "." + splitToken[1] + ".");
This was usings the https://github.com/jwtk/jjwt library.
You can use jose4j's JWT consumer to do parsing only and not check the claims or signature. Something like the following will parse the token and compare the expiration time to the current time to see if it's expired.
String jwt = "eyJhbGciOiJIUzI1NiJ9" +
".eyJzdWIiOiIxMjM0NTY3ODkwIiwiZXhwIjoxNDUzODE0NjA0LCJuYW1lIjoiSm9obiBEb2UifQ" +
".IXcDDLXEpGN9Po5C-Mz88jUCNYrHxu6TVJLavf0NgT8";
JwtConsumer consumer = new JwtConsumerBuilder()
.setSkipAllValidators()
.setDisableRequireSignature()
.setSkipSignatureVerification()
.build();
JwtClaims claims = consumer.processToClaims(jwt);
NumericDate expirationTime = claims.getExpirationTime();
if (NumericDate.now().isAfter(expirationTime))
{
System.out.println("Token expired at " + expirationTime);
}
else
{
System.out.println("Token is still good until " + expirationTime);
}
parseClaimsJwt() method of Jwt will require a signature. So, right way to do it is:
String jws = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ";
int i = jws.lastIndexOf('.')
String withoutSignature = jws.substring(0, i+1);
Claims claims = (Claims) = Jwts.parser().parse(withoutSignature).getBody();

Categories