Files
felhom-controller/controller/internal/agentapi/operatorreboot.go
T

34 lines
1.0 KiB
Go

package agentapi
import (
"context"
"encoding/json"
"fmt"
"time"
)
// OperatorReboot calls GET /guest/operator-reboot (D65 = A, agent ≥ the reboot_guest commit): the time the operator
// rebooted THIS guest from the hub, when it is less than a day old; the zero time when there is none. An agent that
// predates the route answers 404 (a *StatusError) — such an agent cannot reboot from the hub either, so there is
// nothing to show and no MinAgent is needed.
func (c *Client) OperatorReboot(ctx context.Context) (time.Time, error) {
body, err := c.get(ctx, "/guest/operator-reboot")
if err != nil {
return time.Time{}, err
}
var out struct {
At string `json:"at"`
}
if err := json.Unmarshal(body, &out); err != nil {
return time.Time{}, fmt.Errorf("agentapi: decode /guest/operator-reboot: %w", err)
}
if out.At == "" {
return time.Time{}, nil
}
at, err := time.Parse(time.RFC3339, out.At)
if err != nil {
return time.Time{}, fmt.Errorf("agentapi: /guest/operator-reboot: bad time %q", out.At)
}
return at, nil
}