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

#299-feature/presentation submission dynamic handler #314

Draft
wants to merge 11 commits into
base: refac
Choose a base branch
from

Conversation

LadyCodesItBetter
Copy link
Collaborator

This PR introduces enhancements to the PresentationSubmission class to improve error handling and dynamic handler initialization based on descriptor_map.

Key points:

  • handlers are dynamically created for each descriptor_map entry based on the format key.
  • handlers attribute contains a dictionary where the key is the index of the descriptor, and the value is the respective handler instance.


logger = logging.getLogger(__name__)

class PresentationSubmission:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't put the classes within the init file

we are going to refactor all the code within this project to remove this code-style in favour or a proper division of files by scopes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

from pydantic import ValidationError
import yaml
import importlib
from typing import Dict, Any
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing Dict is deprecated since Python 3.9 and this project officially supports Python 3.10+ only - use dict instead (no import required).
https://docs.python.org/3/library/typing.html#aliases-to-built-in-types

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go ahead using dict without any import

Raises:
FileNotFoundError: If the configuration file is not found.
"""
config_path = os.path.join(os.path.dirname(__file__), "config.yml")
Copy link
Collaborator

@Zicchio Zicchio Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of having a class configurable by editing an obscure configuration file in the installed class project that is available who-knows-where based on what pip (or other build tool) is doing and might possibly be inside a container? Just use a config.py file at this point - it is functionally the same thing.

@peppelinux @LadyCodesItBetter I'm not sure here what is the intended design goal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the intended propose is for a generic python package, not necessarly used in the iam proxy context

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point still stands. Assume I am using the project as a package, that is, I am using it with pip install pyeudiw as a part of my project.
To change the configuration of this class, I have to go in the location where pip placed config.yaml (which is usually inside the site-packages) and and edit it. This is IMO very convoluted and only doable by technically advanced users.

@Zicchio
Copy link
Collaborator

Zicchio commented Jan 16, 2025

handlers attribute contains a dictionary where the key is the index of the descriptor, and the value is the respective handler instance.

Sorry if the question is dull, but... what is an handler?
Let's say I create an instance of PresentationSubmission. How and when am I supposed to use self.handler? What should they do?

# Dynamically load the module and class
module = importlib.import_module(module_name)
cls = getattr(module, class_name)
handlers[index] = cls() # Instantiate the class
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK the fact that each handler is a class initialized with an empty constructor implies that handlers are functionally just namespace for static methods. It's impossible to known what they should do without doing introspection on what aforementioned namespace contains.

@@ -0,0 +1,121 @@
import pytest
Copy link
Collaborator

@Zicchio Zicchio Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I'm wrong but if a test file name does not start with test_ or ends with _test.py then pytest will NOT execute it for unit tests (altough ci-cd pipeline might change this behaviour - I'm not 100% sure how unit tests are configured here).

In doubt, this file should be named test_presentation_submission.py
https://docs.pytest.org/en/stable/explanation/goodpractices.html#test-discovery

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that _test doesn't get loaded

class PresentationSubmissionSchema(BaseModel):
id: str
definition_id: str
descriptor_map: List[DescriptorSchema]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List is also deprecated: use list instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go ahead using list without any import

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Define Presentation Submission Requirements for Verifiable Presentations
3 participants