Skip to content

Commit

Permalink
Allow attestors to have multiple types (#277)
Browse files Browse the repository at this point in the history
Signed-off-by: John Kjell <[email protected]>
  • Loading branch information
jkjell authored Jun 13, 2024
1 parent a4911fd commit 9f32585
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions attestation/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ func RegisterAttestation(name, predicateType string, run RunType, factoryFunc re
attestationsByRun[run] = registrationEntry
}

func RegisterAttestationWithTypes(name string, predicateTypes []string, run RunType, factoryFunc registry.FactoryFunc[Attestor], opts ...registry.Configurer) {
registrationEntry := attestorRegistry.Register(name, factoryFunc, opts...)
for _, predicateType := range predicateTypes {
attestationsByType[predicateType] = registrationEntry
}
attestationsByRun[run] = registrationEntry
}

func FactoryByType(uri string) (registry.FactoryFunc[Attestor], bool) {
registrationEntry, ok := attestationsByType[uri]
return registrationEntry.Factory, ok
Expand Down
2 changes: 1 addition & 1 deletion attestation/sbom/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
)

func init() {
attestation.RegisterAttestation(Name, Type, RunType,
attestation.RegisterAttestationWithTypes(Name, []string{Type, SPDXPredicateType, CycloneDxPredicateType}, RunType,
func() attestation.Attestor { return NewSBOMAttestor() },
registry.BoolConfigOption(
"export",
Expand Down

0 comments on commit 9f32585

Please sign in to comment.