opsmill / infrahub-sync

Infrahub Sync: A Python package for flexible data synchronization between Infrahub and various platforms like Netbox, Nautobot with a Typer-based CLI.
Apache License 2.0
0 stars 3 forks source link

SchemaMappingTransform allow kinds to be defined #7

Open minitriga opened 2 months ago

minitriga commented 2 months ago

The addition of SchemaMappingTransform is wonderful however it will always return a string.

There are some reasons why you might not want to return a string. Such as in IP Fabrics case we display an interface state as up or down. But I need to be able to convert it to a boolean for a generic InfrahubSchema to be useful to anyone.

Interface Schema:

attributes:
  - name: enabled
     kind: Boolean

Sync Config

  - name: InfraInterface
    transforms:
       - field: l1
          expression: '{{ "true" if "up" in l1 else "false" }}'
    mapping: ...
    fields:
      - name: enabled
        mapping: l1

Returning a string will fail as enabled expects a Boolean. If there was a way to define the kind in the transforms like so:

  - name: InfraInterface
    transforms:
       - field: l1
          expression: '{{ "true" if "up" in l1 else "false" }}'
          kind: Boolean
    mapping: ...
    fields:
      - name: enabled
        mapping: l1

Then it would be good to convert the string to another type allowing yes/no or true false, if kind is Number then it converts the string to an int if its valid for the infrahub schema.

minitriga commented 3 weeks ago

After speaking about this with the Infrahub Team it makes sense to not have a kind and derive the kind from the destination schema.