-
Notifications
You must be signed in to change notification settings - Fork 46
[Validation] moved fields pydantic to validation #438
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e785c38
- fixed + removed unnecessary pydantic validation
AmitJ98 b118d19
fixed gemini comments
AmitJ98 41cbc9e
add exclutions
AmitJ98 3ac7db3
Merge branch 'main' into name-validation
AmitJ98 f0d5d00
added validation tests
AmitJ98 881e714
fixed tal comments
AmitJ98 ea364a0
update tests
AmitJ98 d49bd42
linter
AmitJ98 0a565d3
comments
AmitJ98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
packages/mp/src/mp/validate/pre_build_validation/integrations/fields_validation.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import dataclasses | ||
| import re | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from mp.core.data_models.integrations.integration import Integration | ||
| from mp.core.exceptions import NonFatalValidationError | ||
| from mp.core.exclusions import get_param_display_name_regex, get_strict_script_display_name_regex | ||
|
|
||
| if TYPE_CHECKING: | ||
| from pathlib import Path | ||
|
|
||
| from mp.core.data_models.integrations.action.metadata import ActionMetadata | ||
| from mp.core.data_models.integrations.action.parameter import ActionParameter | ||
| from mp.core.data_models.integrations.connector.metadata import ConnectorMetadata | ||
| from mp.core.data_models.integrations.connector.parameter import ConnectorParameter | ||
| from mp.core.data_models.integrations.integration_meta.metadata import IntegrationMetadata | ||
| from mp.core.data_models.integrations.integration_meta.parameter import IntegrationParameter | ||
| from mp.core.data_models.integrations.job.metadata import JobMetadata | ||
| from mp.core.data_models.integrations.job.parameter import JobParameter | ||
|
|
||
| METADATA_NAME_REGEX: str = get_strict_script_display_name_regex() | ||
| PARAM_NAME_REGEX: str = get_param_display_name_regex() | ||
|
|
||
|
|
||
| @dataclasses.dataclass(slots=True, frozen=True) | ||
| class FieldsValidation: | ||
| name: str = "Fields Validation" | ||
|
|
||
| @staticmethod | ||
| def run(integration_path: Path) -> None: | ||
| """Strict integration fields names. | ||
|
|
||
| Args: | ||
| integration_path: The path of the integration to validate. | ||
|
|
||
| Raises: | ||
| NonFatalValidationError: If the integration doesn't have a documentation link. | ||
AmitJ98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| """ | ||
| integration: Integration = Integration.from_non_built_path(integration_path) | ||
|
|
||
| result: list[str] = [] | ||
| result.extend(_validate_action_metadata(list(integration.actions_metadata.values()))) | ||
| result.extend(_validate_connector_metadata(list(integration.connectors_metadata.values()))) | ||
| result.extend(_validate_job_metadata(list(integration.jobs_metadata.values()))) | ||
AmitJ98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| result.extend(_integration_metadata(integration.metadata)) | ||
|
|
||
| if result: | ||
| raise NonFatalValidationError("\n".join(result)) | ||
|
|
||
|
|
||
| def _validate_action_metadata(all_actions_metadata: list[ActionMetadata]) -> list[str]: | ||
| result: list[str] = [] | ||
| for metadata in all_actions_metadata: | ||
| if not re.match(METADATA_NAME_REGEX, metadata.name): | ||
| result.append( | ||
| f"Action name: {metadata.name} does not match the regex: {METADATA_NAME_REGEX}" | ||
| ) | ||
| result.extend(_validate_action_parameters(metadata.parameters)) | ||
|
|
||
| return result | ||
|
|
||
|
|
||
| def _validate_action_parameters(action_parameters: list[ActionParameter]) -> list[str]: | ||
| result: list[str] = [ | ||
| f"Action Parameter name: {parameter.name} does not match the regex: {PARAM_NAME_REGEX}" | ||
| for parameter in action_parameters | ||
| if not re.match(PARAM_NAME_REGEX, parameter.name) | ||
| ] | ||
| return result | ||
|
|
||
|
|
||
| def _validate_connector_metadata(all_connectors_metadata: list[ConnectorMetadata]) -> list[str]: | ||
| result: list[str] = [] | ||
| for metadata in all_connectors_metadata: | ||
| if not re.match(METADATA_NAME_REGEX, metadata.name): | ||
| result.append( | ||
| f"Connector name: {metadata.name} does not match the regex: {METADATA_NAME_REGEX}" | ||
| ) | ||
AmitJ98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| result.extend(_validate_connector_parameters(metadata.parameters)) | ||
| return result | ||
|
|
||
|
|
||
| def _validate_connector_parameters(connector_parameters: list[ConnectorParameter]) -> list[str]: | ||
| result: list[str] = [ | ||
| f"Connector Parameter name: {parameter.name} does not match the regex: {PARAM_NAME_REGEX}" | ||
| for parameter in connector_parameters | ||
| if not re.match(PARAM_NAME_REGEX, parameter.name) | ||
| ] | ||
| return result | ||
|
|
||
|
|
||
| def _validate_job_metadata(all_jobs_metadata: list[JobMetadata]) -> list[str]: | ||
| result: list[str] = [] | ||
| for metadata in all_jobs_metadata: | ||
| if not re.match(METADATA_NAME_REGEX, metadata.name): | ||
| result.append( | ||
| f"Job name: {metadata.name} does not match the regex: {METADATA_NAME_REGEX}" | ||
| ) | ||
| result.extend(_validate_job_parameters(metadata.parameters)) | ||
| return result | ||
|
|
||
|
|
||
| def _validate_job_parameters(job_parameters: list[JobParameter]) -> list[str]: | ||
| result: list[str] = [ | ||
| f"Job Parameter name: {parameter.name} does not match the regex: {PARAM_NAME_REGEX}" | ||
| for parameter in job_parameters | ||
| if not re.match(PARAM_NAME_REGEX, parameter.name) | ||
| ] | ||
| return result | ||
|
|
||
|
|
||
| def _integration_metadata(integration_metadata: IntegrationMetadata) -> list[str]: | ||
AmitJ98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| result: list[str] = [] | ||
| if not re.match(METADATA_NAME_REGEX, integration_metadata.name): | ||
| result.append( | ||
| f"Integration name: {integration_metadata.name} " | ||
| f"does not match the regex: {METADATA_NAME_REGEX}\n" | ||
| ) | ||
| result.extend(_integration_parameters(integration_metadata.parameters)) | ||
|
|
||
| return result | ||
|
|
||
|
|
||
| def _integration_parameters(integration_parameters: list[IntegrationParameter]) -> list[str]: | ||
| result: list[str] = [ | ||
| f"Integration Parameter name: {parameter.name} does not match the regex: {PARAM_NAME_REGEX}" | ||
| for parameter in integration_parameters | ||
| if not re.match(PARAM_NAME_REGEX, parameter.name) | ||
| ] | ||
| return result | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.