Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Add validation to Shard, Service, Project, and Farm name #228

Merged
merged 1 commit into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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