sigstore / sigstore-java

java clients for sigstore
Apache License 2.0
36 stars 20 forks source link

Add StringMatchable interface #730

Closed loosebazooka closed 1 month ago

loosebazooka commented 1 month ago

part of #729

Makes it easier to either direct match strings or regex when comparing certificate OIDs (or really any string -- but this is what we use it for)

patflynn commented 1 month ago

My curiosity is peaked. I'm struggling to see what weight this abstraction is carrying over using .equals or .pattern directly (or just wrapping them with a static method).

loosebazooka commented 1 month ago

My curiosity is peaked. I'm struggling to see what weight this abstraction is carrying over using .equals or .pattern directly (or just wrapping them with a static method).

I wanted to be able to specify if any comparisons that were happening in the library were regexes or plain strings. For example

My policy could be accept any signatures from identity: https://github.com/org/project/.github/workflows/release.yaml@refs/tags/v1.4.0, but essentially that only applies to the release 1.4.0 Instead my policy could accept signatures from identity: https://github\\.com/org/project/\\.github/workflows/release\\.yaml@refs/tags/v\\d+\\.\\d+\\.\\d+ which now doesn't need constant modification.

There's not a great way to know deep in the library if a regex comparison or plain string comparison needs to happen, so just using equals or pattern directly isn't possible.

So it was an option between providing a convention for regexes or just make them separate types (mimic'ing a oneOf). I went with the interface abstraction so that it matches what the other libraries are doing -- make them explicit and separate.

loosebazooka commented 1 month ago

Maybe a name like PatternOrString more meaningful here?

loosebazooka commented 1 month ago

okay round 2, cleaned this up a lot. @patflynn @vlsi

loosebazooka commented 1 month ago

sorry @vlsi need a rereview unfortunately

loosebazooka commented 1 month ago

Once again, I am an idiot. My code format changes weren't committed. Sorry