|
22 | 22 |
|
23 | 23 | from api.utils import get_session, dict_diff |
24 | 24 | from api.exceptions import AlreadyExists, DryccException, ServiceUnavailable |
25 | | -from api.utils import CacheLock, DeployLock, generate_app_name, apply_tasks |
| 25 | +from api.utils import ( |
| 26 | + CacheLock, DeployLock, generate_app_name, apply_tasks, validate_reserved_names) |
26 | 27 | from scheduler import KubeHTTPException, KubeException |
27 | 28 | from .gateway import Gateway, Route |
28 | 29 | from .limit import LimitPlan |
@@ -88,32 +89,28 @@ def validate_app_id(value): |
88 | 89 | if not match: |
89 | 90 | raise ValidationError("App name must start with an alphabetic character, cannot end with a" |
90 | 91 | + " hyphen and can only contain a-z (lowercase), 0-9 and hyphens.") |
| 92 | + validate_reserved_names(value) |
91 | 93 |
|
92 | 94 |
|
93 | 95 | def validate_app_structure(value): |
94 | 96 | """Error if the dict values aren't ints >= 0""" |
95 | 97 | try: |
96 | | - if any(int(v) < 0 for v in value.values()): |
97 | | - raise ValueError("Must be greater than or equal to zero") |
| 98 | + for k, v in value.items(): |
| 99 | + if int(v) < 0: |
| 100 | + raise ValueError("Must be greater than or equal to zero") |
| 101 | + validate_reserved_names(k) |
98 | 102 | except ValueError as err: |
99 | 103 | raise ValidationError(str(err)) |
100 | 104 |
|
101 | 105 |
|
102 | | -def validate_reserved_names(value): |
103 | | - """A value cannot use some reserved names.""" |
104 | | - if value in settings.RESERVED_NAMES: |
105 | | - raise ValidationError('{} is a reserved name.'.format(value)) |
106 | | - |
107 | | - |
108 | 106 | class App(UuidAuditedModel): |
109 | 107 | """ |
110 | 108 | Application used to service requests on behalf of end-users |
111 | 109 | """ |
112 | 110 |
|
113 | 111 | owner = models.ForeignKey(User, on_delete=models.PROTECT) |
114 | 112 | id = models.SlugField(max_length=63, unique=True, null=True, |
115 | | - validators=[validate_app_id, |
116 | | - validate_reserved_names]) |
| 113 | + validators=[validate_app_id]) |
117 | 114 | structure = models.JSONField( |
118 | 115 | default=dict, blank=True, validators=[validate_app_structure]) |
119 | 116 |
|
|
0 commit comments