Download this file
| 1 | package hostbox |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | ) |
| 7 | |
| 8 | // HostLaunches is root's local journal view, including older installations |
| 9 | // whose claim-named cgroups still need an emptiness check. |
| 10 | func (j *LaunchJournal) HostLaunches(ctx context.Context, host string) ([]LaunchInventory, error) { |
| 11 | if j == nil || j.db == nil || j.remote != nil || !component(host) { |
| 12 | return nil, ErrUnsupported |
| 13 | } |
| 14 | rows, err := journalExecutorFor(ctx, j.db).QueryContext(ctx, "SELECT identity, body FROM launches ORDER BY identity") |
| 15 | if err != nil { |
| 16 | return nil, err |
| 17 | } |
| 18 | defer rows.Close() |
| 19 | var out []LaunchInventory |
| 20 | for rows.Next() { |
| 21 | var key string |
| 22 | var body []byte |
| 23 | if err := rows.Scan(&key, &body); err != nil { |
| 24 | return nil, err |
| 25 | } |
| 26 | var in LaunchInventory |
| 27 | if err := json.Unmarshal(body, &in); err != nil { |
| 28 | return nil, err |
| 29 | } |
| 30 | if !validLaunchOwner(in.Target) || launchKey(in.Target) != key || !in.Completed.Valid() { |
| 31 | return nil, ErrTypedInventory |
| 32 | } |
| 33 | if in.Target.Host == host { |
| 34 | out = append(out, in) |
| 35 | } |
| 36 | } |
| 37 | return out, rows.Err() |
| 38 | } |
| 39 | |