Skip to content

Commit

Permalink
Configure server access logging for an S3 bucket. It enables access l…
Browse files Browse the repository at this point in the history
…ogging, directing logs to the Remove unnecessary methods. Raise an exception if the S3 credentials are undefined.
  • Loading branch information
Chrystinne committed Oct 24, 2023
1 parent fa6fbf9 commit 77bb3be
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 381 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ AWS_PROFILE=
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=

# Datacite
# Used to assign the DOIs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ <h5 class="card-title mt-3 mb-1">AWS</h5>
are set.)
</p>
{% elif not project.aws.bucket_name %}
<p>Create a bucket on AWS to store the files associated with this project. dsjkbjak {{project.id}} {{project.aws.bucket_name}} {{project.aws.sent_files}}</p>
<p>Create a bucket on AWS to store the files associated with this project.</p>
<form action="" method="post">
{% csrf_token %}
<button class="btn btn-primary" name="aws-bucket" value='{{project.slug}}'
Expand Down
17 changes: 5 additions & 12 deletions physionet-django/console/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@
get_bucket_name,
check_s3_bucket_exists,
update_bucket_policy,
get_bucket_name_and_prefix,
check_s3_bucket_with_prefix_exists,
has_s3_credentials,
)

Expand Down Expand Up @@ -797,13 +795,13 @@ def send_files_to_aws(pid):
"""
project = PublishedProject.objects.get(id=pid)
# Create or get the associated AWS object
aws_instance = AWS.objects.get_or_create(project=project)
AWS.objects.get_or_create(project=project)
upload_project_to_S3(project)
aws_instance.sent_files = True
aws_instance.finished_datetime = timezone.now()
project.aws.sent_files = True
project.aws.finished_datetime = timezone.now()
if project.compressed_storage_size:
aws_instance.sent_zip = True
aws_instance.save()
project.aws.sent_zip = True
project.aws.save()


@associated_task(PublishedProject, "pid", read_only=True)
Expand Down Expand Up @@ -902,18 +900,13 @@ def manage_published_project(request, project_slug, version):
project = PublishedProject.objects.get(slug=project_slug, version=version)
except PublishedProject.DoesNotExist:
raise Http404()
# s3_bucket_exists = None
# s3_bucket_name = None
user = request.user
passphrase = ''
anonymous_url = project.get_anonymous_url()
topic_form = forms.TopicForm(project=project)
topic_form.set_initial()
deprecate_form = None if project.deprecated_files else forms.DeprecateFilesForm()
has_credentials = bool(settings.GOOGLE_APPLICATION_CREDENTIALS)
# if has_s3_credentials():
# s3_bucket_exists = check_s3_bucket_with_prefix_exists(project)
# s3_bucket_name = get_bucket_name_and_prefix(project)
data_access_form = forms.DataAccessForm(project=project)
contact_form = forms.PublishedProjectContactForm(project=project,
instance=project.contact)
Expand Down
3 changes: 3 additions & 0 deletions physionet-django/physionet/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@
# 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)

# Header tags for the AWS lambda function that grants access to S3 storage
AWS_HEADER_KEY = config('AWS_KEY', default=False)
AWS_HEADER_VALUE = config('AWS_VALUE', default=False)
Expand Down
Loading

0 comments on commit 77bb3be

Please sign in to comment.