Skip to content

Commit

Permalink
Rename variables, remove import.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrystinne committed Nov 10, 2023
1 parent 46532e8 commit 0f08483
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ AWS_CLOUD_FORMATION=url

# AWS credentials (Access Key and Secret Key): Configure AWS credentials in the AWS CLI profile using the 'aws configure' command.
AWS_PROFILE=
BUCKET_OWNER_ID=
# AWS account ID of the bucket owner
S3_BUCKET_OWNER_ID=
# Path to the file containing credentials for AWS
# (https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html#shared-credentials-file)
AWS_SHARED_CREDENTIALS_FILE=
# The default bucket name to store projects with an 'OPEN' access policy.
S3_OPEN_ACCESS_BUCKET=
# The default bucket name to store logs and metrics related to project usage.
S3_SERVER_ACCESS_LOGS=
S3_SERVER_ACCESS_LOG_BUCKET=

# Datacite
# Used to assign the DOIs
Expand Down
1 change: 0 additions & 1 deletion physionet-django/console/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
from physionet.enums import LogCategory
from console import forms, utility, services
from console.forms import ProjectFilterForm, UserFilterForm
from console import views
from project.cloud.s3 import (
create_s3_bucket,
upload_project_to_S3,
Expand Down
4 changes: 2 additions & 2 deletions physionet-django/physionet/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,13 @@

AWS_PROFILE = config('AWS_PROFILE', default=False)

BUCKET_OWNER_ID = config('BUCKET_OWNER_ID', default=False)
S3_BUCKET_OWNER_ID = config('S3_BUCKET_OWNER_ID', default=False)

# Bucket name for the S3 bucket containing the open access data
S3_OPEN_ACCESS_BUCKET = config('S3_OPEN_ACCESS_BUCKET', default=False)

# Bucket name to store logs and metrics related to project usage.
S3_SERVER_ACCESS_LOGS = config('S3_SERVER_ACCESS_LOGS', default=False)
S3_SERVER_ACCESS_LOG_BUCKET = config('S3_SERVER_ACCESS_LOG_BUCKET', default=False)

# Header tags for the AWS lambda function that grants access to S3 storage
AWS_HEADER_KEY = config('AWS_KEY', default=False)
Expand Down
19 changes: 7 additions & 12 deletions physionet-django/project/cloud/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def has_s3_credentials():
"""
return all([
settings.AWS_PROFILE,
settings.BUCKET_OWNER_ID,
settings.S3_BUCKET_OWNER_ID,
settings.S3_OPEN_ACCESS_BUCKET,
settings.S3_SERVER_ACCESS_LOGS,
settings.S3_SERVER_ACCESS_LOG_BUCKET,
])


Expand Down Expand Up @@ -551,18 +551,13 @@ def put_public_access_block(client, bucket_name, configuration):
client object.
bucket_name (str): The name of the S3 bucket
to configure.
configuration (bool): The desired configuration for
public access. Set to 'True' to allow public access
or 'False' to restrict public access.
configuration (bool): The PublicAccessBlock configuration
to be applied to the S3 bucket.
Returns:
None
Note:
- To create a bucket that allows public access, you must
set 'configuration' to 'True' for all four settings:
'BlockPublicAcls', 'IgnorePublicAcls', 'BlockPublicPolicy',
and 'RestrictPublicBuckets'.
- Ensure that AWS credentials (Access Key and Secret Key)
are properly configured for the provided 'client'.
"""
Expand Down Expand Up @@ -673,16 +668,16 @@ def upload_project_to_S3(project):
if check_s3_bucket_exists(project):
# Check bucket ownership
bucket_owner_id = get_bucket_owner(s3, bucket_name)
if bucket_owner_id != settings.BUCKET_OWNER_ID:
if bucket_owner_id != settings.S3_BUCKET_OWNER_ID:
raise Exception("Bucket is owned by another AWS account.")
if bucket_owner_id is None or bucket_owner_id == settings.BUCKET_OWNER_ID:
if bucket_owner_id is None or bucket_owner_id == settings.S3_BUCKET_OWNER_ID:
try:
create_s3_bucket(s3, bucket_name)
except s3.exceptions.BucketAlreadyOwnedByYou:
pass

put_bucket_logging(
s3, bucket_name, settings.S3_SERVER_ACCESS_LOGS, bucket_name + "/logs/"
s3, bucket_name, settings.S3_SERVER_ACCESS_LOG_BUCKET, bucket_name + "/logs/"
)
# upload files to bucket
folder_path = project.file_root()
Expand Down

0 comments on commit 0f08483

Please sign in to comment.