Is it correct that something like
snap validate --enforce --refresh ...
Is not supported on snapd 2.63?
I have briefly investigated the code and it seems like the --refresh option is “acted on” before the API call to the snapd client.
See code snippet here
func (cmd *cmdValidate) Execute(args []string) error {
// check that only one action is used at a time
var action string
for _, a := range []struct {
name string
set bool
}{
{"monitor", cmd.Monitor},
{"enforce", cmd.Enforce},
{"forget", cmd.Forget},
} {
if a.set {
if action != "" {
return fmt.Errorf("cannot use --%s and --%s together", action, a.name)
}
action = a.name
}
}
if cmd.Positional.ValidationSet == "" && action != "" {
return fmt.Errorf("missing validation set argument")
}
var accountID, name string
var seq int
var err error
if cmd.Positional.ValidationSet != "" {
accountID, name, seq, err = snapasserts.ParseValidationSet(cmd.Positional.ValidationSet)
if err != nil {
return err
}
}
if action != "" {
if cmd.Refresh && action != "enforce" {
return fmt.Errorf("--refresh can only be used together with --enforce")
}
if cmd.Refresh {
changeID, err := cmd.client.RefreshMany(nil, &client.SnapOptions{
ValidationSets: []string{cmd.Positional.ValidationSet},
})
if err != nil {
return err
}
chg, err := cmd.wait(changeID)
if err != nil {
if err == noWait {
return nil
}
return err
}
var names []string
if err := chg.Get("snap-names", &names); err != nil && !errors.Is(err, client.ErrNoData) {
return err
}
if len(names) != 0 {
fmt.Fprintf(Stdout, i18n.G("Refreshed/installed snaps %s to enforce validation set %q\n"), strutil.Quoted(names), cmd.Positional.ValidationSet)
} else {
fmt.Fprintf(Stdout, i18n.G("Enforced validation set %q\n"), cmd.Positional.ValidationSet)
}
return nil
}
// forget
if cmd.Forget {
return cmd.client.ForgetValidationSet(accountID, name, seq)
}
// apply
opts := &client.ValidateApplyOptions{
Mode: action,
Sequence: seq,
}
res, err := cmd.client.ApplyValidationSet(accountID, name, opts)
...
Is there a reason not to do this on the “other” side? That is, add the option to the REST API and doing the refresh on the snapd server side?
I understand I can probably implement the refresh in a similar way as is done in the snapd application, but double implementation is not ideal.
Regards, Charlee