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
|
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2025 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package main
import (
"fmt"
"strconv"
"strings"
"github.com/jessevdk/go-flags"
"github.com/snapcore/snapd/snap"
)
type cmdDebugRAA struct {
clientMixin
unicodeMixin
}
func init() {
addDebugCommand("refresh-app-awareness",
"(internal) list refresh-app-awareness details",
"(internal) list refresh-app-awareness details",
func() flags.Commander {
return &cmdDebugRAA{}
}, nil, nil)
}
type monitoredSnapInfo struct {
Pids map[string][]int `json:"pids"`
}
type refreshCandidateInfo struct {
Revision snap.Revision `json:"revision"`
Version string `json:"version,omitempty"`
Channel string `json:"channel,omitempty"`
Monitored bool `json:"monitored,omitempty"`
}
func fmtMonitored(monitored bool) string {
if monitored {
return "Yes"
}
return "No"
}
func (x *cmdDebugRAA) Execute(args []string) error {
if len(args) > 0 {
return ErrExtraArgs
}
var resp struct {
MonitoredSnaps map[string]monitoredSnapInfo `json:"monitored-snaps,omitempty"`
RefreshCandidates map[string]refreshCandidateInfo `json:"refresh-candidates,omitempty"`
}
if err := x.client.DebugGet("raa", &resp, nil); err != nil {
return err
}
w := tabWriter()
if len(resp.MonitoredSnaps) != 0 {
fmt.Fprintf(w, "Monitored snaps:\n")
fmt.Fprintf(w, "Name\tSecurity Tag\tPID\n")
}
for snapName, monitored := range resp.MonitoredSnaps {
for securityTag, pids := range monitored.Pids {
for _, pid := range pids {
line := []string{snapName, securityTag, strconv.Itoa(pid)}
fmt.Fprintln(w, strings.Join(line, "\t"))
}
}
}
if len(resp.RefreshCandidates) != 0 {
fmt.Fprintf(w, "\nRefresh candidates:\n")
fmt.Fprintf(w, "Name\tVersion\tRev\tChannel\tMonitored\n")
}
for snapName, candidate := range resp.RefreshCandidates {
line := []string{
snapName,
fmtVersion(candidate.Version),
candidate.Revision.String(),
fmtChannel(candidate.Channel),
fmtMonitored(candidate.Monitored),
}
fmt.Fprintln(w, strings.Join(line, "\t"))
}
w.Flush()
return nil
}
|