/
slsaattestation.go
308 lines (287 loc) · 11 KB
/
slsaattestation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
// Code generated by ent, DO NOT EDIT.
package ent
import (
"encoding/json"
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/google/uuid"
"github.com/guacsec/guac/pkg/assembler/backends/ent/artifact"
"github.com/guacsec/guac/pkg/assembler/backends/ent/builder"
"github.com/guacsec/guac/pkg/assembler/backends/ent/slsaattestation"
"github.com/guacsec/guac/pkg/assembler/graphql/model"
)
// SLSAAttestation is the model entity for the SLSAAttestation schema.
type SLSAAttestation struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// Type of the builder
BuildType string `json:"build_type,omitempty"`
// ID of the builder
BuiltByID uuid.UUID `json:"built_by_id,omitempty"`
// ID of the subject artifact
SubjectID uuid.UUID `json:"subject_id,omitempty"`
// Individual predicates found in the attestation
SlsaPredicate []*model.SLSAPredicate `json:"slsa_predicate,omitempty"`
// Version of the SLSA predicate
SlsaVersion string `json:"slsa_version,omitempty"`
// Timestamp of build start time
StartedOn time.Time `json:"started_on,omitempty"`
// Timestamp of build end time
FinishedOn time.Time `json:"finished_on,omitempty"`
// Document from which this attestation is generated from
Origin string `json:"origin,omitempty"`
// GUAC collector for the document
Collector string `json:"collector,omitempty"`
// Hash of the artifacts that was built
BuiltFromHash string `json:"built_from_hash,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the SLSAAttestationQuery when eager-loading is set.
Edges SLSAAttestationEdges `json:"edges"`
selectValues sql.SelectValues
}
// SLSAAttestationEdges holds the relations/edges for other nodes in the graph.
type SLSAAttestationEdges struct {
// BuiltFrom holds the value of the built_from edge.
BuiltFrom []*Artifact `json:"built_from,omitempty"`
// BuiltBy holds the value of the built_by edge.
BuiltBy *Builder `json:"built_by,omitempty"`
// Subject holds the value of the subject edge.
Subject *Artifact `json:"subject,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [3]bool
// totalCount holds the count of the edges above.
totalCount [3]map[string]int
namedBuiltFrom map[string][]*Artifact
}
// BuiltFromOrErr returns the BuiltFrom value or an error if the edge
// was not loaded in eager-loading.
func (e SLSAAttestationEdges) BuiltFromOrErr() ([]*Artifact, error) {
if e.loadedTypes[0] {
return e.BuiltFrom, nil
}
return nil, &NotLoadedError{edge: "built_from"}
}
// BuiltByOrErr returns the BuiltBy value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e SLSAAttestationEdges) BuiltByOrErr() (*Builder, error) {
if e.loadedTypes[1] {
if e.BuiltBy == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: builder.Label}
}
return e.BuiltBy, nil
}
return nil, &NotLoadedError{edge: "built_by"}
}
// SubjectOrErr returns the Subject value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e SLSAAttestationEdges) SubjectOrErr() (*Artifact, error) {
if e.loadedTypes[2] {
if e.Subject == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: artifact.Label}
}
return e.Subject, nil
}
return nil, &NotLoadedError{edge: "subject"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*SLSAAttestation) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case slsaattestation.FieldSlsaPredicate:
values[i] = new([]byte)
case slsaattestation.FieldBuildType, slsaattestation.FieldSlsaVersion, slsaattestation.FieldOrigin, slsaattestation.FieldCollector, slsaattestation.FieldBuiltFromHash:
values[i] = new(sql.NullString)
case slsaattestation.FieldStartedOn, slsaattestation.FieldFinishedOn:
values[i] = new(sql.NullTime)
case slsaattestation.FieldID, slsaattestation.FieldBuiltByID, slsaattestation.FieldSubjectID:
values[i] = new(uuid.UUID)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the SLSAAttestation fields.
func (sa *SLSAAttestation) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case slsaattestation.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
sa.ID = *value
}
case slsaattestation.FieldBuildType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field build_type", values[i])
} else if value.Valid {
sa.BuildType = value.String
}
case slsaattestation.FieldBuiltByID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field built_by_id", values[i])
} else if value != nil {
sa.BuiltByID = *value
}
case slsaattestation.FieldSubjectID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field subject_id", values[i])
} else if value != nil {
sa.SubjectID = *value
}
case slsaattestation.FieldSlsaPredicate:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field slsa_predicate", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &sa.SlsaPredicate); err != nil {
return fmt.Errorf("unmarshal field slsa_predicate: %w", err)
}
}
case slsaattestation.FieldSlsaVersion:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field slsa_version", values[i])
} else if value.Valid {
sa.SlsaVersion = value.String
}
case slsaattestation.FieldStartedOn:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field started_on", values[i])
} else if value.Valid {
sa.StartedOn = value.Time
}
case slsaattestation.FieldFinishedOn:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field finished_on", values[i])
} else if value.Valid {
sa.FinishedOn = value.Time
}
case slsaattestation.FieldOrigin:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field origin", values[i])
} else if value.Valid {
sa.Origin = value.String
}
case slsaattestation.FieldCollector:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field collector", values[i])
} else if value.Valid {
sa.Collector = value.String
}
case slsaattestation.FieldBuiltFromHash:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field built_from_hash", values[i])
} else if value.Valid {
sa.BuiltFromHash = value.String
}
default:
sa.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the SLSAAttestation.
// This includes values selected through modifiers, order, etc.
func (sa *SLSAAttestation) Value(name string) (ent.Value, error) {
return sa.selectValues.Get(name)
}
// QueryBuiltFrom queries the "built_from" edge of the SLSAAttestation entity.
func (sa *SLSAAttestation) QueryBuiltFrom() *ArtifactQuery {
return NewSLSAAttestationClient(sa.config).QueryBuiltFrom(sa)
}
// QueryBuiltBy queries the "built_by" edge of the SLSAAttestation entity.
func (sa *SLSAAttestation) QueryBuiltBy() *BuilderQuery {
return NewSLSAAttestationClient(sa.config).QueryBuiltBy(sa)
}
// QuerySubject queries the "subject" edge of the SLSAAttestation entity.
func (sa *SLSAAttestation) QuerySubject() *ArtifactQuery {
return NewSLSAAttestationClient(sa.config).QuerySubject(sa)
}
// Update returns a builder for updating this SLSAAttestation.
// Note that you need to call SLSAAttestation.Unwrap() before calling this method if this SLSAAttestation
// was returned from a transaction, and the transaction was committed or rolled back.
func (sa *SLSAAttestation) Update() *SLSAAttestationUpdateOne {
return NewSLSAAttestationClient(sa.config).UpdateOne(sa)
}
// Unwrap unwraps the SLSAAttestation entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (sa *SLSAAttestation) Unwrap() *SLSAAttestation {
_tx, ok := sa.config.driver.(*txDriver)
if !ok {
panic("ent: SLSAAttestation is not a transactional entity")
}
sa.config.driver = _tx.drv
return sa
}
// String implements the fmt.Stringer.
func (sa *SLSAAttestation) String() string {
var builder strings.Builder
builder.WriteString("SLSAAttestation(")
builder.WriteString(fmt.Sprintf("id=%v, ", sa.ID))
builder.WriteString("build_type=")
builder.WriteString(sa.BuildType)
builder.WriteString(", ")
builder.WriteString("built_by_id=")
builder.WriteString(fmt.Sprintf("%v", sa.BuiltByID))
builder.WriteString(", ")
builder.WriteString("subject_id=")
builder.WriteString(fmt.Sprintf("%v", sa.SubjectID))
builder.WriteString(", ")
builder.WriteString("slsa_predicate=")
builder.WriteString(fmt.Sprintf("%v", sa.SlsaPredicate))
builder.WriteString(", ")
builder.WriteString("slsa_version=")
builder.WriteString(sa.SlsaVersion)
builder.WriteString(", ")
builder.WriteString("started_on=")
builder.WriteString(sa.StartedOn.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("finished_on=")
builder.WriteString(sa.FinishedOn.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("origin=")
builder.WriteString(sa.Origin)
builder.WriteString(", ")
builder.WriteString("collector=")
builder.WriteString(sa.Collector)
builder.WriteString(", ")
builder.WriteString("built_from_hash=")
builder.WriteString(sa.BuiltFromHash)
builder.WriteByte(')')
return builder.String()
}
// NamedBuiltFrom returns the BuiltFrom named value or an error if the edge was not
// loaded in eager-loading with this name.
func (sa *SLSAAttestation) NamedBuiltFrom(name string) ([]*Artifact, error) {
if sa.Edges.namedBuiltFrom == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := sa.Edges.namedBuiltFrom[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (sa *SLSAAttestation) appendNamedBuiltFrom(name string, edges ...*Artifact) {
if sa.Edges.namedBuiltFrom == nil {
sa.Edges.namedBuiltFrom = make(map[string][]*Artifact)
}
if len(edges) == 0 {
sa.Edges.namedBuiltFrom[name] = []*Artifact{}
} else {
sa.Edges.namedBuiltFrom[name] = append(sa.Edges.namedBuiltFrom[name], edges...)
}
}
// SLSAAttestations is a parsable slice of SLSAAttestation.
type SLSAAttestations []*SLSAAttestation