From ac5e1d28bb5046c1cafad685723a925983e39ee7 Mon Sep 17 00:00:00 2001 From: Kairo Araujo Date: Wed, 10 Apr 2024 13:30:44 +0200 Subject: [PATCH] feat: Implements the basic schema for Policy Adds the basic schema for the policy Signed-off-by: Kairo Araujo --- ent/schema/attestationpolicy.go | 56 +++++++++++++++++++++++++++++++++ ent/schema/statement.go | 1 + 2 files changed, 57 insertions(+) create mode 100644 ent/schema/attestationpolicy.go diff --git a/ent/schema/attestationpolicy.go b/ent/schema/attestationpolicy.go new file mode 100644 index 00000000..6ed7453e --- /dev/null +++ b/ent/schema/attestationpolicy.go @@ -0,0 +1,56 @@ +// Copyright 2024 The Archivista Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package schema + +import ( + "entgo.io/contrib/entgql" + "entgo.io/ent" + "entgo.io/ent/schema" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" +) + +// Attestation represents an attestation from a witness attestation collection +type AttestationPolicy struct { + ent.Schema +} + +func (AttestationPolicy) Fields() []ent.Field { + return []ent.Field{ + field.String("name").NotEmpty(), + } +} + +// Edges of the AttestationPolicy. +func (AttestationPolicy) Edges() []ent.Edge { + return []ent.Edge{ + edge.From("statement", Statement.Type). + Ref("policies").Unique(), + } +} + +func (AttestationPolicy) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("name"), + } +} + +func (AttestationPolicy) Annotations() []schema.Annotation { + return []schema.Annotation{ + entgql.RelayConnection(), + entgql.QueryField(), + } +} diff --git a/ent/schema/statement.go b/ent/schema/statement.go index cf62f984..9e53210a 100644 --- a/ent/schema/statement.go +++ b/ent/schema/statement.go @@ -38,6 +38,7 @@ func (Statement) Fields() []ent.Field { func (Statement) Edges() []ent.Edge { return []ent.Edge{ edge.To("subjects", Subject.Type).Annotations(entgql.RelayConnection()), + edge.To("policies", AttestationPolicy.Type).Annotations(entgql.RelayConnection()), edge.To("attestation_collections", AttestationCollection.Type).Unique(), edge.From("dsse", Dsse.Type).Ref("statement"),