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

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

Open
ketola opened this issue Sep 15, 2024 · 3 comments · Fixed by #1411
Open

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

ketola opened this issue Sep 15, 2024 · 3 comments · Fixed by #1411
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ketola
Copy link
Contributor

ketola commented Sep 15, 2024

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
Copy link
Member

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

MotoContainer container = new MotoContainer(
DockerImageName.parse(motoDevServicesBuildTimeConfig.imageName()));
container.start();

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
Copy link
Contributor Author

ketola commented Sep 22, 2024

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
Copy link
Member

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" ?

@scrocquesel scrocquesel reopened this Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants