webhook

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 13 Imported by: 1

Documentation

Overview

Package webhook is a NanoMDM service for sending HTTP webhook events.

Index

Constants

View Source
const (
	// ContentType used for all requests.
	ContentType = "application/json; charset=utf-8"

	// HTTP header name used when including HMAC signatures.
	HMACHeader = "X-Hmac-Signature"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AcknowledgeEvent

type AcknowledgeEvent struct {
	// The command UUID parsed from the command report, if available.
	CommandUuid *string `json:"command_uuid,omitempty"`

	// The `EnrollmentID` of the MDM enrollment.
	EnrollmentId *EnrollmentID `json:"enrollment_id,omitempty"`

	// NanoMDM enrollment IDs.
	Ids *IDs `json:"ids,omitempty"`

	// The raw HTTP body of the MDM command report.
	RawPayload RawPayload `json:"raw_payload"`

	// The MDM status of the device. Can indicate command report status.
	Status string `json:"status"`

	// The `UDID` of the MDM device.
	Udid *UDID `json:"udid,omitempty"`

	// Query paramters of the command report MDM HTTP request.
	UrlParams map[string]string `json:"url_params,omitempty"`
}

The "command and report results" (a.k.a. "Acknowledge" or "Connect") event. Represents the MDM command report from MDM enrollments.

type CheckinEvent

type CheckinEvent struct {
	// The `EnrollmentID` of the MDM enrollment.
	EnrollmentId *EnrollmentID `json:"enrollment_id,omitempty"`

	// NanoMDM enrollment IDs.
	Ids *IDs `json:"ids,omitempty"`

	// The raw HTTP body of the MDM command report.
	RawPayload RawPayload `json:"raw_payload"`

	// Count of how many `TokenUpdate` check-in messages have occured since device
	// enrollment. Primarily to differentiate an enrollment `TokenUpdate` vs. a
	// follow-up. Will only be present for a topic name of `mdm.TokenUpdate`.
	TokenUpdateTally *int `json:"token_update_tally,omitempty"`

	// The `UDID` of the MDM device.
	Udid *UDID `json:"udid,omitempty"`

	// Query paramters of the command report MDM HTTP request.
	UrlParams map[string]string `json:"url_params,omitempty"`
}

The MDM check-in event. The specific check-in type will be indicated in the event topic name as well as the `MessageType` key in the raw payload.

type Doer

type Doer interface {
	// Do sends an HTTP request and returns an HTTP response.
	Do(*http.Request) (*http.Response, error)
}

type EnrollmentID

type EnrollmentID string

An `EnrollmentID` of the MDM enrollment.

type EventJson

type EventJson struct {
	// If present, the MDM "command and report results" (a.k.a. "Acknowledge" or
	// "Connect") event. The topic name will be `mdm.Connect`.
	AcknowledgeEvent *AcknowledgeEvent `json:"acknowledge_event,omitempty"`

	// If present, the MDM check-in event.
	CheckinEvent *CheckinEvent `json:"checkin_event,omitempty"`

	// The date and time the event was created at.
	CreatedAt time.Time `json:"created_at"`

	// The unique identifier of the event.
	EventId *string `json:"event_id,omitempty"`

	// The topic name of the event.
	Topic EventJsonTopic `json:"topic"`
}

MicroMDM webhook event

type EventJsonTopic

type EventJsonTopic string
const EventJsonTopicMdmAuthenticate EventJsonTopic = "mdm.Authenticate"
const EventJsonTopicMdmCheckOut EventJsonTopic = "mdm.CheckOut"
const EventJsonTopicMdmConnect EventJsonTopic = "mdm.Connect"
const EventJsonTopicMdmDeclarativeManagement EventJsonTopic = "mdm.DeclarativeManagement"
const EventJsonTopicMdmGetBootstrapToken EventJsonTopic = "mdm.GetBootstrapToken"
const EventJsonTopicMdmGetToken EventJsonTopic = "mdm.GetToken"
const EventJsonTopicMdmSetBootstrapToken EventJsonTopic = "mdm.SetBootstrapToken"
const EventJsonTopicMdmTokenUpdate EventJsonTopic = "mdm.TokenUpdate"
const EventJsonTopicMdmUserAuthenticate EventJsonTopic = "mdm.UserAuthenticate"

type IDs

type IDs struct {
	// NanoMDM enrollment ID. See
	// https://github.com/micromdm/nanomdm/blob/main/docs/operations-guide.md#enrollment-ids
	// for details.
	Id string `json:"id"`

	// Parent Enrollment ID. In the case of a user channel enrollment the Parent ID
	// will be the device channel enrollment ID for the user user.
	ParentId *string `json:"parent_id,omitempty"`

	// Type of enrollment.
	Type IDsType `json:"type"`
}

NanoMDM enrollment IDs.

type IDsType

type IDsType string
const IDsTypeDevice IDsType = "Device"
const IDsTypeSharedIPad IDsType = "Shared iPad"
const IDsTypeUser IDsType = "User"
const IDsTypeUserEnrollment IDsType = "User Enrollment"
const IDsTypeUserEnrollmentDevice IDsType = "User Enrollment (Device)"

type Option

type Option func(*Webhook)

Options configure webhook services.

func WithClient

func WithClient(doer Doer) Option

WithClient configures an HTTP client to use when sending webhooks.

func WithEventID

func WithEventID(fn func(context.Context) string) Option

WithEventID uses fn to get the event ID for each webhook event. Commonly a trace ID or other identifier is used from the context.

func WithHMACSecret

func WithHMACSecret(key []byte) Option

WithHMACSecret will add a SHA-256 HMAC of the webhook HTTP body using key. The HMAC is provided in the HMACHeader header and is Base-64 encoded.

func WithTokenUpdateTalley

func WithTokenUpdateTalley(store storage.TokenUpdateTallyStore) Option

WithTokenUpdateTalley specifies a storage backend to retrieve the "token talley" from. This permits sending the token talley in the event to the webhook.

type RawPayload

type RawPayload string

A raw HTTP body of an MDM request.

type UDID

type UDID string

A `UDID` identifier of the MDM enrollment.

type Webhook

type Webhook struct {
	// contains filtered or unexported fields
}

Webhook is a NanoMDM service for sending HTTP webhook events.

func New

func New(url string, opts ...Option) *Webhook

New initializes a new Webhook sending events to url.

func (*Webhook) Authenticate

func (w *Webhook) Authenticate(r *mdm.Request, m *mdm.Authenticate) error

Authenticate sends a webhook event of the NanoMDM Authenticate check-in message.

func (*Webhook) CheckOut

func (w *Webhook) CheckOut(r *mdm.Request, m *mdm.CheckOut) error

CheckOut sends a webhook event of the NanoMDM CheckOut check-in message.

func (*Webhook) CommandAndReportResults

func (w *Webhook) CommandAndReportResults(r *mdm.Request, results *mdm.CommandResults) (*mdm.Command, error)

CommandAndReportResults sends a webhook event of the NanoMDM command results.

func (*Webhook) DeclarativeManagement

func (w *Webhook) DeclarativeManagement(r *mdm.Request, m *mdm.DeclarativeManagement) ([]byte, error)

DeclarativeManagement sends a webhook event of the NanoMDM DeclarativeManagement check-in message.

func (*Webhook) GetBootstrapToken

func (w *Webhook) GetBootstrapToken(r *mdm.Request, m *mdm.GetBootstrapToken) (*mdm.BootstrapToken, error)

GetBootstrapToken sends a webhook event of the NanoMDM GetBootstrapToken check-in message.

func (*Webhook) GetToken

func (w *Webhook) GetToken(r *mdm.Request, m *mdm.GetToken) (*mdm.GetTokenResponse, error)

GetToken sends a webhook event of the NanoMDM GetToken check-in message.

func (*Webhook) SetBootstrapToken

func (w *Webhook) SetBootstrapToken(r *mdm.Request, m *mdm.SetBootstrapToken) error

SetBootstrapToken sends a webhook event of the NanoMDM SetBootstrapToken check-in message.

func (*Webhook) TokenUpdate

func (w *Webhook) TokenUpdate(r *mdm.Request, m *mdm.TokenUpdate) error

TokenUpdate sends a webhook event of the NanoMDM TokenUpdate check-in message.

func (*Webhook) UserAuthenticate

func (w *Webhook) UserAuthenticate(r *mdm.Request, m *mdm.UserAuthenticate) ([]byte, error)

UserAuthenticate sends a webhook event of the NanoMDM UserAuthenticate check-in message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL