-
Notifications
You must be signed in to change notification settings - Fork 16
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
Expand config validation to most of the config #73
Conversation
0c32f3d
to
cafa374
Compare
cafa374
to
6ddbe51
Compare
|
||
class SSHKey(BaseModel, extra='forbid'): | ||
""" SSH key model """ | ||
file: Optional[str] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these working without assigning "None" to the value? That's surprising to me, I thought newer pydantic versions required it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it appears to be working. But I don't quite understand what you are saying. Can you give me an example of what you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had to do file: Optional[str] = None
to get it working in some cases (newer pydantic versions I thought)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is using an older version of pydantic
version 1.10.11
because that is the highest that python-on-whales
allows currently. That may be why I am able to get away with using that syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yes, I knew that
buildrunner/validation/config.py
Outdated
@@ -188,5 +157,5 @@ def validate_config(**kwargs) -> Errors: | |||
try: | |||
Config(**kwargs) | |||
except ValidationError as exc: | |||
errors = _add_validation_errors(exc) | |||
errors = add_validation_errors(exc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really adding validation errors or just getting validation errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are correct. It really just gets the errors. I'll make the change.
buildrunner/validation/step.py
Outdated
from pydantic import BaseModel, Field | ||
|
||
|
||
class StepPypiPush(BaseModel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this forbid extra?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that. I just wasn't sure if the documentation was complete on that so I erred on the side of having it allow more. I'll add that in and hope for the best. :)
|
||
|
||
class Config(BaseModel): | ||
""" Top level config model """ | ||
|
||
# Unclear if this is actively used | ||
class GithubModel(BaseModel, extra='forbid'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool syntax, didn't know that was possible. Should the Config top-level class also forbid extra?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just afraid that I may have missed something. I'll add it in to the top-level config. Then if it fails we can address where the issue is, either update the validation code, the documentation or the buildrunner config with the issue.
buildrunner/validation/step.py
Outdated
""" Run model within a step """ | ||
|
||
xfail: Optional[bool] | ||
services: Optional[Dict[str, Any]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this should be Optional[Dict[str, Service]]
or something so that the services get validated as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might share a lot with run
as well, so maybe there can be a base class that is shared between them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this update, to validate the Service portion.
buildrunner/validation/step.py
Outdated
ports: Optional[Dict[str, str]] | ||
volumes_from: Optional[List[str]] | ||
ssh_keys: Optional[List[str]] = Field(alias='ssh-keys') | ||
artifacts: Optional[Dict[str, Union[Artifact, None]]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this Optional[Dict[str, Optional[Artifact]]]
? i.e. Optional instead of the Union with None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I like that. It is more concise. I'll make the update.
buildrunner/validation/step.py
Outdated
pull: Optional[bool] | ||
platform: Optional[str] | ||
platforms: Optional[List[str]] | ||
inject: Optional[Dict[str, str]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be possible to use inject with a key but no value, and it defaults to the working dir, but I could be remembering wrong here. It might be worth checking inject in various buildrunner files in git.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find a buildrunner file which had a inject value as None. But I am ok with making this check less strict. I'll make the value Optional.
config_yaml = """ | ||
version: 2.0 | ||
steps: | ||
my-build-step: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice that you're testing the docs, but maybe this should be a separate file that we can then load into the docs as well directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a great idea. Are you thinking that the README.rst
would just have a link to the example file?.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say it's not an exact copy and paste from the README I had to make some edits to make it valid YAML.
Description
Expanded configuration file validation to most of the available fields. This has the potential of breaking existing builds which are using buildrunner in a non-supported way, contrary to the written buildrunner documentation. This will fail immediately if the configuration is invalid for any reason.
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: