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

feat: Coginto class Update #84

Merged
merged 17 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
b0801de
feat: add AUDIT log level for upload
wphyojpl Oct 14, 2024
00d6bde
chore: update outdated tests
wphyojpl Oct 14, 2024
327ef8d
Merge branch 'develop' of github.com:unity-sds/mdps-ds-lib into develop
wphyojpl Oct 21, 2024
6fd6910
chore: merge from develop
wphyojpl Oct 21, 2024
f77e47e
Merge branch 'develop' of github.com:unity-sds/mdps-ds-lib into develop
wphyojpl Oct 21, 2024
a51314b
fix: allow empty str as RESULT_PATH_PREFIX & replace w/ default val
wphyojpl Oct 21, 2024
2d72378
Merge branch 'develop' of github.com:unity-sds/mdps-ds-lib into develop
wphyojpl Oct 28, 2024
0c31b5f
Merge branch 'develop' of gh.neting.ccmunity-sds/mdps-ds-lib into develop
wphyojpl Oct 28, 2024
5701e60
Merge branch 'develop' of github.com:unity-sds/mdps-ds-lib into develop
wphyojpl Nov 7, 2024
b429a12
erge branch 'develop' of github.com:unity-sds/mdps-ds-lib into develop
wphyojpl Nov 7, 2024
87e82ae
Merge branch 'develop' of github.com:unity-sds/mdps-ds-lib into develop
wphyojpl Nov 26, 2024
b730339
Merge branch 'develop' of github.com:unity-sds/mdps-ds-lib into develop
wphyojpl Nov 26, 2024
a6d89f6
Merge branch 'develop' of github.com:unity-sds/mdps-ds-lib into develop
wphyojpl Dec 4, 2024
87a2858
Merge branch 'develop' of github.com:unity-sds/mdps-ds-lib into develop
wphyojpl Dec 9, 2024
efb0d8c
Merge branch 'develop' of github.com:unity-sds/mdps-ds-lib into develop
wphyojpl Dec 9, 2024
d918170
feat: add more methods to cognito class
wphyojpl Dec 9, 2024
5c1248b
feat: add more methods
wphyojpl Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions mdps_ds_lib/lib/aws/aws_cognito.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,50 @@ def get_groups(self, username: str):
return []
belonged_groups = [k['GroupName'] for k in response['Groups']]
return belonged_groups

def add_user_to_group(self, username: str, group_name: str):
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cognito-idp/client/admin_add_user_to_group.html

response = self.__cognito.admin_add_user_to_group(
UserPoolId=self.__user_pool_id,
Username=username,
GroupName=group_name,
)
if response['ResponseMetadata']['HTTPStatusCode'] != 200:
raise RuntimeError(response)
return response

def remove_user_from_group(self, username: str, group_name: str):
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cognito-idp/client/admin_remove_user_from_group.html
response = self.__cognito.admin_remove_user_from_group(
UserPoolId=self.__user_pool_id,
Username=username,
GroupName=group_name,
)
if response['ResponseMetadata']['HTTPStatusCode'] != 200:
raise RuntimeError(response)
return response

def add_group(self, group_name: str):
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cognito-idp/client/create_group.html
response = self.__cognito.create_group(
GroupName=group_name,
UserPoolId=self.__user_pool_id,
# Description='NA',
# RoleArn='string',
)
if response['ResponseMetadata']['HTTPStatusCode'] != 200:
raise RuntimeError(response)
return response

def delete_group(self, group_name: str):
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cognito-idp/client/delete_group.html
response = self.__cognito.delete_group(
GroupName=group_name,
UserPoolId=self.__user_pool_id,
# Description='NA',
# RoleArn='string',
)
if response['ResponseMetadata']['HTTPStatusCode'] != 200:
raise RuntimeError(response)
return response
19 changes: 16 additions & 3 deletions tests/mdps_ds_lib/lib/aws/test_aws_cognito.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,22 @@

class TestAwsCognitor(TestCase):
def test_01(self):
cognito = AwsCognito('us-west-2_FLDyXE2mO')
wphyo_groups = cognito.get_groups('wphyo')
cognito = AwsCognito('us-west-2_yaOw3yj0z')
sample_group_name = 'UNIT_TEST_GROUP_WPHYO'
username = 'wphyo'
result = cognito.add_group(sample_group_name)
print(result)
result = cognito.add_user_to_group(username, sample_group_name)
print(result)
wphyo_groups = cognito.get_groups(username)
self.assertTrue(isinstance(wphyo_groups, list), f'response is not list. {wphyo_groups}')
self.assertTrue(len(wphyo_groups) > 0, f'empty list')
print(wphyo_groups)
self.assertTrue(sample_group_name in wphyo_groups, f'empty list')
result = cognito.remove_user_from_group(username, sample_group_name)
print(result)
wphyo_groups = cognito.get_groups(username)
self.assertTrue(isinstance(wphyo_groups, list), f'response is not list. {wphyo_groups}')
self.assertTrue(sample_group_name not in wphyo_groups, f'empty list')
result = cognito.delete_group(sample_group_name)
print(result)
return
Loading