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

Define more than one Type per Attestor #291

Closed
Closed
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions attestation/aws-iid/aws-iid.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ C1haGgSI/A1uZUKs/Zfnph0oEI0/hu1IIJ/SKBDtN5lvmZ/IzbOPIJWirlsllQIQ
// This is a hacky way to create a compile time error in case the attestor
// doesn't implement the expected interfaces.
var (
_ attestation.Attestor = &Attestor{}
_ attestation.Subjecter = &Attestor{}
_ attestation.Attestor = &Attestor{}
_ attestation.Subjecter = &Attestor{}
types = attestation.TypeSet{Type}
)

func init() {
attestation.RegisterAttestation(Name, Type, RunType, func() attestation.Attestor {
attestation.RegisterAttestation(Name, types, RunType, func() attestation.Attestor {
return New()
})
}
Expand Down Expand Up @@ -106,8 +107,8 @@ func (a *Attestor) Name() string {
return Name
}

func (a *Attestor) Type() string {
return Type
func (a *Attestor) Type() attestation.TypeSet {
return attestation.TypeSet{Type}
}

func (a *Attestor) RunType() attestation.RunType {
Expand Down
6 changes: 3 additions & 3 deletions attestation/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func NewCollection(name string, attestors []CompletedAttestor) Collection {
Attestations: make([]CollectionAttestation, 0),
}

//move start/stop time to collection
//todo: this is a bit of a hack, but it's the easiest way to get the start/stop time
// move start/stop time to collection
// todo: this is a bit of a hack, but it's the easiest way to get the start/stop time

for _, completed := range attestors {
collection.Attestations = append(collection.Attestations, NewCollectionAttestation(completed))
Expand All @@ -54,7 +54,7 @@ func NewCollection(name string, attestors []CompletedAttestor) Collection {

func NewCollectionAttestation(completed CompletedAttestor) CollectionAttestation {
return CollectionAttestation{
Type: completed.Attestor.Type(),
Type: completed.Attestor.Type().First(),
Attestation: completed.Attestor,
StartTime: completed.StartTime,
EndTime: completed.EndTime,
Expand Down
13 changes: 7 additions & 6 deletions attestation/commandrun/commandrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,22 @@ const (
// This is a hacky way to create a compile time error in case the attestor
// doesn't implement the expected interfaces.
var (
_ attestation.Attestor = &CommandRun{}
_ CommandRunAttestor = &CommandRun{}
_ attestation.Attestor = &CommandRun{}
_ CommandRunAttestor = &CommandRun{}
types = attestation.TypeSet{Type}
)

type CommandRunAttestor interface {
// Attestor
Name() string
Type() string
Type() attestation.TypeSet
RunType() attestation.RunType
Attest(ctx *attestation.AttestationContext) error
Data() *CommandRun
}

func init() {
attestation.RegisterAttestation(Name, Type, RunType, func() attestation.Attestor {
attestation.RegisterAttestation(Name, types, RunType, func() attestation.Attestor {
return New()
})
}
Expand Down Expand Up @@ -152,8 +153,8 @@ func (rc *CommandRun) Name() string {
return Name
}

func (rc *CommandRun) Type() string {
return Type
func (rc *CommandRun) Type() attestation.TypeSet {
return types
}

func (rc *CommandRun) RunType() attestation.RunType {
Expand Down
13 changes: 7 additions & 6 deletions attestation/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,22 @@ const (
// This is a hacky way to create a compile time error in case the attestor
// doesn't implement the expected interfaces.
var (
_ attestation.Attestor = &Attestor{}
_ EnvironmentAttestor = &Attestor{}
_ attestation.Attestor = &Attestor{}
_ EnvironmentAttestor = &Attestor{}
types = attestation.TypeSet{Type}
)

type EnvironmentAttestor interface {
// Attestor
Name() string
Type() string
Type() attestation.TypeSet
RunType() attestation.RunType
Attest(ctx *attestation.AttestationContext) error
Data() *Attestor
}

func init() {
attestation.RegisterAttestation(Name, Type, RunType, func() attestation.Attestor {
attestation.RegisterAttestation(Name, types, RunType, func() attestation.Attestor {
return New()
})
}
Expand Down Expand Up @@ -85,8 +86,8 @@ func (a *Attestor) Name() string {
return Name
}

func (a *Attestor) Type() string {
return Type
func (a *Attestor) Type() attestation.TypeSet {
return types
}

func (a *Attestor) RunType() attestation.RunType {
Expand Down
27 changes: 24 additions & 3 deletions attestation/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,31 @@ var (

type Attestor interface {
Name() string
Type() string
Type() TypeSet
RunType() RunType
Attest(ctx *AttestationContext) error
Schema() *jsonschema.Schema
}

type TypeSet []string

func (s TypeSet) First() string {
if len(s) == 0 {
return ""
} else {
return s[0]
}
}

func (s TypeSet) Contains(t string) bool {
for _, v := range s {
if v == t {
return true
}
}
return false
}

// Subjecter allows attestors to expose bits of information that will be added to
// the in-toto statement as subjects. External services such as Rekor and Archivista
// use in-toto subjects as indexes back to attestations.
Expand Down Expand Up @@ -84,9 +103,11 @@ 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) {
func RegisterAttestation(name string, predicateType TypeSet, run RunType, factoryFunc registry.FactoryFunc[Attestor], opts ...registry.Configurer) {
registrationEntry := attestorRegistry.Register(name, factoryFunc, opts...)
attestationsByType[predicateType] = registrationEntry
for _, t := range predicateType {
attestationsByType[t] = registrationEntry
}
attestationsByRun[run] = registrationEntry
}

Expand Down
11 changes: 6 additions & 5 deletions attestation/gcp-iit/gcp-iit.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ const (
// This is a hacky way to create a compile time error in case the attestor
// doesn't implement the expected interfaces.
var (
_ attestation.Attestor = &Attestor{}
_ attestation.Subjecter = &Attestor{}
_ attestation.Attestor = &Attestor{}
_ attestation.Subjecter = &Attestor{}
types = attestation.TypeSet{Type}
)

func init() {
attestation.RegisterAttestation(Name, Type, RunType, func() attestation.Attestor {
attestation.RegisterAttestation(Name, types, RunType, func() attestation.Attestor {
return New()
})
}
Expand Down Expand Up @@ -91,8 +92,8 @@ func (a *Attestor) Name() string {
return Name
}

func (a *Attestor) Type() string {
return Type
func (a *Attestor) Type() attestation.TypeSet {
return types
}

func (a *Attestor) RunType() attestation.RunType {
Expand Down
17 changes: 9 additions & 8 deletions attestation/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ const (
// This is a hacky way to create a compile time error in case the attestor
// doesn't implement the expected interfaces.
var (
_ attestation.Attestor = &Attestor{}
_ attestation.Subjecter = &Attestor{}
_ attestation.BackReffer = &Attestor{}
_ GitAttestor = &Attestor{}
_ attestation.Attestor = &Attestor{}
_ attestation.Subjecter = &Attestor{}
_ attestation.BackReffer = &Attestor{}
_ GitAttestor = &Attestor{}
types = attestation.TypeSet{Type}
)

type GitAttestor interface {
// Attestor
Name() string
Type() string
Type() attestation.TypeSet
RunType() attestation.RunType
Attest(ctx *attestation.AttestationContext) error
Data() *Attestor
Expand All @@ -59,7 +60,7 @@ type GitAttestor interface {
}

func init() {
attestation.RegisterAttestation(Name, Type, RunType, func() attestation.Attestor {
attestation.RegisterAttestation(Name, types, RunType, func() attestation.Attestor {
return New()
})
}
Expand Down Expand Up @@ -107,8 +108,8 @@ func (a *Attestor) Name() string {
return Name
}

func (a *Attestor) Type() string {
return Type
func (a *Attestor) Type() attestation.TypeSet {
return types
}

func (a *Attestor) RunType() attestation.RunType {
Expand Down
17 changes: 9 additions & 8 deletions attestation/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ const (
// This is a hacky way to create a compile time error in case the attestor
// doesn't implement the expected interfaces.
var (
_ attestation.Attestor = &Attestor{}
_ attestation.Subjecter = &Attestor{}
_ attestation.BackReffer = &Attestor{}
_ GitHubAttestor = &Attestor{}
_ attestation.Attestor = &Attestor{}
_ attestation.Subjecter = &Attestor{}
_ attestation.BackReffer = &Attestor{}
_ GitHubAttestor = &Attestor{}
types = attestation.TypeSet{Type}
)

type GitHubAttestor interface {
// Attestor
Name() string
Type() string
Type() attestation.TypeSet
RunType() attestation.RunType
Attest(ctx *attestation.AttestationContext) error
Data() *Attestor
Expand All @@ -69,7 +70,7 @@ type GitHubAttestor interface {

// init registers the github attestor.
func init() {
attestation.RegisterAttestation(Name, Type, RunType, func() attestation.Attestor {
attestation.RegisterAttestation(Name, types, RunType, func() attestation.Attestor {
return New()
})
}
Expand Down Expand Up @@ -116,8 +117,8 @@ func (a *Attestor) Name() string {
}

// Type returns the type of the attestor.
func (a *Attestor) Type() string {
return Type
func (a *Attestor) Type() attestation.TypeSet {
return types
}

// RunType returns the run type of the attestor.
Expand Down
17 changes: 9 additions & 8 deletions attestation/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ const (
// This is a hacky way to create a compile time error in case the attestor
// doesn't implement the expected interfaces.
var (
_ attestation.Attestor = &Attestor{}
_ attestation.Subjecter = &Attestor{}
_ attestation.BackReffer = &Attestor{}
_ GitLabAttestor = &Attestor{}
_ attestation.Attestor = &Attestor{}
_ attestation.Subjecter = &Attestor{}
_ attestation.BackReffer = &Attestor{}
_ GitLabAttestor = &Attestor{}
types = attestation.TypeSet{Type}
)

type GitLabAttestor interface {
// Attestor
Name() string
Type() string
Type() attestation.TypeSet
RunType() attestation.RunType
Attest(ctx *attestation.AttestationContext) error
Data() *Attestor
Expand All @@ -58,7 +59,7 @@ type GitLabAttestor interface {
}

func init() {
attestation.RegisterAttestation(Name, Type, RunType, func() attestation.Attestor {
attestation.RegisterAttestation(Name, types, RunType, func() attestation.Attestor {
return New()
})
}
Expand Down Expand Up @@ -94,8 +95,8 @@ func (a *Attestor) Name() string {
return Name
}

func (a *Attestor) Type() string {
return Type
func (a *Attestor) Type() attestation.TypeSet {
return types
}

func (a *Attestor) RunType() attestation.RunType {
Expand Down
9 changes: 5 additions & 4 deletions attestation/jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ const (
// This is a hacky way to create a compile time error in case the attestor
// doesn't implement the expected interfaces.
var (
_ attestation.Attestor = &Attestor{}
_ attestation.Attestor = &Attestor{}
types = attestation.TypeSet{Type}
)

func init() {
attestation.RegisterAttestation(Name, Type, RunType, func() attestation.Attestor {
attestation.RegisterAttestation(Name, types, RunType, func() attestation.Attestor {
return New()
})
}
Expand Down Expand Up @@ -142,8 +143,8 @@ func (a *Attestor) Name() string {
return Name
}

func (a *Attestor) Type() string {
return Type
func (a *Attestor) Type() attestation.TypeSet {
return types
}

func (a *Attestor) RunType() attestation.RunType {
Expand Down
11 changes: 6 additions & 5 deletions attestation/link/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ const (
// This is a hacky way to create a compile time error in case the attestor
// doesn't implement the expected interfaces.
var (
_ attestation.Attestor = &Link{}
_ attestation.Subjecter = &Link{}
_ attestation.Attestor = &Link{}
_ attestation.Subjecter = &Link{}
types = attestation.TypeSet{Type}
)

func init() {
attestation.RegisterAttestation(Name, Type, RunType,
attestation.RegisterAttestation(Name, types, RunType,
func() attestation.Attestor { return New() },
registry.BoolConfigOption(
"export",
Expand Down Expand Up @@ -87,8 +88,8 @@ func (l *Link) Name() string {
return Name
}

func (l *Link) Type() string {
return Type
func (l *Link) Type() attestation.TypeSet {
return types
}

func (l *Link) RunType() attestation.RunType {
Expand Down
Loading
Loading