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

Refactor List-Rules #381

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

neilnaveen
Copy link
Collaborator

…y-staging

Signed-off-by: neilnaveen <42328488+neilnaveen@users.noreply.github.com>
Signed-off-by: neilnaveen <42328488+neilnaveen@users.noreply.github.com>
@neilnaveen neilnaveen marked this pull request as ready for review May 7, 2024 16:24
Signed-off-by: neilnaveen <42328488+neilnaveen@users.noreply.github.com>
Signed-off-by: neilnaveen <42328488+neilnaveen@users.noreply.github.com>
Signed-off-by: neilnaveen <42328488+neilnaveen@users.noreply.github.com>
Signed-off-by: neilnaveen <42328488+neilnaveen@users.noreply.github.com>
Signed-off-by: neilnaveen <42328488+neilnaveen@users.noreply.github.com>
Copy link
Collaborator

@patzielinski patzielinski left a comment

Choose a reason for hiding this comment

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

Nice functionality that I think gets us closer to a better user experience. A few comments.

for _, key := range curRule.Delegation.Role.KeyIDs {
fmt.Printf(strings.Repeat(" ", curRule.Depth+2)+"%s\n", key)
}
fmt.Print(policy.GetDiffBetweenPolicyAndStaging(policyRules, policyStagingRules, policyRoot, policyStagingRoot))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would be a good candidate to route to the display package when #282 lands.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was also thinking the same thing. I don't think it really matters which PR lands first, but #282 definitely needs some attention, since without it, it is quite hard to know what a mantainer is approving when they create a reference authorization.

@@ -21,6 +21,7 @@ import (
"github.com/go-git/go-git/v5/plumbing/filemode"
"github.com/go-git/go-git/v5/plumbing/object"
sslibdsse "github.com/secure-systems-lab/go-securesystemslib/dsse"
"github.com/sergi/go-diff/diffmatchpatch"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm unsure if we want to introduce another dependency. It is however only used for diffing text to be printed out for the user and to my knowledge the original library from Google is no longer maintained, so it might be ok.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I don't know what else I could use, if you have any other suggestions for what we could use, I am open to ideas.

internal/policy/policy.go Show resolved Hide resolved
internal/policy/policy.go Show resolved Hide resolved
internal/policy/policy.go Outdated Show resolved Hide resolved
Signed-off-by: neilnaveen <42328488+neilnaveen@users.noreply.github.com>
Copy link
Collaborator

@patzielinski patzielinski left a comment

Choose a reason for hiding this comment

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

For now I think this LGTM; once the display package changes have been merged a rebase + update to use that will be in order.

func getRuleString(rule tuf.Delegation, depth int) string {
var changes string

changes += fmt.Sprintf(strings.Repeat(" ", depth)+"Rule %s:\n", rule.Name)
Copy link
Member

Choose a reason for hiding this comment

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

Could this be cleaned up a bit so there's not a mix of + to concat strings and fmt.Sprintf?

Copy link
Member

Choose a reason for hiding this comment

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

Wonder if the indent string at one scope can be computed once too 🤔

@@ -818,7 +819,122 @@ func ListRules(ctx context.Context, repo *git.Repository, targetRef string) ([]*
}
}

return allDelegations, nil
rootMetadata, err := state.GetRootMetadata()
Copy link
Member

Choose a reason for hiding this comment

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

ListRules returning the root metadata is a bit counterintuitive, no? I wonder if the consumer for this can load the root metadata separately, so this func is tighter.

for _, key := range curRule.Delegation.Role.KeyIDs {
fmt.Printf(strings.Repeat(" ", curRule.Depth+2)+"%s\n", key)
}
fmt.Print(policy.GetDiffBetweenPolicyAndStaging(policyRules, policyStagingRules, policyRoot, policyStagingRoot))
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit of a higher level thought but rolling list-rules and diff into one is counter intuitive to me. Instead, diff should be its own utility that a user can pass policy/staging RSL entries too. That way, they can also see the diff between any arbitrary policy states, no?

If we want to do a separate diff subcommand and show a diff here when staging exists on top of policy, some additional logic may be in order to verify staging is ahead of policy and so on.

@patzielinski
Copy link
Collaborator

patzielinski commented Jun 4, 2024

@neilnaveen Can you rebase/rework this as the display package in #282 landed and address Aditya's suggestions? I can give this another look then to move it along.

@neilnaveen neilnaveen mentioned this pull request Jun 25, 2024
1 task
@adityasaky
Copy link
Member

Hey @neilnaveen, are you still working on this?

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.

List-rules should not only list rules
3 participants