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

Add attribute alias to attrs.field #953

Closed
MSAdministrator opened this issue Apr 29, 2022 · 3 comments
Closed

Add attribute alias to attrs.field #953

MSAdministrator opened this issue Apr 29, 2022 · 3 comments

Comments

@MSAdministrator
Copy link

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!

@hynek
Copy link
Member

hynek commented Apr 29, 2022

That’s #950, no?

@MSAdministrator
Copy link
Author

Actually you are correct - not sure why my searching sucks but thanks!

@hynek
Copy link
Member

hynek commented Apr 29, 2022

Great, I'm at PyCon but I'll try to review that PR at the sprints (famous last words).

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

No branches or pull requests

2 participants