This may have been answered before but looking through the issues I couldn't find exactly what I was looking for.
Basically, I am beginning to use attrs in pyattck and want to ingest the raw JSON properties on my models but also access them using better attribute names.
For example, I have this Actor data model and I would like to access attributes named x_mitre_ (e.g. x_mitre_contributors) as contributors on my object:
@define
class Actor(BaseModel):
aliases: List = field()
x_mitre_contributors: List = field(alias='contributors') # < Here's the example
revoked: bool = field(factory=bool)
description: AnyStr = field(factory=str)
x_mitre_modified_by_ref: Id = field(factory=Id)
x_mitre_deprecated: bool = field(factory=bool)
x_mitre_attack_spec_version: SemVersion = field(factory=SemVersion)
created_by_ref: Id = field(factory=Id)
country: List = field(factory=list)
operations: List = field(factory=list)
attribution_links: List = field(factory=list)
known_tools: List = field(factory=list)
targets: List = field(factory=list)
additional_comments: List = field(factory=list)
external_description: List = field(factory=list)
malwares: List = field(factory=list)
tools: List = field(factory=list)
techniques: List = field(factory=list)
What do you think ? Any alternative ways I can solve this with how attrs is currently implemented?
Also, I did try the field_transformer but I may be either not using it correctly or it can't be done from my point of view.
Thanks for the help!
This may have been answered before but looking through the issues I couldn't find exactly what I was looking for.
Basically, I am beginning to use attrs in pyattck and want to ingest the raw JSON properties on my models but also access them using better attribute names.
For example, I have this
Actordata model and I would like to access attributes namedx_mitre_(e.g.x_mitre_contributors) ascontributorson my object:What do you think ? Any alternative ways I can solve this with how attrs is currently implemented?
Also, I did try the
field_transformerbut I may be either not using it correctly or it can't be done from my point of view.Thanks for the help!