opsmill / infrahub-sdk-python

Apache License 2.0
3 stars 1 forks source link

bug: Infrahubctl protocols doesn't support all attribute kind #57

Open BaptisteGi opened 1 week ago

BaptisteGi commented 1 week ago

Component

Python SDK, infrahubctl

Infrahub SDK version

0.14

Current Behavior

When I try to generate protocols for my schema it fails if my schema contains node with attributes of certain kind.

Expected Behavior

I expect my command to pass and generate protocols

Steps to Reproduce

version: "1.0"

nodes:
  - name: FullAttributesNode
    namespace: Example
    description: "Node with all possible attribute kinds"
    attributes:
      - name: identifier
        kind: ID
      - name: text_attribute
        kind: Text
      - name: text_area_attribute
        kind: TextArea
      - name: datetime_attribute
        kind: DateTime
      - name: email_attribute
        kind: Email
      - name: password_attribute
        kind: Password
      - name: hashed_password_attribute
        kind: HashedPassword
      - name: url_attribute
        kind: URL
      - name: file_attribute
        kind: File
      - name: mac_address_attribute
        kind: MacAddress
      - name: color_attribute
        kind: Color
      - name: number_attribute
        kind: Number
      - name: bandwidth_attribute
        kind: Bandwidth
      - name: ip_host_attribute
        kind: IPHost
      - name: ip_network_attribute
        kind: IPNetwork
      - name: boolean_attribute
        kind: Boolean
      - name: checkbox_attribute
        kind: Checkbox
      - name: list_attribute
        kind: List
      - name: json_attribute
        kind: JSON
      - name: any_attribute
        kind: Any
      - name: dropdown_attribute
        kind: Dropdown
        choices:
          - name: option_1
            label: Option 1
            color: "#7fbf7f"
          - name: option_2
            label: Option 2
            color: "#ffff7f"

Additional Information

So far are not supported:

Seems to be missing in this map: https://github.com/opsmill/infrahub-sdk-python/blob/develop/infrahub_sdk/code_generator.py#L71

This is the error returned by the command:

infrahub-py3.12➜  infrahub git:(develop) ✗ infrahubctl protocols --branch main                
Error: 'email'
Traceback (most recent call last):
  File "/Users/Baptiste/Workspaces/Infrahub/infrahub/python_sdk/infrahub_sdk/ctl/utils.py", line 89, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Baptiste/Workspaces/Infrahub/infrahub/python_sdk/infrahub_sdk/ctl/cli_commands.py", line 356, in protocols
    write_to_file(output_file, code_generator.render(sync=sync))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/Baptiste/Workspaces/Infrahub/infrahub/python_sdk/infrahub_sdk/code_generator.py", line 53, in render
    return template.render(
           ^^^^^^^^^^^^^^^^
  File "/Users/Baptiste/Library/Caches/pypoetry/virtualenvs/infrahub-6p6-ZiP_-py3.12/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/Users/Baptiste/Library/Caches/pypoetry/virtualenvs/infrahub-6p6-ZiP_-py3.12/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 73, in top-level template code
  File "/Users/Baptiste/Workspaces/Infrahub/infrahub/python_sdk/infrahub_sdk/code_generator.py", line 90, in _jinja2_filter_render_attribute
    attribute_kind = attribute_kind_map
                     ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'email'
BaptisteGi commented 1 week ago

@dgarros if I extend the map following what's already in there is it going to work?

dgarros commented 1 week ago

@BaptisteGi yes updating the map is the main part in addition to the map, we might need to update the Jinja template as well to pre import all the new kind