Debian Codegraph @

ent/schema/attestationpolicy.go

raw
1 // Copyright 2024 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"
21 "entgo.io/ent/schema/edge"
22 "entgo.io/ent/schema/field"
23 "entgo.io/ent/schema/index"
24 "github.com/google/uuid"
25 )
26
27 // Attestation represents an attestation from a witness attestation collection
28 type AttestationPolicy struct {
29 ent.Schema
30 }
31
32 func (AttestationPolicy) Fields() []ent.Field {
33 return []ent.Field{
34 field.UUID("id", uuid.UUID{}).Default(uuid.New).Immutable().Unique(),
35 field.String("name").NotEmpty(),
36 }
37 }
38
39 // Edges of the AttestationPolicy.
40 func (AttestationPolicy) Edges() []ent.Edge {
41 return []ent.Edge{
42 edge.From("statement", Statement.Type).
43 Ref("policy").Unique(),
44 }
45 }
46
47 func (AttestationPolicy) Indexes() []ent.Index {
48 return []ent.Index{
49 index.Fields("name"),
50 }
51 }
52
53 func (AttestationPolicy) Annotations() []schema.Annotation {
54 return []schema.Annotation{
55 entgql.RelayConnection(),
56 entgql.QueryField(),
57 }
58 }