Skip to content

Commit

Permalink
Update schedule and operation Schemas
Browse files Browse the repository at this point in the history
- Add a validation step to ensure the schedule field has a valid cron
  syntax.
- Change the obfuscator field to be required.
  • Loading branch information
sasirven authored and samuel-sirven-bib committed Sep 24, 2024
1 parent 5be2c4a commit 6bf8591
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/objects/c_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Meta:
planner = ma.fields.Nested(PlannerSchema())
start = ma.fields.DateTime(format=BaseObject.TIME_FORMAT, dump_only=True)
state = ma.fields.String()
obfuscator = ma.fields.String()
obfuscator = ma.fields.String(required=True)
autonomous = ma.fields.Integer()
chain = ma.fields.Function(lambda obj: [lnk.display for lnk in obj.chain])
auto_close = ma.fields.Boolean()
Expand Down
8 changes: 7 additions & 1 deletion app/objects/c_schedule.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid

import marshmallow as ma
from croniter import croniter

from app.objects.interfaces.i_object import FirstClassObjectInterface
from app.objects.c_operation import OperationSchema
Expand All @@ -13,9 +14,14 @@ class Meta:
unknown = ma.EXCLUDE

id = ma.fields.String()
schedule = ma.fields.Time(required=True)
schedule = ma.fields.String(required=True, metadata={"example": "5 4 * * *"})
task = ma.fields.Nested(OperationSchema())

@ma.validates('schedule')
def validate_schedule(self, value):
if not croniter.is_valid(value):
raise ma.ValidationError("Invalid cron syntax for schedule field.")

@ma.post_load
def build_schedule(self, data, **kwargs):
return None if kwargs.get('partial') is True else Schedule(**data)
Expand Down

0 comments on commit 6bf8591

Please sign in to comment.