Skip to content

Commit 2dbabde

Browse files
committed
Initial draft of queue inspect and delete APIs
1 parent 448c86e commit 2dbabde

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

api/types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,12 @@ func (r *APIResult) Error() error {
8585

8686
return nil
8787
}
88+
89+
// QueueAPIResult is the result of queue APIs.
90+
type QueueAPIResult struct {
91+
// Status is the per-enrollment ID results of queue APIs.
92+
// Map key is the enrollment ID.
93+
Status map[string]*Error `json:"status,omitempty"`
94+
// Error is present if there was a general error with the queue API call.
95+
Error *Error `json:"error,omitempty"`
96+
}

docs/openapi.yaml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,59 @@ paths:
102102
schema:
103103
type: string
104104
example: '1'
105+
/v1/queue/{id}:
106+
get:
107+
description: Retrieve queued MDM commands for a specific enrollment ID with pagination support
108+
security:
109+
- basicAuth: []
110+
parameters:
111+
- name: id
112+
in: path
113+
description: Enrollment ID of device- or user-channel enrollment. Typically a UUID-looking identifier.
114+
required: true
115+
schema:
116+
type: string
117+
example: '299BD49-1A0C-422C-B285-2E4FF087C673'
118+
- name: cursor
119+
in: query
120+
description: Pagination cursor for retrieving the next page of results. Omit or leave empty to start from the beginning.
121+
required: false
122+
schema:
123+
type: string
124+
- name: limit
125+
in: query
126+
description: Maximum number of commands to retrieve per page.
127+
required: false
128+
schema:
129+
type: integer
130+
example: 100
131+
responses:
132+
'200':
133+
description: Successfully retrieved queued commands
134+
content:
135+
application/json:
136+
schema:
137+
$ref: '#/components/schemas/QueuedCommandsResponse'
138+
'401':
139+
$ref: '#/components/responses/UnauthorizedError'
140+
'500':
141+
description: Error retrieving queued commands
142+
/v1/queue/{id*}:
143+
delete:
144+
description: Clear all queued MDM commands for one or more enrollment IDs
145+
security:
146+
- basicAuth: []
147+
parameters:
148+
- $ref: '#/components/parameters/idParam'
149+
responses:
150+
'204':
151+
description: Successfully cleared queued commands for all enrollment IDs
152+
'207':
153+
$ref: '#/components/responses/QueueAPIResultSomeFailed'
154+
'401':
155+
$ref: '#/components/responses/UnauthorizedError'
156+
'500':
157+
$ref: '#/components/responses/QueueAPIResultAllFailed'
105158
/v1/escrowkeyunlock:
106159
post:
107160
description: "Perform an Escrow Key Unlock against Apple's API. Uses the APNs certificate of the provided topic for mTLS authentication. Note that despite all parameters being in the HTTP body (form) this endpoint moves the appropriate parameters to the URL query parameters per Apple's documentation. The response body, status, and headers are handed straight through from the Apple endpoint."
@@ -228,6 +281,18 @@ components:
228281
application/json:
229282
schema:
230283
$ref: '#/components/schemas/APIResult'
284+
QueueAPIResultSomeFailed:
285+
description: Some requests succeeded and some failed. Returns JSON queue API response object including errors.
286+
content:
287+
application/json:
288+
schema:
289+
$ref: '#/components/schemas/QueueAPIResult'
290+
QueueAPIResultAllFailed:
291+
description: All requests failed. Returns JSON queue API response object including errors.
292+
content:
293+
application/json:
294+
schema:
295+
$ref: '#/components/schemas/QueueAPIResult'
231296
schemas:
232297
APIResult:
233298
type: object
@@ -276,3 +341,44 @@ components:
276341
format: date-time
277342
description: Expiration date of the uploaded APNs certificate.
278343
example: '2026-01-07T04:04:46Z'
344+
QueuedCommandsResponse:
345+
type: object
346+
properties:
347+
commands:
348+
type: array
349+
description: Array of queued MDM commands
350+
items:
351+
type: object
352+
properties:
353+
command_uuid:
354+
type: string
355+
format: uuid
356+
example: 'fedd659e-fc3c-4e35-8bb1-c8f51ae542a5'
357+
request_type:
358+
type: string
359+
example: 'ProfileList'
360+
command:
361+
type: string
362+
format: byte
363+
description: The full MDM command plist data, base64-encoded.
364+
example: |-
365+
PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPCFET0NUWVBFIHBsaXN0IFBVQkxJQyAiLS8vQXBwbGUvL0RURCBQTElTVCAxLjAvL0VOIiAiaHR0cDovL3d3dy5hcHBsZS5jb20vRFREcy9Qcm9wZXJ0eUxpc3QtMS4wLmR0ZCI+CjxwbGlzdCB2ZXJzaW9uPSIxLjAiPgo8ZGljdD4KPGtleT5Db21tYW5kPC9rZXk+CjxkaWN0PgogICAgPGtleT5SZXF1ZXN0VHlwZTwva2V5PgogICAgPHN0cmluZz5Qcm9maWxlTGlzdDwvc3RyaW5nPgo8L2RpY3Q+CjxrZXk+Q29tbWFuZFVVSUQ8L2tleT4KPHN0cmluZz5mZWRkNjU5ZS1mYzNjLTRlMzUtOGJiMS1jOGY1MWFlNTQyYTU8L3N0cmluZz4KPC9kaWN0Pgo8L3BsaXN0Pg==
366+
next_cursor:
367+
type: string
368+
description: Cursor for retrieving the next page of results. Empty if no more results available.
369+
QueueAPIResult:
370+
type: object
371+
description: Result of queue API operations
372+
properties:
373+
status:
374+
type: object
375+
description: Per-enrollment ID error status. Map key is the enrollment ID.
376+
properties:
377+
$id:
378+
type: string
379+
description: Error message for this enrollment ID
380+
example:
381+
'299BD49-1A0C-422C-B285-2E4FF087C673': 'queue not found'
382+
'E2E4A8EB-45EE-488D-B9D7-4CC3B1C40699': 'database error'
383+
error:
384+
type: string

storage/queue.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,14 @@ type CommandAndReportResultsStore interface {
1717
type CommandEnqueuer interface {
1818
EnqueueCommand(ctx context.Context, id []string, cmd *mdm.Command) (map[string]error, error)
1919
}
20+
21+
// CommandQueueAPIStore can retrieve and clear queued commands by enrollment ID.
22+
type CommandQueueAPIStore interface {
23+
// RetrieveQueuedCommands retrieves queued commands for the given enrollment ID.
24+
// The cursor is used for pagination; an empty cursor retrieves from the start.
25+
// Limit specifies the maximum number of commands to retrieve. If limit is zero or negative, all commands are retrieved.
26+
// The retrieved commands and the next cursor (if more commands are available) are returned, or an error if any.
27+
RetrieveQueuedCommands(ctx context.Context, id, cursor string, limit int) (commands []*mdm.Command, nextCursor string, err error)
28+
// ClearQueueByID clears all queued commands for the given enrollment ID.
29+
ClearQueueByID(ctx context.Context, id string) error
30+
}

0 commit comments

Comments
 (0)