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

Handle merging of lists in RecursiveModifyToml #1154

Open
chatton opened this issue Jun 25, 2024 · 0 comments
Open

Handle merging of lists in RecursiveModifyToml #1154

chatton opened this issue Jun 25, 2024 · 0 comments

Comments

@chatton
Copy link
Contributor

chatton commented Jun 25, 2024

When attempting to modify the hermes configuration file using this function, I wanted to apply the following changes

    var channelIDs [][]string
    for _, c := range channels {
       channelIDs = append(channelIDs, []string{c.PortID, c.ChannelID})
    }

    channelIDs = append(channelIDs, []string{"ica*", "*"})

    overrides := map[string]any{
       "chains": []map[string]interface{}{
          {
             "id": chainID,
             "packet_filter": map[string]interface{}{
                "policy": "allow",
                // we explicitly override the full list, this allows this function to provide a complete set of channels to watch.
                "list": channelIDs,
             },
          },
       },
    }

    return h.ModifyTomlConfigFile(ctx, ".hermes/config.toml", overrides)

i.e. explicitly adding the packet_filter field for chainID. The current behaviour of RecursiveModifyToml will ignore slices of maps, I think it would be desirable to be able to merge lists of maps this way.

Things may get tricky when you are trying to append/prepend/insert items in the merging logic, but I think it would be fine to even just require providing the same number of items, e.g. the above example would become

    overrides := map[string]any{
       "chains": []map[string]interface{}{
          {
             "packet_filter": map[string]interface{}{
                "policy": "allow",
                // we explicitly override the full list, this allows this function to provide a complete set of channels to watch.
                "list": channelIDs,
             },
          },
       },
      {}, // <--- empty map
    }

to modify the first chain in a 2 chain setup

@jonathanpberger jonathanpberger changed the title Handle merging of lists in RecursiveModifyToml Handle merging of lists in RecursiveModifyToml Jul 11, 2024
@Reecepbcups Reecepbcups removed their assignment Aug 25, 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

No branches or pull requests

2 participants