Skip to content

Commit

Permalink
Ruff formatting (#1157)
Browse files Browse the repository at this point in the history
### Feature or Bugfix
- Bugfix

### Detail
In some of the last PRs ruff formatting has not been enforced and there
are some formatting errors. This PR is the result of running `make lint`
on the current `main` branch

### Relates

### Security
Please answer the questions below briefly where applicable, or write
`N/A`. Based on
[OWASP 10](https://owasp.org/Top10/en/).

- Does this PR introduce or modify any input fields or queries - this
includes
fetching data from storage outside the application (e.g. a database, an
S3 bucket)?
  - Is the input sanitized?
- What precautions are you taking before deserializing the data you
consume?
  - Is injection prevented by parametrizing queries?
  - Have you ensured no `eval` or similar functions are used?
- Does this PR introduce any functionality or component that requires
authorization?
- How have you ensured it respects the existing AuthN/AuthZ mechanisms?
  - Are you logging failed auth attempts?
- Are you using or adding any cryptographic features?
  - Do you use a standard proven implementations?
  - Are the used keys controlled by the customer? Where are they stored?
- Are you introducing any new policies/roles/users?
  - Have you used the least-privilege principle? How?


By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
  • Loading branch information
dlpzx authored Apr 9, 2024
1 parent c61b27d commit da194b6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
2 changes: 2 additions & 0 deletions backend/dataall/core/organizations/api/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ def update_organization(context, source, organizationUri=None, input=None):
def get_organization(context: Context, source, organizationUri=None):
return OrganizationService.get_organization(uri=organizationUri)


def get_organization_simplified(context: Context, source, organizationUri=None):
return OrganizationService.get_organization_simplified(uri=organizationUri)


def list_organizations(context: Context, source, filter=None):
if not filter:
filter = {'page': 1, 'pageSize': 5}
Expand Down
2 changes: 1 addition & 1 deletion backend/dataall/core/organizations/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@
fields=[
gql.Field(name='organizationUri', type=gql.ID),
gql.Field(name='label', type=gql.String),
gql.Field(name='name', type=gql.String)
gql.Field(name='name', type=gql.String),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,37 @@ def __init__(self, session, dataset: Dataset, share: ShareObject):

def notify_share_object_submission(self, email_id: str):
share_link_text = ''
if os.environ.get("frontend_domain_url"):
if os.environ.get('frontend_domain_url'):
share_link_text = f'<br><br> Please visit data.all <a href="{os.environ.get("frontend_domain_url")}/console/shares/{self.share.shareUri}">share link </a> to take action or view more details'
msg = f'User {email_id} SUBMITTED share request for dataset {self.dataset.label} for principal {self.share.principalId}'
subject = f'Data.all | Share Request Submitted for {self.dataset.label}'
email_notification_msg = msg + share_link_text

notifications = self._register_notifications(
notification_type=DataSharingNotificationType.SHARE_OBJECT_SUBMITTED.value, msg=msg)
notification_type=DataSharingNotificationType.SHARE_OBJECT_SUBMITTED.value, msg=msg
)

self._create_notification_task(subject=subject, msg=email_notification_msg)
return notifications

def notify_share_object_approval(self, email_id: str):
share_link_text = ''
if os.environ.get("frontend_domain_url"):
if os.environ.get('frontend_domain_url'):
share_link_text = f'<br><br> Please visit data.all <a href="{os.environ.get("frontend_domain_url")}/console/shares/{self.share.shareUri}">share link </a> to take action or view more details'
msg = f'User {email_id} APPROVED share request for dataset {self.dataset.label} for principal {self.share.principalId}'
subject = f'Data.all | Share Request Approved for {self.dataset.label}'
email_notification_msg = msg + share_link_text

notifications = self._register_notifications(
notification_type=DataSharingNotificationType.SHARE_OBJECT_APPROVED.value, msg=msg)
notification_type=DataSharingNotificationType.SHARE_OBJECT_APPROVED.value, msg=msg
)

self._create_notification_task(subject=subject, msg=email_notification_msg)
return notifications

def notify_share_object_rejection(self, email_id: str):
share_link_text = ''
if os.environ.get("frontend_domain_url"):
if os.environ.get('frontend_domain_url'):
share_link_text = f'<br><br> Please visit data.all <a href="{os.environ.get("frontend_domain_url")}/console/shares/{self.share.shareUri}">share link </a> to take action or view more details'
if self.share.status == ShareObjectStatus.Rejected.value:
msg = f'User {email_id} REJECTED share request for dataset {self.dataset.label} for principal {self.share.principalId}'
Expand All @@ -85,7 +87,8 @@ def notify_share_object_rejection(self, email_id: str):
email_notification_msg = msg + share_link_text

notifications = self._register_notifications(
notification_type=DataSharingNotificationType.SHARE_OBJECT_REJECTED.value, msg=msg)
notification_type=DataSharingNotificationType.SHARE_OBJECT_REJECTED.value, msg=msg
)

self._create_notification_task(subject=subject, msg=email_notification_msg)
return notifications
Expand All @@ -94,7 +97,8 @@ def notify_new_data_available_from_owners(self, s3_prefix):
msg = f'New data (at {s3_prefix}) is available from dataset {self.dataset.datasetUri} shared by owner {self.dataset.owner}'

notifications = self._register_notifications(
notification_type=DataSharingNotificationType.DATASET_VERSION.value, msg=msg)
notification_type=DataSharingNotificationType.DATASET_VERSION.value, msg=msg
)
return notifications

def _get_share_object_targeted_users(self):
Expand All @@ -114,7 +118,7 @@ def _register_notifications(self, notification_type, msg):
"""
notifications = []
for recipient in self.notification_target_users:
log.info(f"Creating notification for {recipient}, msg {msg}")
log.info(f'Creating notification for {recipient}, msg {msg}')
notifications.append(
NotificationRepository.create_notification(
session=self.session,
Expand Down Expand Up @@ -144,8 +148,8 @@ def _create_notification_task(self, subject, msg):
notification_recipient_groups_list = [self.dataset.SamlAdminGroupName, self.dataset.stewards]
notification_recipient_email_ids = []

if share_notification_config_type == "email":
if params.get("group_notifications", False) == True:
if share_notification_config_type == 'email':
if params.get('group_notifications', False) == True:
notification_recipient_groups_list.append(self.share.groupUri)
else:
notification_recipient_email_ids = [self.share.owner]
Expand All @@ -158,7 +162,7 @@ def _create_notification_task(self, subject, msg):
'subject': subject,
'message': msg,
'recipientGroupsList': notification_recipient_groups_list,
'recipientEmailList': notification_recipient_email_ids
'recipientEmailList': notification_recipient_email_ids,
},
)
self.session.add(notification_task)
Expand Down
26 changes: 11 additions & 15 deletions deploy/stacks/param_store_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import string

import boto3
from aws_cdk import (
aws_ssm,
custom_resources as cr
)
from aws_cdk import aws_ssm, custom_resources as cr

from .pyNestedStack import pyNestedClass
from .deploy_config import deploy_config
Expand Down Expand Up @@ -134,20 +131,19 @@ def __init__(
)
if prod_sizing:
cr.AwsCustomResource(
self,
"SSMParamSettingHighThroughput",
self,
'SSMParamSettingHighThroughput',
on_update=cr.AwsSdkCall(
service="SSM",
action="UpdateServiceSettingCommand",
parameters={
"SettingId": "/ssm/parameter-store/high-throughput-enabled",
"SettingValue": "true"
},
physical_resource_id=cr.PhysicalResourceId.of(f"ssm-high-throughput-{self.account}-{self.region}")
service='SSM',
action='UpdateServiceSettingCommand',
parameters={'SettingId': '/ssm/parameter-store/high-throughput-enabled', 'SettingValue': 'true'},
physical_resource_id=cr.PhysicalResourceId.of(f'ssm-high-throughput-{self.account}-{self.region}'),
),
policy=cr.AwsCustomResourcePolicy.from_sdk_calls(
resources=[f"arn:aws:ssm:{self.region}:{self.account}:servicesetting/ssm/parameter-store/high-throughput-enabled"]
)
resources=[
f'arn:aws:ssm:{self.region}:{self.account}:servicesetting/ssm/parameter-store/high-throughput-enabled'
]
),
)


Expand Down

0 comments on commit da194b6

Please sign in to comment.