Skip to content

Commit

Permalink
Add a migration file that alters the 'aws_id' field in the CloudInfor…
Browse files Browse the repository at this point in the history
…mation model. The modification includes the addition of the 'validate_aws_id' validator to ensure AWS ID validity at the model level.
  • Loading branch information
Chrystinne committed Oct 4, 2023
1 parent 88fae67 commit 1ce6f76
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.1.10 on 2023-10-04 21:14

from django.db import migrations, models
import user.validators


class Migration(migrations.Migration):
dependencies = [
("user", "0056_remove_credentialreview_appears_correct_and_more"),
]

operations = [
migrations.AlterField(
model_name="cloudinformation",
name="aws_id",
field=models.CharField(
blank=True,
default=None,
max_length=60,
null=True,
validators=[user.validators.validate_aws_id],
),
),
]
9 changes: 8 additions & 1 deletion physionet-django/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,14 @@ class CloudInformation(models.Model):
on_delete=models.CASCADE)
gcp_email = models.OneToOneField('user.AssociatedEmail', related_name='gcp_email',
on_delete=models.SET_NULL, null=True)
aws_id = models.CharField(max_length=60, null=True, blank=True, default=None, validators=[validators.validate_aws_id])
aws_id = models.CharField(
max_length=60,
null=True,
blank=True,
default=None,
validators=[validators.validate_aws_id],
)

class Meta:
default_permissions = ()

Expand Down
5 changes: 4 additions & 1 deletion physionet-django/user/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,13 @@ def is_institutional_email(value):
except ValidationError:
return False


def validate_aws_id(value):
""""
Validate an AWS ID.
"""
aws_id_pattern = r"\b\d{12}\b"
if value is not None and not re.search(aws_id_pattern, value):
raise ValidationError('Invalid AWS ID. Please provide a valid AWS ID, which should be a 12-digit number.')
raise ValidationError(
"Invalid AWS ID. Please provide a valid AWS ID, which should be a 12-digit number."
)

0 comments on commit 1ce6f76

Please sign in to comment.