Skip to content

Commit

Permalink
Removing version information from open bucket prefixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrystinne committed Oct 16, 2023
1 parent bf6b923 commit 1b8176c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
16 changes: 7 additions & 9 deletions physionet-django/console/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,12 +796,14 @@ def send_files_to_aws(pid):
up for the S3 client.
"""
project = PublishedProject.objects.get(id=pid)
# Create or get the associated AWS object
aws_instance = AWS.objects.get_or_create(project=project)
upload_project_to_S3(project)
project.aws.sent_files = True
project.aws.finished_datetime = timezone.now()
aws_instance.sent_files = True
aws_instance.finished_datetime = timezone.now()
if project.compressed_storage_size:
project.aws.sent_zip = True
project.aws.save()
aws_instance.sent_zip = True
aws_instance.save()


@associated_task(PublishedProject, "pid", read_only=True)
Expand Down Expand Up @@ -1133,17 +1135,13 @@ def aws_bucket_management(request, project, user):
bucket_name = get_bucket_name(project)

try:
aws_object = AWS.objects.get(bucket_name=bucket_name)
AWS.objects.get(bucket_name=bucket_name)
messages.success(request, "The bucket already exists. Resending the \
files for the project {0}.".format(project))
except AWS.DoesNotExist:
if check_s3_bucket_exists(project):
LOGGER.info("The bucket {0} already exists, skipping bucket \
creation".format(bucket_name))
# else:
# create_bucket(project.slug, project.version, project.title, is_private)
# messages.success(request, "The GCP bucket for project {0} was \
# successfully created.".format(project))
AWS.objects.create(project=project, bucket_name=bucket_name,
is_private=is_private)

Expand Down
13 changes: 8 additions & 5 deletions physionet-django/project/cloud/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,25 @@ def create_s3_client():
session = boto3.Session(
profile_name=settings.AWS_PROFILE
)
s3 = session.client("s3")
s3 = session.client("s3", region_name="us-east-1")
return s3
else:
return None


def create_s3_resource():
"""
Creates and returns an AWS S3 resource if valid credentials are available.
Returns:
boto3.resources.base.ServiceResource or None:
An S3 resource if credentials are valid, otherwise None.
"""
if has_s3_credentials():
session = boto3.Session(
profile_name=settings.AWS_PROFILE
)
s3 = session.resource("s3")
s3 = session.resource("s3", region_name="us-east-1")
return s3
else:
return None
Expand Down Expand Up @@ -712,13 +716,12 @@ def upload_project_to_S3(project):

# upload files to bucket
folder_path = project.project_file_root()
project_name = project.slug + "-" + project.version

# set the prefix only for the projects
# in the open data bucket
s3_prefix = ""
if project.access_policy == AccessPolicy.OPEN:
s3_prefix = f"{project_name}/"
s3_prefix = f"{project.slug}/"
send_files_to_s3(folder_path, s3_prefix, bucket_name)


Expand Down
2 changes: 1 addition & 1 deletion physionet-django/project/migrations/0071_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Migration(migrations.Migration):
"project",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name='aws',
related_name='aws',
to='project.PublishedProject'
),
),
Expand Down
7 changes: 4 additions & 3 deletions physionet-django/project/modelcomponents/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ class GCP(models.Model):
class Meta:
default_permissions = ()


class AWS(models.Model):
"""
Store all of the AWS information with a relation to a project.
"""
project = models.OneToOneField('project.PublishedProject', related_name='aws',
on_delete=models.CASCADE)
project = models.OneToOneField(
"project.PublishedProject", related_name="aws", on_delete=models.CASCADE
)
bucket_name = models.CharField(max_length=150, null=True)
is_private = models.BooleanField(default=False)
sent_zip = models.BooleanField(default=False)
Expand Down

0 comments on commit 1b8176c

Please sign in to comment.