Skip to content

Commit

Permalink
Add a validator for the manifest version (#12788)
Browse files Browse the repository at this point in the history
* Add a validator for the manifest version

* Remove unused imports
  • Loading branch information
FlorentClarret authored and steveny91 committed Oct 27, 2022
1 parent 2749663 commit 1f6fdf8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ...constants import get_root
from ...datastructures import JSONDict
from ...manifest_validator import get_all_validators
from ...manifest_validator.constants import V1_STRING, V2_STRING
from ...manifest_validator.constants import V2_STRING
from ...testing import process_checks_option
from ...utils import complete_valid_checks
from ..console import (
Expand Down Expand Up @@ -75,10 +75,6 @@ def manifest(ctx, check, fix):
continue

version = decoded.get('manifest_version', V2_STRING)
if version == V1_STRING:
file_failures += 1
display_queue.append((echo_failure, 'Manifest version must be >= 2.0.0'))

all_validators = get_all_validators(ctx, version, is_extras, is_marketplace)

for validator in all_validators:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# (C) Datadog, Inc. 2021-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from .common.validator import VersionValidator
from .constants import V2_STRING
from .v2.validator import get_v2_validators


def get_all_validators(ctx, version_string, is_extras=False, is_marketplace=False):
return get_v2_validators(ctx, is_extras, is_marketplace)
validators = [VersionValidator()]

if version_string == V2_STRING:
validators.extend(get_v2_validators(ctx, is_extras, is_marketplace))

return validators
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ...datastructures import JSONDict
from ...git import git_show_file
from ...utils import get_metadata_file, has_logs, is_metric_in_metadata_file, read_metadata_rows
from ..constants import V1, V2
from ..constants import V1, V1_STRING, V2, V2_STRING


class ValidationResult(object):
Expand Down Expand Up @@ -311,3 +311,9 @@ def validate(self, check_name, decoded, fix):
+ ' or define the logs properly'
)
self.fail(output)


class VersionValidator(BaseManifestValidator):
def validate(self, check_name, decoded, fix):
if decoded.get('manifest_version', V2_STRING) == V1_STRING:
self.fail('Manifest version must be >= 2.0.0')

0 comments on commit 1f6fdf8

Please sign in to comment.