gittuf / gittuf

A security layer for Git repositories
https://gittuf.dev
Apache License 2.0
439 stars 28 forks source link

Add rule reordering functionality #425

Open patzielinski opened 3 weeks ago

patzielinski commented 3 weeks ago

Add a description

Currently, gittuf rules cannot be easily reordered without removing them and adding them back in the desired order. As rule order matters in gittuf, adding reordering functionality to make this easier is in order. Maybe something like gittuf policy reorder-rule <original number> <new number>, though this needs thought as well.

Raised in #424 by @adityasaky.

Relevant log output if the discussion pertains to existing gittuf functionality

No response

Code of Conduct

fr0m-scratch commented 2 weeks ago

I'd like to work on this : ) One other way crosses my mind to do this is gittuf policy reorder-rule <rule-name> <updated-position> (assuming no duplicated rule names.) And other rules move accordingly like how insert in ArrayList works

adityasaky commented 2 weeks ago

position is hard, though, as it'll be relative to other rule entries. Does --position=3 mean it becomes 3 and pushes the existing rule 3 to 4? What if I say position=10 when there are only 3 rules? Maybe I'm overthinking it, though. I'm definitely also nervous of a full fledged TUI for this, in part because I haven't built one into anything before.

neilnaveen commented 2 weeks ago

This could also happen in tandem with list-rules, where list-rules—-interactive opens an editor, allowing you to move around, add, and remove rules. We could then parse that list-rules file back into the actual policy. Updates to thresholds, additions of keys, or similar changes would be much easier and could be accomplished with a single command.

patzielinski commented 2 weeks ago

Maybe the entry method could be all rule names in the desired order they should be in after the command runs? i.e. gittuf policy reorder-rules rulename1 rulename2 etc...

fr0m-scratch commented 2 weeks ago

Maybe we can offer two ways to reorder? One is simply command line, either being gittuf policy reorder-rules rulename1 rulename2 etc... or ArrayList insertion like command with a few edge case checks, and the second way would be interactive TUI as a part of #424. Users can leverage two options depending on the number of rules