Skip to content

Commit

Permalink
Add validation to Shard, Service, Project, and Farm name
Browse files Browse the repository at this point in the history
  • Loading branch information
kfdm committed Jan 16, 2020
1 parent 68a0467 commit bd4dab6
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
66 changes: 66 additions & 0 deletions promgen/migrations/0012_validation_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright (c) 2020 LINE Corporation
# These sources are released under the terms of the MIT license: see LICENSE
# Generated by Django 2.2.9 on 2020-01-16 06:35

import django.core.validators
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [("promgen", "0011_notifier_counts")]

operations = [
migrations.AlterField(
model_name="farm",
name="name",
field=models.CharField(
max_length=128,
validators=[
django.core.validators.RegexValidator(
"^[0-9a-zA-Z_]*$", "Only alphanumeric characters are allowed."
)
],
),
),
migrations.AlterField(
model_name="project",
name="name",
field=models.CharField(
max_length=128,
unique=True,
validators=[
django.core.validators.RegexValidator(
"^[0-9a-zA-Z_]*$", "Only alphanumeric characters are allowed."
)
],
),
),
migrations.AlterField(
model_name="service",
name="name",
field=models.CharField(
max_length=128,
unique=True,
validators=[
django.core.validators.RegexValidator(
"^[0-9a-zA-Z_]*$", "Only alphanumeric characters are allowed."
)
],
),
),
migrations.AlterField(
model_name="shard",
name="name",
field=models.CharField(
max_length=128,
unique=True,
validators=[
django.core.validators.RegexValidator(
"^[0-9a-zA-Z_]*$", "Only alphanumeric characters are allowed."
)
],
),
),
]
8 changes: 4 additions & 4 deletions promgen/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class Meta:


class Shard(models.Model):
name = models.CharField(max_length=128, unique=True)
name = models.CharField(max_length=128, unique=True, validators=[validators.alphanumeric])
url = models.URLField(max_length=256)
proxy = models.BooleanField(default=False,
help_text='Queries can be proxied to these shards')
Expand All @@ -185,7 +185,7 @@ def __str__(self):


class Service(models.Model):
name = models.CharField(max_length=128, unique=True)
name = models.CharField(max_length=128, unique=True, validators=[validators.alphanumeric])
description = models.TextField(blank=True)
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, default=None)

Expand Down Expand Up @@ -219,7 +219,7 @@ def default(cls, service_name='Default', shard_name='Default'):


class Project(models.Model):
name = models.CharField(max_length=128, unique=True)
name = models.CharField(max_length=128, unique=True, validators=[validators.alphanumeric])
description = models.TextField(blank=True)
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, default=None)

Expand All @@ -241,7 +241,7 @@ def __str__(self):


class Farm(models.Model):
name = models.CharField(max_length=128)
name = models.CharField(max_length=128, validators=[validators.alphanumeric])
source = models.CharField(max_length=128)

class Meta:
Expand Down

0 comments on commit bd4dab6

Please sign in to comment.