electionguard-api-python icon indicating copy to clipboard operation
electionguard-api-python copied to clipboard

Migrate manifest schema checking into API

Open keithrfung opened this issue 4 years ago • 4 comments

Feature Request

Is your feature request related to a problem? Please describe. These should get moved into to the electionguard-python-api https://github.com/microsoft/electionguard-python/blob/6d70f6602746bfcf840b59ce986f2c76c5fe58e5/src/electionguard/election_description_schema.json

https://github.com/microsoft/electionguard-python/blob/6d70f6602746bfcf840b59ce986f2c76c5fe58e5/src/electionguard/schema.py

Ideally with a schema folder. These could then be moved to electionguard root at a later point.

Accompanying PR to remove schema checking at base level.

Accompany issue: https://github.com/microsoft/electionguard-python/issues/384

keithrfung avatar Jul 12 '21 15:07 keithrfung

from typing import Any, Tuple
from os.path import join, dirname, realpath
from json import load
from jsonschema import validate
from jsonschema.exceptions import ValidationError

__all__ = ["get_election_description_schema", "validate_json_schema"]


def _load_schema(json_schema_file_name: str) -> Any:
    """Loads the given schema"""
    with open(join(dirname(realpath(__file__)), json_schema_file_name), "r") as file:
        schema = load(file)
    return schema


def get_election_description_schema() -> Any:
    """Get default schema for election description schema"""
    return _load_schema("election_description_schema.json")


def validate_json_schema(
    json_data: Any,
    json_schema: Any,
) -> Tuple[bool, str]:
    """Validate json schema"""
    try:
        validate(instance=json_data, schema=json_schema)
    except ValidationError as err:
        return (False, err.message)
    return (True, "Json schema validated")

keithrfung avatar Jul 21 '21 21:07 keithrfung

Hey @keithrfung I would like to take up this issue. As far as I have understood the description, those two files have to be moved into the api project under schema folder correct? But what is the above code that you have given?

bhushan-borole avatar Jul 29 '21 12:07 bhushan-borole

Hey @keithrfung, is this issue available I would like to work on it.

PradyumnaKrishna avatar Oct 03 '21 12:10 PradyumnaKrishna

@bhushan-borole and @PradyumnaKrishna Sorry I missed both of these.

The schemas are currently in the process of being moved to the github.com/microsoft/electionguard repositories. The idea is that there should be some schemas readily available at that level that can be used in the API to ensure the models are correct.

It would likely be wiser to help at that level first. However, this issue is still stands if either of you would like to work. The issue is about making a method to check the schema after a post is made to the call to check a manifest. The schema check itself is getting entirely removed from the bottom python level.

keithrfung avatar Oct 06 '21 15:10 keithrfung