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

Expand config validation to most of the config #73

Merged
merged 3 commits into from
Sep 14, 2023

Conversation

shanejbrown
Copy link
Contributor

@shanejbrown shanejbrown commented Sep 12, 2023

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@shanejbrown shanejbrown force-pushed the full-validation branch 3 times, most recently from 0c32f3d to cafa374 Compare September 13, 2023 15:56
@shanejbrown shanejbrown marked this pull request as ready for review September 13, 2023 16:10

class SSHKey(BaseModel, extra='forbid'):
""" SSH key model """
file: Optional[str]
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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

@@ -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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

from pydantic import BaseModel, Field


class StepPypiPush(BaseModel):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this forbid extra?

Copy link
Contributor Author

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'):
Copy link
Contributor

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?

Copy link
Contributor Author

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.

""" Run model within a step """

xfail: Optional[bool]
services: Optional[Dict[str, Any]]
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

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]]]
Copy link
Contributor

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

Copy link
Contributor Author

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.

pull: Optional[bool]
platform: Optional[str]
platforms: Optional[List[str]]
inject: Optional[Dict[str, str]]
Copy link
Contributor

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.

Copy link
Contributor Author

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:
Copy link
Contributor

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?

Copy link
Contributor Author

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?.

Copy link
Contributor Author

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.

@shanejbrown shanejbrown merged commit 510e77a into adobe:main Sep 14, 2023
8 checks passed
@shanejbrown shanejbrown deleted the full-validation branch September 19, 2023 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants