| 1 |
// Copyright 2022 The Archivista Contributors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
package schema |
| 16 |
|
| 17 |
import ( |
| 18 |
"entgo.io/contrib/entgql" |
| 19 |
"entgo.io/ent" |
| 20 |
"entgo.io/ent/schema/edge" |
| 21 |
"entgo.io/ent/schema/field" |
| 22 |
"entgo.io/ent/schema/index" |
| 23 |
"github.com/google/uuid" |
| 24 |
) |
| 25 |
|
| 26 |
// Statement represents an in-toto statement from an archived dsse envelope |
| 27 |
type Statement struct { |
| 28 |
ent.Schema |
| 29 |
} |
| 30 |
|
| 31 |
// Fields of the Statement. |
| 32 |
func (Statement) Fields() []ent.Field { |
| 33 |
return []ent.Field{ |
| 34 |
field.UUID("id", uuid.UUID{}).Default(uuid.New).Immutable().Unique(), |
| 35 |
field.String("predicate").NotEmpty(), |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
// Edges of the Statement. |
| 40 |
func (Statement) Edges() []ent.Edge { |
| 41 |
return []ent.Edge{ |
| 42 |
edge.To("subjects", Subject.Type).Annotations(entgql.RelayConnection()), |
| 43 |
edge.To("policy", AttestationPolicy.Type).Unique(), |
| 44 |
edge.To("attestation_collections", AttestationCollection.Type).Unique(), |
| 45 |
|
| 46 |
edge.From("dsse", Dsse.Type).Ref("statement"), |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
func (Statement) Indexes() []ent.Index { |
| 51 |
return []ent.Index{ |
| 52 |
index.Fields("predicate"), |
| 53 |
} |
| 54 |
} |