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

Migrate manifest schema checking into API #160

Open
keithrfung opened this issue Jul 12, 2021 · 4 comments
Open

Migrate manifest schema checking into API #160

keithrfung opened this issue Jul 12, 2021 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest Issues for the Hacktoberfest help wanted Extra attention is needed

Comments

@keithrfung
Copy link
Collaborator

keithrfung commented Jul 12, 2021

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: Election-Tech-Initiative/electionguard-python#384

@keithrfung
Copy link
Collaborator Author

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")

@bhushan-borole
Copy link

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?

@lmarie79 lmarie79 added enhancement New feature or request hacktoberfest Issues for the Hacktoberfest help wanted Extra attention is needed labels Sep 23, 2021
@PradyumnaKrishna
Copy link

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

@keithrfung
Copy link
Collaborator Author

@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 keithrfung changed the title Schema checking of manifest should exist here Migrate manifest schema checking into within the API itself Oct 8, 2021
@keithrfung keithrfung added the good first issue Good for newcomers label Oct 8, 2021
@keithrfung keithrfung changed the title Migrate manifest schema checking into within the API itself Migrate manifest schema checking into API Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest Issues for the Hacktoberfest help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants