Debian Codegraph @

ent/schema/subjectdigest.go

raw
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/ent"
19 "entgo.io/ent/schema/edge"
20 "entgo.io/ent/schema/field"
21 "entgo.io/ent/schema/index"
22 "github.com/google/uuid"
23 )
24
25 // SubjectDigest represents the digests of a subject from an in-toto statement
26 type SubjectDigest struct {
27 ent.Schema
28 }
29
30 // Fields of the Digest.
31 func (SubjectDigest) Fields() []ent.Field {
32 return []ent.Field{
33 field.UUID("id", uuid.UUID{}).Default(uuid.New).Immutable().Unique(),
34 field.String("algorithm").NotEmpty(),
35 field.String("value").NotEmpty(),
36 }
37 }
38
39 // Edges of the Digest.
40 func (SubjectDigest) Edges() []ent.Edge {
41 return []ent.Edge{
42 edge.From("subject", Subject.Type).
43 Ref("subject_digests").
44 Unique(),
45 }
46 }
47
48 func (SubjectDigest) Indexes() []ent.Index {
49 return []ent.Index{
50 // Index on the "value" field.
51 index.Fields("value"),
52 }
53 }