Skip to content

Support all attributes kind in protocols #68

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

Closed
wants to merge 2 commits into from

Conversation

BaptisteGi
Copy link
Contributor

@BaptisteGi BaptisteGi commented Oct 11, 2024

relates #57

@BaptisteGi BaptisteGi linked an issue Oct 11, 2024 that may be closed by this pull request
8 tasks
@BaptisteGi BaptisteGi self-assigned this Oct 11, 2024
Copy link

codecov bot commented Oct 11, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/protocols_base.py 0.00% 4 Missing ⚠️
Flag Coverage Δ
python-3.10 43.05% <0.00%> (?)
python-3.11 43.05% <0.00%> (?)
python-3.12 43.05% <0.00%> (?)
python-3.9 42.99% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/code_generator.py 25.39% <ø> (ø)
infrahub_sdk/protocols_base.py 0.00% <0.00%> (ø)

@BaptisteGi
Copy link
Contributor Author

@dgarros I added the support for Checkbox kind, is it heading the right way? (so I can pretty much do the same thing for the others)

The infrahubctl protocols command works fine on a schema containing checkbox with that modification.

Copy link
Contributor

@dgarros dgarros left a comment

Choose a reason for hiding this comment

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

LGTM

@BaptisteGi
Copy link
Contributor Author

Not quite sure about the implementation here:

  • I created a class for each possible kind
  • Then had to append "Attribute" to the name to avoid collisions
  • So it generates protocols with exact same type as user would expect it to be from the schema
  • Even tho it's mapped to something else (e.g. str) behind the scene

Example generated:

class ExampleFullAttributesNode(CoreNode):
    id_required: IDAttribute
    id_optional: IDAttributeOptional
    text_required: TextAttribute
    text_optional: TextAttributeOptional
    textarea_required: TextAreaAttribute
    textarea_optional: TextAreaAttributeOptional
    datetime_required: DateTimeAttribute
    datetime_optional: DateTimeAttributeOptional
    email_required: EmailAttribute
    email_optional: EmailAttributeOptional
    password_required: PasswordAttribute
    password_optional: PasswordAttributeOptional
    hashed_password_required: HashedPasswordAttribute
    hashed_password_optional: HashedPasswordAttributeOptional
    url_required: URLAttribute
    url_optional: URLAttributeOptional
    file_required: FileAttribute
    file_optional: FileAttributeOptional
    mac_address_required: MacAddressAttribute
    mac_address_optional: MacAddressAttributeOptional
    color_required: ColorAttribute
    color_optional: ColorAttributeOptional
    number_required: NumberAttribute
    number_optional: NumberAttributeOptional
    bandwidth_required: BandwidthAttribute
    bandwidth_optional: BandwidthAttributeOptional
    ip_host_required: IPHostAttribute
    ip_host_optional: IPHostAttributeOptional
    ip_network_required: IPNetworkAttribute
    ip_network_optional: IPNetworkAttributeOptional
    boolean_required: BooleanAttribute
    boolean_optional: BooleanAttributeOptional
    checkbox_required: CheckboxAttribute
    checkbox_optional: CheckboxAttributeOptional
    list_required: ListAttribute
    list_optional: ListAttributeOptional
    json_required: JSONAttribute
    json_optional: JSONAttributeOptional
    any_required: AnyAttribute
    any_optional: AnyAttributeOptional
    dropdown_required: DropdownAttribute
    dropdown_optional: DropdownAttributeOptional
    profiles: RelationshipManager
    member_of_groups: RelationshipManager
    subscriber_of_groups: RelationshipManager

@BaptisteGi
Copy link
Contributor Author

BaptisteGi commented Oct 15, 2024

  • Fix unit tests
  • Add changelog

@petercrocker
Copy link
Contributor

This came up today with another deployment, so would be great to finish this off and make a new SDK build asap. FYI @wvandeun

@BaptisteGi BaptisteGi closed this Oct 17, 2024
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.

bug: Infrahubctl protocols doesn't support all attribute kind
3 participants