From 05344403a547baf3fb358ab96fa4dabe9b98268f Mon Sep 17 00:00:00 2001 From: Scott Knight <4534275+knightsc@users.noreply.github.com> Date: Thu, 21 Jun 2018 08:07:56 -0400 Subject: [PATCH] Add software update command examples (#442) Add support for the OSUpdateStatus command Add example Software Update API commands --- mdm/mdm/marshal_json.go | 3 ++- mdm/mdm/marshal_plist.go | 3 ++- mdm/mdm/marshal_proto.go | 3 ++- mdm/mdm/unmarshal_json.go | 3 ++- mdm/mdm/unmarshal_plist.go | 3 ++- mdm/mdm/unmarshal_proto.go | 3 ++- tools/api/commands/available_os_updates | 10 ++++++++++ tools/api/commands/os_update_status | 10 ++++++++++ tools/api/commands/schedule_os_update | 16 ++++++++++++++++ tools/api/commands/schedule_os_update_scan | 12 ++++++++++++ 10 files changed, 60 insertions(+), 6 deletions(-) create mode 100755 tools/api/commands/available_os_updates create mode 100755 tools/api/commands/os_update_status create mode 100755 tools/api/commands/schedule_os_update create mode 100755 tools/api/commands/schedule_os_update_scan diff --git a/mdm/mdm/marshal_json.go b/mdm/mdm/marshal_json.go index f7b3762a..c5a0ea98 100644 --- a/mdm/mdm/marshal_json.go +++ b/mdm/mdm/marshal_json.go @@ -23,7 +23,8 @@ func (c *Command) MarshalJSON() ([]byte, error) { "ManagedMediaList", "DeviceConfigured", "AvailableOSUpdates", - "NSExtensionMappings": + "NSExtensionMappings", + "OSUpdateStatus": var x = struct { RequestType string `json:"request_type"` }{ diff --git a/mdm/mdm/marshal_plist.go b/mdm/mdm/marshal_plist.go index d6d48478..cd17b621 100644 --- a/mdm/mdm/marshal_plist.go +++ b/mdm/mdm/marshal_plist.go @@ -20,7 +20,8 @@ func (c *Command) MarshalPlist() (interface{}, error) { "ManagedMediaList", "DeviceConfigured", "AvailableOSUpdates", - "NSExtensionMappings": + "NSExtensionMappings", + "OSUpdateStatus": return &struct { RequestType string }{ diff --git a/mdm/mdm/marshal_proto.go b/mdm/mdm/marshal_proto.go index 898e44de..5f50de7c 100644 --- a/mdm/mdm/marshal_proto.go +++ b/mdm/mdm/marshal_proto.go @@ -41,7 +41,8 @@ func commandToProto(cmd *Command) (*mdmproto.Command, error) { "ManagedMediaList", "DeviceConfigured", "AvailableOSUpdates", - "NSExtensionMappings": + "NSExtensionMappings", + "OSUpdateStatus": case "InstallProfile": if cmd.InstallProfile == nil { diff --git a/mdm/mdm/unmarshal_json.go b/mdm/mdm/unmarshal_json.go index 0222533f..1e679997 100644 --- a/mdm/mdm/unmarshal_json.go +++ b/mdm/mdm/unmarshal_json.go @@ -46,7 +46,8 @@ func (c *Command) UnmarshalJSON(data []byte) error { "ManagedMediaList", "DeviceConfigured", "AvailableOSUpdates", - "NSExtensionMappings": + "NSExtensionMappings", + "OSUpdateStatus": return nil case "InstallProfile": var payload InstallProfile diff --git a/mdm/mdm/unmarshal_plist.go b/mdm/mdm/unmarshal_plist.go index 8ae5f876..9ce6c449 100644 --- a/mdm/mdm/unmarshal_plist.go +++ b/mdm/mdm/unmarshal_plist.go @@ -32,7 +32,8 @@ func (c *Command) UnmarshalPlist(unmarshal func(i interface{}) error) error { "ManagedMediaList", "DeviceConfigured", "AvailableOSUpdates", - "NSExtensionMappings": + "NSExtensionMappings", + "OSUpdateStatus": return nil case "InstallProfile": var payload InstallProfile diff --git a/mdm/mdm/unmarshal_proto.go b/mdm/mdm/unmarshal_proto.go index 9ac98449..3a469a10 100644 --- a/mdm/mdm/unmarshal_proto.go +++ b/mdm/mdm/unmarshal_proto.go @@ -28,7 +28,8 @@ func protoToCommand(pb *mdmproto.Command) *Command { "ManagedMediaList", "DeviceConfigured", "AvailableOSUpdates", - "NSExtensionMappings": + "NSExtensionMappings", + "OSUpdateStatus": case "InstallProfile": cmd.InstallProfile = &InstallProfile{ diff --git a/tools/api/commands/available_os_updates b/tools/api/commands/available_os_updates new file mode 100755 index 00000000..a3074afd --- /dev/null +++ b/tools/api/commands/available_os_updates @@ -0,0 +1,10 @@ +#!/bin/bash +source $MICROMDM_ENV_PATH +endpoint="v1/commands" +jq -n \ + --arg request_type "AvailableOSUpdates" \ + --arg udid "$1" \ + '.udid = $udid + |.request_type = $request_type + '|\ + curl -u "micromdm:$API_TOKEN" "$SERVER_URL/$endpoint" -d@- diff --git a/tools/api/commands/os_update_status b/tools/api/commands/os_update_status new file mode 100755 index 00000000..496c3a08 --- /dev/null +++ b/tools/api/commands/os_update_status @@ -0,0 +1,10 @@ +#!/bin/bash +source $MICROMDM_ENV_PATH +endpoint="v1/commands" +jq -n \ + --arg request_type "OSUpdateStatus" \ + --arg udid "$1" \ + '.udid = $udid + |.request_type = $request_type + '|\ + curl -u "micromdm:$API_TOKEN" "$SERVER_URL/$endpoint" -d@- diff --git a/tools/api/commands/schedule_os_update b/tools/api/commands/schedule_os_update new file mode 100755 index 00000000..8e702d28 --- /dev/null +++ b/tools/api/commands/schedule_os_update @@ -0,0 +1,16 @@ +#!/bin/bash +source $MICROMDM_ENV_PATH +endpoint="v1/commands" +jq -n \ + --arg request_type "ScheduleOSUpdate" \ + --arg udid "$1" \ + --arg product_key "$2" \ + --arg install_action "$3" \ + '.udid = $udid + |.request_type = $request_type + |.updates = [ + .product_key = $product_key + |.install_action = $install_action + ] + '|\ + curl -u "micromdm:$API_TOKEN" "$SERVER_URL/$endpoint" -d@- diff --git a/tools/api/commands/schedule_os_update_scan b/tools/api/commands/schedule_os_update_scan new file mode 100755 index 00000000..a6c9f359 --- /dev/null +++ b/tools/api/commands/schedule_os_update_scan @@ -0,0 +1,12 @@ +#!/bin/bash +source $MICROMDM_ENV_PATH +endpoint="v1/commands" +jq -n \ + --arg request_type "ScheduleOSUpdateScan" \ + --arg udid "$1" \ + --argjson force "$2" \ + '.udid = $udid + |.request_type = $request_type + |.force = $force + '|\ + curl -u "micromdm:$API_TOKEN" "$SERVER_URL/$endpoint" -d@-