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

Adding function to add a single attestor #128

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion attestation/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ func (e ErrAttestationNotFound) Error() string {
return fmt.Sprintf("attestation not found: %v", string(e))
}

type ErrAttestorNotFound string

func (e ErrAttestorNotFound) Error() string {
return fmt.Sprintf("attestor not found: %v", string(e))
}

func RegisterAttestation(name, predicateType string, run RunType, factoryFunc registry.FactoryFunc[Attestor], opts ...registry.Configurer) {
registrationEntry := attestorRegistry.Register(name, factoryFunc, opts...)
attestationsByType[predicateType] = registrationEntry
Expand All @@ -86,14 +92,32 @@ func FactoryByName(name string) (registry.FactoryFunc[Attestor], bool) {
return registrationEntry.Factory, ok
}

func GetAttestor(nameOrType string) (Attestor, error) {
attestors, err := GetAttestors([]string{nameOrType})
if err != nil {
return nil, err
}

if len(attestors) == 0 {
return nil, ErrAttestorNotFound(nameOrType)
}

return attestors[0], nil
mikhailswift marked this conversation as resolved.
Show resolved Hide resolved
}

// Deprecated: use AddAttestors instead
func Attestors(nameOrTypes []string) ([]Attestor, error) {
return GetAttestors(nameOrTypes)
}

func GetAttestors(nameOrTypes []string) ([]Attestor, error) {
attestors := make([]Attestor, 0)
for _, nameOrType := range nameOrTypes {
factory, ok := FactoryByName(nameOrType)
if !ok {
factory, ok = FactoryByType(nameOrType)
if !ok {
return nil, ErrAttestationNotFound(nameOrType)
return nil, ErrAttestorNotFound(nameOrType)
}
}

Expand Down
Loading