/
hostprocess.go
303 lines (287 loc) · 10.4 KB
/
hostprocess.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
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"realm.pub/tavern/internal/c2/epb"
"realm.pub/tavern/internal/ent/host"
"realm.pub/tavern/internal/ent/hostprocess"
"realm.pub/tavern/internal/ent/task"
)
// HostProcess is the model entity for the HostProcess schema.
type HostProcess struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Timestamp of when this ent was created
CreatedAt time.Time `json:"created_at,omitempty"`
// Timestamp of when this ent was last updated
LastModifiedAt time.Time `json:"last_modified_at,omitempty"`
// ID of the process.
Pid uint64 `json:"pid,omitempty"`
// ID of the parent process.
Ppid uint64 `json:"ppid,omitempty"`
// The name of the process.
Name string `json:"name,omitempty"`
// The user the process is running as.
Principal string `json:"principal,omitempty"`
// The path to the process executable.
Path string `json:"path,omitempty"`
// The command used to execute the process.
Cmd string `json:"cmd,omitempty"`
// The environment variables set for the process.
Env string `json:"env,omitempty"`
// The current working directory for the process.
Cwd string `json:"cwd,omitempty"`
// Current process status.
Status epb.Process_Status `json:"status,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the HostProcessQuery when eager-loading is set.
Edges HostProcessEdges `json:"edges"`
host_processes *int
host_process_host *int
task_reported_processes *int
selectValues sql.SelectValues
}
// HostProcessEdges holds the relations/edges for other nodes in the graph.
type HostProcessEdges struct {
// Host the process was reported on.
Host *Host `json:"host,omitempty"`
// Task that reported this process.
Task *Task `json:"task,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
// totalCount holds the count of the edges above.
totalCount [2]map[string]int
}
// HostOrErr returns the Host value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e HostProcessEdges) HostOrErr() (*Host, error) {
if e.loadedTypes[0] {
if e.Host == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: host.Label}
}
return e.Host, nil
}
return nil, &NotLoadedError{edge: "host"}
}
// TaskOrErr returns the Task value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e HostProcessEdges) TaskOrErr() (*Task, error) {
if e.loadedTypes[1] {
if e.Task == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: task.Label}
}
return e.Task, nil
}
return nil, &NotLoadedError{edge: "task"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*HostProcess) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case hostprocess.FieldStatus:
values[i] = new(epb.Process_Status)
case hostprocess.FieldID, hostprocess.FieldPid, hostprocess.FieldPpid:
values[i] = new(sql.NullInt64)
case hostprocess.FieldName, hostprocess.FieldPrincipal, hostprocess.FieldPath, hostprocess.FieldCmd, hostprocess.FieldEnv, hostprocess.FieldCwd:
values[i] = new(sql.NullString)
case hostprocess.FieldCreatedAt, hostprocess.FieldLastModifiedAt:
values[i] = new(sql.NullTime)
case hostprocess.ForeignKeys[0]: // host_processes
values[i] = new(sql.NullInt64)
case hostprocess.ForeignKeys[1]: // host_process_host
values[i] = new(sql.NullInt64)
case hostprocess.ForeignKeys[2]: // task_reported_processes
values[i] = new(sql.NullInt64)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the HostProcess fields.
func (hp *HostProcess) 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 hostprocess.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
hp.ID = int(value.Int64)
case hostprocess.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 {
hp.CreatedAt = value.Time
}
case hostprocess.FieldLastModifiedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field last_modified_at", values[i])
} else if value.Valid {
hp.LastModifiedAt = value.Time
}
case hostprocess.FieldPid:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field pid", values[i])
} else if value.Valid {
hp.Pid = uint64(value.Int64)
}
case hostprocess.FieldPpid:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field ppid", values[i])
} else if value.Valid {
hp.Ppid = uint64(value.Int64)
}
case hostprocess.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
hp.Name = value.String
}
case hostprocess.FieldPrincipal:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field principal", values[i])
} else if value.Valid {
hp.Principal = value.String
}
case hostprocess.FieldPath:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field path", values[i])
} else if value.Valid {
hp.Path = value.String
}
case hostprocess.FieldCmd:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field cmd", values[i])
} else if value.Valid {
hp.Cmd = value.String
}
case hostprocess.FieldEnv:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field env", values[i])
} else if value.Valid {
hp.Env = value.String
}
case hostprocess.FieldCwd:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field cwd", values[i])
} else if value.Valid {
hp.Cwd = value.String
}
case hostprocess.FieldStatus:
if value, ok := values[i].(*epb.Process_Status); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value != nil {
hp.Status = *value
}
case hostprocess.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field host_processes", value)
} else if value.Valid {
hp.host_processes = new(int)
*hp.host_processes = int(value.Int64)
}
case hostprocess.ForeignKeys[1]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field host_process_host", value)
} else if value.Valid {
hp.host_process_host = new(int)
*hp.host_process_host = int(value.Int64)
}
case hostprocess.ForeignKeys[2]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field task_reported_processes", value)
} else if value.Valid {
hp.task_reported_processes = new(int)
*hp.task_reported_processes = int(value.Int64)
}
default:
hp.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the HostProcess.
// This includes values selected through modifiers, order, etc.
func (hp *HostProcess) Value(name string) (ent.Value, error) {
return hp.selectValues.Get(name)
}
// QueryHost queries the "host" edge of the HostProcess entity.
func (hp *HostProcess) QueryHost() *HostQuery {
return NewHostProcessClient(hp.config).QueryHost(hp)
}
// QueryTask queries the "task" edge of the HostProcess entity.
func (hp *HostProcess) QueryTask() *TaskQuery {
return NewHostProcessClient(hp.config).QueryTask(hp)
}
// Update returns a builder for updating this HostProcess.
// Note that you need to call HostProcess.Unwrap() before calling this method if this HostProcess
// was returned from a transaction, and the transaction was committed or rolled back.
func (hp *HostProcess) Update() *HostProcessUpdateOne {
return NewHostProcessClient(hp.config).UpdateOne(hp)
}
// Unwrap unwraps the HostProcess 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 (hp *HostProcess) Unwrap() *HostProcess {
_tx, ok := hp.config.driver.(*txDriver)
if !ok {
panic("ent: HostProcess is not a transactional entity")
}
hp.config.driver = _tx.drv
return hp
}
// String implements the fmt.Stringer.
func (hp *HostProcess) String() string {
var builder strings.Builder
builder.WriteString("HostProcess(")
builder.WriteString(fmt.Sprintf("id=%v, ", hp.ID))
builder.WriteString("created_at=")
builder.WriteString(hp.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("last_modified_at=")
builder.WriteString(hp.LastModifiedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("pid=")
builder.WriteString(fmt.Sprintf("%v", hp.Pid))
builder.WriteString(", ")
builder.WriteString("ppid=")
builder.WriteString(fmt.Sprintf("%v", hp.Ppid))
builder.WriteString(", ")
builder.WriteString("name=")
builder.WriteString(hp.Name)
builder.WriteString(", ")
builder.WriteString("principal=")
builder.WriteString(hp.Principal)
builder.WriteString(", ")
builder.WriteString("path=")
builder.WriteString(hp.Path)
builder.WriteString(", ")
builder.WriteString("cmd=")
builder.WriteString(hp.Cmd)
builder.WriteString(", ")
builder.WriteString("env=")
builder.WriteString(hp.Env)
builder.WriteString(", ")
builder.WriteString("cwd=")
builder.WriteString(hp.Cwd)
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(fmt.Sprintf("%v", hp.Status))
builder.WriteByte(')')
return builder.String()
}
// HostProcesses is a parsable slice of HostProcess.
type HostProcesses []*HostProcess