-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1187 from shreyabiradar07/local_monitoring_tests
Include Local monitoring tests for Datasource APIs
- Loading branch information
Showing
41 changed files
with
1,210 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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 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 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,36 @@ | ||
import_metadata_json_schema = { | ||
"type": "object", | ||
"properties": { | ||
"datasources": { | ||
"type": "object", | ||
"patternProperties": { | ||
"^[a-zA-Z0-9_-]+$": { | ||
"type": "object", | ||
"properties": { | ||
"datasource_name": { | ||
"type": "string", | ||
"pattern": "^[a-zA-Z0-9_-]+$" | ||
}, | ||
"clusters": { | ||
"type": "object", | ||
"patternProperties": { | ||
"^[a-zA-Z0-9_-]+$": { | ||
"type": "object", | ||
"properties": { | ||
"cluster_name": { | ||
"type": "string", | ||
"pattern": "^[a-zA-Z0-9_-]+$" | ||
} | ||
}, | ||
"required": ["cluster_name"] | ||
} | ||
} | ||
} | ||
}, | ||
"required": ["datasource_name", "clusters"] | ||
} | ||
} | ||
} | ||
}, | ||
"required": ["datasources"] | ||
} |
This file contains 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,68 @@ | ||
""" | ||
Copyright (c) 2023, 2023 Red Hat, IBM Corporation and others. | ||
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. | ||
""" | ||
import json | ||
import jsonschema | ||
from jsonschema import FormatChecker | ||
from jsonschema.exceptions import ValidationError | ||
from helpers.import_metadata_json_schema import import_metadata_json_schema | ||
|
||
JSON_NULL_VALUES = ("is not of type 'string'", "is not of type 'integer'", "is not of type 'number'") | ||
VALUE_MISSING = " cannot be empty or null!" | ||
|
||
def validate_import_metadata_json(import_metadata_json, json_schema): | ||
errorMsg = "" | ||
try: | ||
# create a validator with the format checker | ||
print("Validating json against the json schema...") | ||
validator = jsonschema.Draft7Validator(json_schema, format_checker=FormatChecker()) | ||
|
||
# validate the JSON data against the schema | ||
errors = "" | ||
errors = list(validator.iter_errors(import_metadata_json)) | ||
print("Validating json against the json schema...done") | ||
errorMsg = validate_import_metadata_json_values(import_metadata_json) | ||
|
||
if errors: | ||
custom_err = ValidationError(errorMsg) | ||
errors.append(custom_err) | ||
return errors | ||
else: | ||
return errorMsg | ||
except ValidationError as err: | ||
print("Received a VaidationError") | ||
|
||
# Check if the exception is due to empty or null required parameters and prepare the response accordingly | ||
if any(word in err.message for word in JSON_NULL_VALUES): | ||
errorMsg = "Parameters" + VALUE_MISSING | ||
return errorMsg | ||
# Modify the error response in case of additional properties error | ||
elif str(err.message).__contains__('('): | ||
errorMsg = str(err.message).split('(') | ||
return errorMsg[0] | ||
else: | ||
return err.message | ||
|
||
def validate_import_metadata_json_values(metadata): | ||
validationErrorMsg = "" | ||
|
||
for key in metadata.keys(): | ||
|
||
# Check if any of the key is empty or null | ||
if not (str(metadata[key]) and str(metadata[key]).strip()): | ||
validationErrorMsg = ",".join([validationErrorMsg, "Parameters" + VALUE_MISSING]) | ||
|
||
return validationErrorMsg.lstrip(',') | ||
|
This file contains 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 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,34 @@ | ||
list_datasources_json_schema = { | ||
"type": "object", | ||
"properties": { | ||
"version": { | ||
"type": "string" | ||
}, | ||
"datasources": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"provider": { | ||
"type": "string" | ||
}, | ||
"serviceName": { | ||
"type": "string" | ||
}, | ||
"namespace": { | ||
"type": "string" | ||
}, | ||
"url": { | ||
"type": "string", | ||
"format": "uri" | ||
} | ||
}, | ||
"required": ["name", "provider", "serviceName", "namespace", "url"] | ||
} | ||
} | ||
}, | ||
"required": ["version", "datasources"] | ||
} |
Oops, something went wrong.