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

Fix/issue 142 #181

Merged
merged 33 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1f66828
add Cognito Group resolver
LEUNGUU Oct 7, 2022
e5fc455
Modified output to array of groups and list of dictionaries - backend
dlpzx Oct 9, 2022
12198f6
api call in frontend view
dlpzx Oct 9, 2022
bf2a7c0
api call in frontend view + fix input output in resolver local + fix …
dlpzx Oct 10, 2022
056b545
flake
dlpzx Oct 10, 2022
3cdcd12
Added orga views and filter for orga or environment
dlpzx Oct 13, 2022
2754739
Show only not invited groups and remove two unused apis
LEUNGUU Oct 17, 2022
359e15d
Cognito list groups in handlers + added integration test for list groups
dlpzx Oct 17, 2022
2984336
added integration test for list groups
dlpzx Oct 17, 2022
e2c7f28
testing of env non-local
dlpzx Oct 17, 2022
b9b839d
testing of env non-local
dlpzx Oct 17, 2022
039d936
Renamed cdk.json and cdk.context.json
dlpzx Oct 18, 2022
3e30b92
Merge branch 'v1m2m0' into list-and-search-for-possible-values-when-i…
dlpzx Oct 18, 2022
4862657
Merge pull request #169 from awslabs/167-rename-cdkjson-to-cdkjsontem…
dlpzx Oct 19, 2022
086cbbe
required --app for non cdk.context (SSM cdk.json) deployments
dlpzx Oct 20, 2022
fc361f9
Merge pull request #173 from awslabs/167-rename-cdkjson-to-cdkjsontem…
dlpzx Oct 20, 2022
de6ec86
Merge pull request #158 from awslabs/list-and-search-for-possible-val…
dlpzx Oct 20, 2022
1c22690
Better sharing management
Oct 25, 2022
e4b6eda
Testing feedbacks
Oct 26, 2022
47ad72d
fix lint issues
Oct 26, 2022
f9285c5
fix it test
Oct 26, 2022
d930e1a
remove empty f strings + put back waiter for cross account sharing
Oct 26, 2022
94efd00
time sleep
Oct 26, 2022
46a91fd
Rename ssm param
Oct 26, 2022
ff85691
Better sharing management
Oct 25, 2022
051f7b1
Testing feedbacks
Oct 26, 2022
85fdaf0
fix lint issues
Oct 26, 2022
cf62501
fix it test
Oct 26, 2022
e195ce9
remove empty f strings + put back waiter for cross account sharing
Oct 26, 2022
3ef336a
time sleep
Oct 26, 2022
b7321b1
First draft - refractoring to include S3 management
dlpzx Oct 27, 2022
341f86e
Merge remote-tracking branch 'origin/fix/issue-142' into fix/issue-142
dlpzx Oct 27, 2022
a6efa67
fix an invoke error in s3_approve_share
LEUNGUU Oct 28, 2022
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
10 changes: 0 additions & 10 deletions backend/dataall/api/Objects/Environment/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,6 @@
resolver=list_environment_invited_groups,
)

listEnvironmentNotInvitedGroups = gql.QueryField(
name='listEnvironmentNotInvitedGroups',
type=gql.Ref('GroupSearchResult'),
args=[
gql.Argument(name='environmentUri', type=gql.NonNullableType(gql.String)),
gql.Argument(name='filter', type=gql.Ref('GroupFilter')),
],
resolver=list_environment_not_invited_groups,
)

listEnvironmentGroups = gql.QueryField(
name='listEnvironmentGroups',
type=gql.Ref('GroupSearchResult'),
Expand Down
16 changes: 0 additions & 16 deletions backend/dataall/api/Objects/Environment/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,6 @@ def list_environment_invited_groups(
)


def list_environment_not_invited_groups(
context: Context, source, environmentUri=None, filter=None
):
if filter is None:
filter = {}
with context.engine.scoped_session() as session:
return db.api.Environment.not_environment_groups(
session=session,
username=context.username,
groups=context.groups,
uri=environmentUri,
data=filter,
check_perm=True,
)


def list_environment_groups(context: Context, source, environmentUri=None, filter=None):
if filter is None:
filter = {}
Expand Down
8 changes: 8 additions & 0 deletions backend/dataall/api/Objects/Group/input_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@
gql.Argument(name='pageSize', type=gql.Integer),
],
)

CognitoGroupFilter = gql.InputType(
name='CognitoGroupFilter',
arguments=[
gql.Argument(name='type', type=gql.String),
gql.Argument(name='uri', type=gql.String),
],
)
11 changes: 10 additions & 1 deletion backend/dataall/api/Objects/Group/queries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ... import gql
from .resolvers import get_group, list_datasets_owned_by_env_group, list_data_items_shared_with_env_group
from .resolvers import get_group, list_datasets_owned_by_env_group, list_data_items_shared_with_env_group, list_cognito_groups

getGroup = gql.QueryField(
name='getGroup',
Expand Down Expand Up @@ -33,3 +33,12 @@
type=gql.Ref('EnvironmentPublishedItemSearchResults'),
test_scope='Dataset',
)

listCognitoGroups = gql.QueryField(
name='listCognitoGroups',
args=[
gql.Argument(name='filter', type=gql.Ref('CognitoGroupFilter')),
],
type=gql.ArrayType(gql.Ref('CognitoGroup')),
resolver=list_cognito_groups
)
40 changes: 39 additions & 1 deletion backend/dataall/api/Objects/Group/resolvers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import os
import logging
from .... import db
from ....db import exceptions
from ....db.models import Group
from ...constants import *
from ....aws.handlers.cognito import Cognito


log = logging.getLogger()


def resolve_group_environment_permissions(context, source, environmentUri):
Expand Down Expand Up @@ -70,3 +75,36 @@ def list_data_items_shared_with_env_group(
data=filter,
check_perm=True,
)


def list_cognito_groups(context, source, filter: dict = None):
envname = os.getenv('envname', 'local')
if envname in ['dkrcompose']:
return [{"groupName": 'Docker'}]
current_region = os.getenv('AWS_REGION', 'eu-west-1')
groups = Cognito.list_cognito_groups(envname=envname, region=current_region)
category, category_uri = filter.get("type"), filter.get("uri")
if category and category_uri:
if category == 'environment':
with context.engine.scoped_session() as session:
invited_groups = db.api.Environment.query_all_environment_groups(
session=session,
username=context.username,
groups=context.groups,
uri=category_uri,
filter=None,
).all()
if category == 'organization':
with context.engine.scoped_session() as session:
organization = db.api.Organization.get_organization_by_uri(session, category_uri)
invited_groups = db.api.Organization.query_organization_groups(
session=session,
uri=organization.organizationUri,
filter=None,
).all()
invited_group_uris = [item.groupUri for item in invited_groups]
res = []
for group in groups:
if group['GroupName'] not in invited_group_uris:
res.append({"groupName": group['GroupName']})
return res
7 changes: 7 additions & 0 deletions backend/dataall/api/Objects/Group/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,10 @@
gql.Field(name='nodes', type=gql.ArrayType(Group)),
],
)

CognitoGroup = gql.ObjectType(
name='CognitoGroup',
fields=[
gql.Field(name='groupName', type=gql.String),
],
)
10 changes: 0 additions & 10 deletions backend/dataall/api/Objects/Organization/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@
resolver=list_organization_invited_groups,
)

listOrganizationNotInvitedGroups = gql.QueryField(
name='listOrganizationNotInvitedGroups',
type=gql.Ref('GroupSearchResult'),
args=[
gql.Argument(name='organizationUri', type=gql.NonNullableType(gql.String)),
gql.Argument(name='filter', type=gql.Ref('GroupFilter')),
],
resolver=list_organization_not_invited_groups,
)

listOrganizationGroups = gql.QueryField(
name='listOrganizationGroups',
type=gql.Ref('GroupSearchResult'),
Expand Down
16 changes: 0 additions & 16 deletions backend/dataall/api/Objects/Organization/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,6 @@ def list_organization_invited_groups(
)


def list_organization_not_invited_groups(
context: Context, source, organizationUri=None, filter=None
):
if filter is None:
filter = {}
with context.engine.scoped_session() as session:
return db.api.Organization.not_organization_groups(
session=session,
username=context.username,
groups=context.groups,
uri=organizationUri,
data=filter,
check_perm=True,
)


def list_organization_groups(
context: Context, source, organizationUri=None, filter=None
):
Expand Down
29 changes: 29 additions & 0 deletions backend/dataall/aws/handlers/cognito.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import logging
import boto3

from .sts import SessionHelper


log = logging.getLogger(__name__)


class Cognito:
@staticmethod
def client(account_id: str, region_name: str, client_type: str):
session = SessionHelper.remote_session(account_id)
return session.client(client_type, region_name=region_name)

@staticmethod
def list_cognito_groups(envname: str, region: str):
try:
parameter_path = f'/dataall/{envname}/cognito/userpool'
ssm = boto3.client('ssm', region_name=region)
user_pool_id = ssm.get_parameter(Name=parameter_path)['Parameter']['Value']
cognito = boto3.client('cognito-idp', region_name=region)
groups = cognito.list_groups(UserPoolId=user_pool_id)['Groups']
except Exception as e:
log.error(
f'Failed to list groups of user pool {user_pool_id} due to {e}'
)
else:
return groups
6 changes: 3 additions & 3 deletions backend/dataall/aws/handlers/ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ... import db
from ...db import models
from ...utils import Parameter
from ...tasks.share_manager import ShareManager
from ...tasks.data_sharing.data_sharing_service import DataSharingService

log = logging.getLogger('aws:ecs')

Expand All @@ -23,7 +23,7 @@ def __init__(self):
def approve_share(engine, task: models.Task):
envname = os.environ.get('envname', 'local')
if envname in ['local', 'dkrcompose']:
return ShareManager.approve_share(engine, task.targetUri)
return DataSharingService.approve_share(engine, task.targetUri)
else:
return Ecs.run_share_management_ecs_task(
envname, task.targetUri, 'approve_share'
Expand All @@ -34,7 +34,7 @@ def approve_share(engine, task: models.Task):
def reject_share(engine, task: models.Task):
envname = os.environ.get('envname', 'local')
if envname in ['local', 'dkrcompose']:
return ShareManager.reject_share(engine, task.targetUri)
return DataSharingService.reject_share(engine, task.targetUri)
else:
return Ecs.run_share_management_ecs_task(
envname, task.targetUri, 'reject_share'
Expand Down
Loading