Skip to content

Commit

Permalink
make cognito users unique for every pool
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias committed Nov 1, 2023
1 parent cfd4e44 commit 037f843
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion plugins/aws/resoto_plugin_aws/resource/cognito.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from attrs import define, field
from typing import ClassVar, Dict, List, Optional, Type
from typing import ClassVar, Dict, List, Optional, Type, Tuple, Any
from resoto_plugin_aws.aws_client import AwsClient
from resoto_plugin_aws.resource.base import AwsApiSpec, AwsResource, GraphBuilder
from resoto_plugin_aws.resource.iam import AwsIamRole
Expand Down Expand Up @@ -91,6 +91,13 @@ class AwsCognitoUser(AwsResource, BaseUser):
enabled: Optional[bool] = field(default=None)
user_status: Optional[str] = field(default=None)
mfa_options: List[AwsCognitoMFAOptionType] = field(factory=list)
pool_name: Optional[str] = None

def _keys(self) -> Tuple[Any, ...]:
# in case different user pools include the same user: we add the
if self.pool_name is not None:
return tuple(list(super()._keys()) + [self.pool_name])
return super()._keys()

@classmethod
def service_name(cls) -> str:
Expand Down Expand Up @@ -197,6 +204,7 @@ def add_tags(pool: AwsCognitoUserPool) -> None:
builder.submit_work(service_name, add_tags, pool_instance)
for user in builder.client.list(service_name, "list-users", "Users", UserPoolId=pool_instance.id):
if user_instance := AwsCognitoUser.from_api(user, builder):
user_instance.pool_name = pool_instance.name
builder.add_node(user_instance, user)
builder.add_edge(from_node=pool_instance, edge_type=EdgeType.default, node=user_instance)
for group in builder.client.list(service_name, "list-groups", "Groups", UserPoolId=pool_instance.id):
Expand Down

0 comments on commit 037f843

Please sign in to comment.