-
Notifications
You must be signed in to change notification settings - Fork 26
/
workflowrun.go
314 lines (296 loc) · 12.2 KB
/
workflowrun.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
309
310
311
312
313
314
// 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/chainloop-dev/chainloop/app/controlplane/internal/biz"
"github.com/chainloop-dev/chainloop/app/controlplane/internal/data/ent/workflow"
"github.com/chainloop-dev/chainloop/app/controlplane/internal/data/ent/workflowcontractversion"
"github.com/chainloop-dev/chainloop/app/controlplane/internal/data/ent/workflowrun"
"github.com/google/uuid"
"github.com/secure-systems-lab/go-securesystemslib/dsse"
)
// WorkflowRun is the model entity for the WorkflowRun schema.
type WorkflowRun struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// FinishedAt holds the value of the "finished_at" field.
FinishedAt time.Time `json:"finished_at,omitempty"`
// State holds the value of the "state" field.
State biz.WorkflowRunStatus `json:"state,omitempty"`
// Reason holds the value of the "reason" field.
Reason string `json:"reason,omitempty"`
// RunURL holds the value of the "run_url" field.
RunURL string `json:"run_url,omitempty"`
// RunnerType holds the value of the "runner_type" field.
RunnerType string `json:"runner_type,omitempty"`
// Attestation holds the value of the "attestation" field.
Attestation *dsse.Envelope `json:"attestation,omitempty"`
// AttestationDigest holds the value of the "attestation_digest" field.
AttestationDigest string `json:"attestation_digest,omitempty"`
// AttestationState holds the value of the "attestation_state" field.
AttestationState []byte `json:"attestation_state,omitempty"`
// ContractRevisionUsed holds the value of the "contract_revision_used" field.
ContractRevisionUsed int `json:"contract_revision_used,omitempty"`
// ContractRevisionLatest holds the value of the "contract_revision_latest" field.
ContractRevisionLatest int `json:"contract_revision_latest,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the WorkflowRunQuery when eager-loading is set.
Edges WorkflowRunEdges `json:"edges"`
workflow_workflowruns *uuid.UUID
workflow_run_contract_version *uuid.UUID
selectValues sql.SelectValues
}
// WorkflowRunEdges holds the relations/edges for other nodes in the graph.
type WorkflowRunEdges struct {
// Workflow holds the value of the workflow edge.
Workflow *Workflow `json:"workflow,omitempty"`
// ContractVersion holds the value of the contract_version edge.
ContractVersion *WorkflowContractVersion `json:"contract_version,omitempty"`
// CasBackends holds the value of the cas_backends edge.
CasBackends []*CASBackend `json:"cas_backends,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [3]bool
}
// WorkflowOrErr returns the Workflow value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e WorkflowRunEdges) WorkflowOrErr() (*Workflow, error) {
if e.loadedTypes[0] {
if e.Workflow == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: workflow.Label}
}
return e.Workflow, nil
}
return nil, &NotLoadedError{edge: "workflow"}
}
// ContractVersionOrErr returns the ContractVersion value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e WorkflowRunEdges) ContractVersionOrErr() (*WorkflowContractVersion, error) {
if e.loadedTypes[1] {
if e.ContractVersion == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: workflowcontractversion.Label}
}
return e.ContractVersion, nil
}
return nil, &NotLoadedError{edge: "contract_version"}
}
// CasBackendsOrErr returns the CasBackends value or an error if the edge
// was not loaded in eager-loading.
func (e WorkflowRunEdges) CasBackendsOrErr() ([]*CASBackend, error) {
if e.loadedTypes[2] {
return e.CasBackends, nil
}
return nil, &NotLoadedError{edge: "cas_backends"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*WorkflowRun) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case workflowrun.FieldAttestation, workflowrun.FieldAttestationState:
values[i] = new([]byte)
case workflowrun.FieldContractRevisionUsed, workflowrun.FieldContractRevisionLatest:
values[i] = new(sql.NullInt64)
case workflowrun.FieldState, workflowrun.FieldReason, workflowrun.FieldRunURL, workflowrun.FieldRunnerType, workflowrun.FieldAttestationDigest:
values[i] = new(sql.NullString)
case workflowrun.FieldCreatedAt, workflowrun.FieldFinishedAt:
values[i] = new(sql.NullTime)
case workflowrun.FieldID:
values[i] = new(uuid.UUID)
case workflowrun.ForeignKeys[0]: // workflow_workflowruns
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
case workflowrun.ForeignKeys[1]: // workflow_run_contract_version
values[i] = &sql.NullScanner{S: 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 WorkflowRun fields.
func (wr *WorkflowRun) 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 workflowrun.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
wr.ID = *value
}
case workflowrun.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
wr.CreatedAt = value.Time
}
case workflowrun.FieldFinishedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field finished_at", values[i])
} else if value.Valid {
wr.FinishedAt = value.Time
}
case workflowrun.FieldState:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field state", values[i])
} else if value.Valid {
wr.State = biz.WorkflowRunStatus(value.String)
}
case workflowrun.FieldReason:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field reason", values[i])
} else if value.Valid {
wr.Reason = value.String
}
case workflowrun.FieldRunURL:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field run_url", values[i])
} else if value.Valid {
wr.RunURL = value.String
}
case workflowrun.FieldRunnerType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field runner_type", values[i])
} else if value.Valid {
wr.RunnerType = value.String
}
case workflowrun.FieldAttestation:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field attestation", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &wr.Attestation); err != nil {
return fmt.Errorf("unmarshal field attestation: %w", err)
}
}
case workflowrun.FieldAttestationDigest:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field attestation_digest", values[i])
} else if value.Valid {
wr.AttestationDigest = value.String
}
case workflowrun.FieldAttestationState:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field attestation_state", values[i])
} else if value != nil {
wr.AttestationState = *value
}
case workflowrun.FieldContractRevisionUsed:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field contract_revision_used", values[i])
} else if value.Valid {
wr.ContractRevisionUsed = int(value.Int64)
}
case workflowrun.FieldContractRevisionLatest:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field contract_revision_latest", values[i])
} else if value.Valid {
wr.ContractRevisionLatest = int(value.Int64)
}
case workflowrun.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field workflow_workflowruns", values[i])
} else if value.Valid {
wr.workflow_workflowruns = new(uuid.UUID)
*wr.workflow_workflowruns = *value.S.(*uuid.UUID)
}
case workflowrun.ForeignKeys[1]:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field workflow_run_contract_version", values[i])
} else if value.Valid {
wr.workflow_run_contract_version = new(uuid.UUID)
*wr.workflow_run_contract_version = *value.S.(*uuid.UUID)
}
default:
wr.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the WorkflowRun.
// This includes values selected through modifiers, order, etc.
func (wr *WorkflowRun) Value(name string) (ent.Value, error) {
return wr.selectValues.Get(name)
}
// QueryWorkflow queries the "workflow" edge of the WorkflowRun entity.
func (wr *WorkflowRun) QueryWorkflow() *WorkflowQuery {
return NewWorkflowRunClient(wr.config).QueryWorkflow(wr)
}
// QueryContractVersion queries the "contract_version" edge of the WorkflowRun entity.
func (wr *WorkflowRun) QueryContractVersion() *WorkflowContractVersionQuery {
return NewWorkflowRunClient(wr.config).QueryContractVersion(wr)
}
// QueryCasBackends queries the "cas_backends" edge of the WorkflowRun entity.
func (wr *WorkflowRun) QueryCasBackends() *CASBackendQuery {
return NewWorkflowRunClient(wr.config).QueryCasBackends(wr)
}
// Update returns a builder for updating this WorkflowRun.
// Note that you need to call WorkflowRun.Unwrap() before calling this method if this WorkflowRun
// was returned from a transaction, and the transaction was committed or rolled back.
func (wr *WorkflowRun) Update() *WorkflowRunUpdateOne {
return NewWorkflowRunClient(wr.config).UpdateOne(wr)
}
// Unwrap unwraps the WorkflowRun 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 (wr *WorkflowRun) Unwrap() *WorkflowRun {
_tx, ok := wr.config.driver.(*txDriver)
if !ok {
panic("ent: WorkflowRun is not a transactional entity")
}
wr.config.driver = _tx.drv
return wr
}
// String implements the fmt.Stringer.
func (wr *WorkflowRun) String() string {
var builder strings.Builder
builder.WriteString("WorkflowRun(")
builder.WriteString(fmt.Sprintf("id=%v, ", wr.ID))
builder.WriteString("created_at=")
builder.WriteString(wr.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("finished_at=")
builder.WriteString(wr.FinishedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("state=")
builder.WriteString(fmt.Sprintf("%v", wr.State))
builder.WriteString(", ")
builder.WriteString("reason=")
builder.WriteString(wr.Reason)
builder.WriteString(", ")
builder.WriteString("run_url=")
builder.WriteString(wr.RunURL)
builder.WriteString(", ")
builder.WriteString("runner_type=")
builder.WriteString(wr.RunnerType)
builder.WriteString(", ")
builder.WriteString("attestation=")
builder.WriteString(fmt.Sprintf("%v", wr.Attestation))
builder.WriteString(", ")
builder.WriteString("attestation_digest=")
builder.WriteString(wr.AttestationDigest)
builder.WriteString(", ")
builder.WriteString("attestation_state=")
builder.WriteString(fmt.Sprintf("%v", wr.AttestationState))
builder.WriteString(", ")
builder.WriteString("contract_revision_used=")
builder.WriteString(fmt.Sprintf("%v", wr.ContractRevisionUsed))
builder.WriteString(", ")
builder.WriteString("contract_revision_latest=")
builder.WriteString(fmt.Sprintf("%v", wr.ContractRevisionLatest))
builder.WriteByte(')')
return builder.String()
}
// WorkflowRuns is a parsable slice of WorkflowRun.
type WorkflowRuns []*WorkflowRun