quarkiverse / quarkus-amazon-services

Quarkus Amazon Services extensions
Apache License 2.0
41 stars 49 forks source link

Cognito user pools with reproducible user pool ids in dev services #1398

Closed ketola closed 2 weeks ago

ketola commented 1 month ago

The Cognito user pool id is generated randomly when the user pool is created (this is correct as it works like this in AWS also). But this makes it difficult to test if your code depends on a known and existing user pool id (for example if you are fetching the users of a specific user pool in your code).

The dev services for Cognito user pools uses moto for emulating the AWS Cognito behaviour. Moto supports creating the user pool ids with reproducible ids: https://docs.getmoto.org/en/latest/docs/services/cognito-idp.html by setting the MOTO_COGNITO_IDP_USER_POOL_ID_STRATEGY=HASH environment variable. When it is enabled, the user pool id will be created based on the input parameters when the pool is created and you should end up with the same user pool id every time as long as the parameters are the same when creating the pool.

That could be added as a configuration option for the devservices/cognito-user-pools module also.

I would be also interested in implementing this, if you would find this a useful feature.

scrocquesel commented 1 month ago

That would be a great addition. there is already a containerProperties config but it is not mapped to the env var of the container. Maybe you can first try to map them here

https://github.com/quarkiverse/quarkus-amazon-services/blob/62dc50a1b62ce710d0d6ea260b1cb5a23bd0e9b2/devservices/cognito-user-pools/src/main/java/io/quarkus/amazon/devservices/cognitouserpools/CognitoUserPoolsDevServicesProcessor.java#L81-L83

Before the container starts.

Then, if you feel it can help, you can introduce a custom propery. You will have to create a new class extending DevServicesBuildTimeConfig in the runtime project and change the type of the property devservices on CognitoUserPoolsBuildTimeConfig. You can look at S3 extension for an existing implementation.

ketola commented 1 month ago

I did the first part of passing the container properties to moto. But what do you think about the second part? Would the custom property be useful also? You can get it working like this, I tested that it works, but of course, it might not be that obvious that you can do this kind of thing if it's not a documented config option.

I would have tested this addition also, but is there a way to access the running devservices container and get the env variables?

scrocquesel commented 1 month ago

I did the first part of passing the container properties to moto. But what do you think about the second part? Would the custom property be useful also? You can get it working like this, I tested that it works, but of course, it might not be that obvious that you can do this kind of thing if it's not a documented config option.

Actually, we documented it a long time ago: https://docs.quarkiverse.io/quarkus-amazon-services/dev/dev-services.html#_cognito, but it wasn't working.

I would have tested this addition also, but is there a way to access the running devservices container and get the env variables?

WDYM by "get the env variables" ?