Documentation
¶
Overview ¶
Package push tells a person's devices that an agent is waiting for them, so a permission request reaches the lock screen while no client is open.
Index ¶
- Constants
- Variables
- func LoadAPNsKey(path string) (*ecdsa.PrivateKey, error)
- func Retract(ctx context.Context, notifiers []Notifier, m Message) error
- func Send(ctx context.Context, notifiers []Notifier, m Message) error
- type APNs
- type Device
- type DeviceStore
- type Message
- type Notifier
- type Ntfy
- type Retracter
Constants ¶
const ( EnvSandbox = "sandbox" EnvProduction = "production" )
APNs environments: a build from Xcode gets sandbox tokens, a TestFlight or App Store build gets production ones, and each works only with its own Apple server.
Variables ¶
var ErrBadDevice = errors.New("not an APNs device token and environment")
ErrBadDevice rejects a registration that cannot be an APNs device.
Functions ¶
func LoadAPNsKey ¶
func LoadAPNsKey(path string) (*ecdsa.PrivateKey, error)
LoadAPNsKey reads a token signing key (.p8) downloaded from the Apple Developer account.
Types ¶
type APNs ¶
type APNs struct {
Key *ecdsa.PrivateKey
KeyID string // the key's id in the developer account
TeamID string
Topic string // the app's bundle id
Devices *DeviceStore
// AllowedLogins are the logins whose devices still get alerts: a phone
// whose login was removed from the allowlist gets nothing.
AllowedLogins []string
Client *http.Client // must speak HTTP/2; Go's default client does over TLS
// contains filtered or unexported fields
}
APNs sends alerts straight to Apple's push service with a token signing key (.p8) from the Apple Developer account, to every registered device.
type Device ¶
type Device struct {
Token string `json:"token"` // lower-case hex
Environment string `json:"environment"`
Login string `json:"login"` // the Tailscale login that registered it
Added time.Time `json:"added"`
}
Device is a phone that asked for approval notifications.
type DeviceStore ¶
type DeviceStore struct {
Path string
// contains filtered or unexported fields
}
DeviceStore keeps registered devices in a JSON file, so they survive a restart of the server.
func (*DeviceStore) Add ¶
func (s *DeviceStore) Add(d Device) error
Add registers d, replacing an earlier registration of the same token.
func (*DeviceStore) List ¶
func (s *DeviceStore) List() ([]Device, error)
List returns the registered devices.
func (*DeviceStore) Remove ¶
func (s *DeviceStore) Remove(token string) error
Remove forgets a token; an unknown one is not an error.
type Message ¶
type Message struct {
Title string
Body string
Link string // opens the session in a client; optional
ApprovalID string
SessionID string
Expires time.Time // not worth delivering after this; zero: deliver now or never
}
Message is one notification. It names what is asked (the tool call's title, which for a shell command is the command), never the tool's full input: a relay or the lock screen may show it to anyone.
func ForApproval ¶
ForApproval words the notification for a permission request in a session. Both titles are shortened to fit about two lock-screen lines.
type Ntfy ¶
type Ntfy struct {
Server string // e.g. https://ntfy.sh
Topic string
Token string // access token for a protected topic; optional
Client *http.Client
}
Ntfy publishes to an ntfy topic (ntfy.sh or a self-hosted server), which the ntfy phone app shows on the lock screen. Anyone who knows a topic on a public server can read it: use a hard-to-guess name or a token.