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

NAS-130449 / 24.10 / Improve validation for apps #43

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps_ci/scripts/catalog_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def validate_train_data(train_data):
except (json.JSONDecodeError, JsonValidationError) as e:
verrors.add(
'catalog_json',
f'Failed to validate contents of train data ({".".join(list(e.path))}): {e!r}'
f'Failed to validate contents of train data ({".".join([str(p) for p in e.path])}): {e!r}'
)
verrors.check()

Expand Down
27 changes: 27 additions & 0 deletions apps_validation/json_schema_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
APP_ITEM_JSON_SCHEMA = {
'type': 'object',
'properties': {
'categories': {
sonicaj marked this conversation as resolved.
Show resolved Hide resolved
'type': 'array',
'items': {'type': 'string'},
},
'tags': {
'type': 'array',
'items': {'type': 'string'},
},
'screenshots': {
'type': 'array',
'items': {'type': 'string'},
},
'icon_url': {'type': 'string'},
},
'required': ['categories'],
}
APP_METADATA_JSON_SCHEMA = {
'type': 'object',
'properties': {
Expand Down Expand Up @@ -79,6 +98,14 @@
'required': ['description', 'host_path'],
},
},
'screenshots': {
'type': 'array',
'items': {'type': 'string'},
},
'categories': {
'type': 'array',
'items': {'type': 'string'},
},
},
'required': [
'name', 'train', 'version', 'app_version', 'title', 'description', 'home',
Expand Down
14 changes: 7 additions & 7 deletions apps_validation/validate_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import json
import yaml

from jsonschema import validate as json_schema_validate, ValidationError as JsonValidationError

from apps_ci.names import CACHED_VERSION_FILE_NAME
from apps_exceptions import ValidationErrors

from .json_schema_utils import APP_ITEM_JSON_SCHEMA
from .validate_app_version import validate_catalog_item_version_data, validate_catalog_item_version
from .utils import validate_key_value_types


def validate_catalog_item(catalog_item_path: str, schema: str, train_name: str, validate_versions: bool = True):
Expand Down Expand Up @@ -37,12 +39,10 @@ def validate_catalog_item(catalog_item_path: str, schema: str, train_name: str,
with open(os.path.join(catalog_item_path, 'item.yaml'), 'r') as f:
item_config = yaml.safe_load(f.read())

# TODO: Remove validate key value type function and have json schemas for all of this
validate_key_value_types(
item_config, (
('categories', list), ('tags', list, False), ('screenshots', list, False),
), verrors, f'{schema}.item_config'
)
try:
json_schema_validate(item_config, APP_ITEM_JSON_SCHEMA)
except JsonValidationError as e:
verrors.add(f'{schema}.item_config', f'Invalid format specified for item configuration: {e}')

cached_version_file_path = os.path.join(catalog_item_path, CACHED_VERSION_FILE_NAME)
if os.path.exists(cached_version_file_path):
Expand Down
Loading