mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-05 08:55:51 +08:00
Added RefreshCellularPlans support (#809)
This commit is contained in:
@@ -68,6 +68,7 @@ type Command struct {
|
||||
ScheduleOSUpdateScan *ScheduleOSUpdateScan
|
||||
ActiveNSExtensions *ActiveNSExtensions
|
||||
RotateFileVaultKey *RotateFileVaultKey
|
||||
RefreshCellularPlans *RefreshCellularPlans
|
||||
}
|
||||
|
||||
// InstallProfile is an InstallProfile MDM Command
|
||||
@@ -307,3 +308,7 @@ type FileVaultUnlock struct {
|
||||
PrivateKeyExport []byte `plist:",omitempty" json:"private_key_export,omitempty"`
|
||||
PrivateKeyExportPassword string `plist:",omitempty" json:"private_key_export_password,omitempty"`
|
||||
}
|
||||
|
||||
type RefreshCellularPlans struct {
|
||||
EsimServerUrl string `plist:"eSIMServerURL,omitempty" json:"esim_server_url,omitempty"`
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -73,6 +73,7 @@ message Command {
|
||||
SetBootstrapToken set_bootstrap_token = 37;
|
||||
SetRecoveryLock set_recovery_lock = 38;
|
||||
VerifyRecoveryLock verify_recovery_lock = 39;
|
||||
RefreshCellularPlans refresh_cellular_plans = 40;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,3 +452,7 @@ message ErrorChain {
|
||||
string error_domain = 3;
|
||||
int32 error_code = 4;
|
||||
}
|
||||
|
||||
message RefreshCellularPlans {
|
||||
string esim_server_url = 1;
|
||||
}
|
||||
|
||||
@@ -367,6 +367,15 @@ func (c *Command) MarshalJSON() ([]byte, error) {
|
||||
RotateFileVaultKey: c.RotateFileVaultKey,
|
||||
}
|
||||
return json.Marshal(&x)
|
||||
case "RefreshCellularPlans":
|
||||
var x = struct {
|
||||
RequestType string `json:"request_type"`
|
||||
*RefreshCellularPlans
|
||||
}{
|
||||
RequestType: c.RequestType,
|
||||
RefreshCellularPlans: c.RefreshCellularPlans,
|
||||
}
|
||||
return json.Marshal(&x)
|
||||
default:
|
||||
return nil, fmt.Errorf("mdm: unknown RequestType: %s", c.RequestType)
|
||||
}
|
||||
|
||||
@@ -343,6 +343,14 @@ func (c *Command) MarshalPlist() (interface{}, error) {
|
||||
RequestType: c.RequestType,
|
||||
RotateFileVaultKey: c.RotateFileVaultKey,
|
||||
}, nil
|
||||
case "RefreshCellularPlans":
|
||||
return &struct {
|
||||
RequestType string
|
||||
*RefreshCellularPlans
|
||||
}{
|
||||
RequestType: c.RequestType,
|
||||
RefreshCellularPlans: c.RefreshCellularPlans,
|
||||
}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("mdm: unknown command RequestType, %s", c.RequestType)
|
||||
}
|
||||
|
||||
@@ -403,6 +403,12 @@ func commandToProto(cmd *Command) (*mdmproto.Command, error) {
|
||||
},
|
||||
},
|
||||
}
|
||||
case "RefreshCellularPlans":
|
||||
cmdproto.Request = &mdmproto.Command_RefreshCellularPlans{
|
||||
RefreshCellularPlans: &mdmproto.RefreshCellularPlans{
|
||||
EsimServerUrl: cmd.RefreshCellularPlans.EsimServerUrl,
|
||||
},
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown command type %s", cmd.RequestType)
|
||||
}
|
||||
|
||||
@@ -138,6 +138,14 @@ func TestMarshalCommand(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Command: Command{
|
||||
RequestType: "RefreshCellularPlans",
|
||||
RefreshCellularPlans: &RefreshCellularPlans{
|
||||
EsimServerUrl: "example.server.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.Command.RequestType+"_json", func(t *testing.T) {
|
||||
@@ -500,6 +508,23 @@ func TestEndToEnd(t *testing.T) {
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "RefreshCellularPlans",
|
||||
requestBytes: []byte(
|
||||
`{"request_type":"RefreshCellularPlans","esim_server_url":"example.server.com"}`,
|
||||
),
|
||||
testFn: func(t *testing.T, parts endToEndParts) {
|
||||
needToSee := [][]byte{
|
||||
[]byte(`eSIMServerURL`),
|
||||
[]byte(`example.server.com`),
|
||||
}
|
||||
for _, b := range needToSee {
|
||||
if !bytes.Contains(parts.plistData, b) {
|
||||
t.Error(fmt.Sprintf("marshaled plist does not contain required bytes: '%s'", string(b)))
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -313,6 +313,13 @@ func (c *Command) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
c.RotateFileVaultKey = &payload
|
||||
return nil
|
||||
case "RefreshCellularPlans":
|
||||
var payload RefreshCellularPlans
|
||||
if err := json.Unmarshal(data, &payload); err != nil {
|
||||
return errors.Wrapf(err, "mdm: unmarshal %s command json", c.RequestType)
|
||||
}
|
||||
c.RefreshCellularPlans = &payload
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("mdm: unknown RequestType: %s", c.RequestType)
|
||||
}
|
||||
|
||||
@@ -297,6 +297,13 @@ func (c *Command) UnmarshalPlist(unmarshal func(i interface{}) error) error {
|
||||
}
|
||||
c.RotateFileVaultKey = &payload
|
||||
return nil
|
||||
case "RefreshCellularPlans":
|
||||
var payload RefreshCellularPlans
|
||||
if err := unmarshal(&payload); err != nil {
|
||||
return errors.Wrapf(err, "mdm: unmarshal %s command plist", requestType.RequestType)
|
||||
}
|
||||
c.RefreshCellularPlans = &payload
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("mdm: unknown RequestType: %s", requestType.RequestType)
|
||||
}
|
||||
|
||||
@@ -364,7 +364,11 @@ func protoToCommand(pb *mdmproto.Command) *Command {
|
||||
PrivateKeyExportPassword: fvunlock.GetPrivateKeyExportPassword(),
|
||||
},
|
||||
}
|
||||
|
||||
case "RefreshCellularPlans":
|
||||
pbc := pb.GetRefreshCellularPlans()
|
||||
cmd.RefreshCellularPlans = &RefreshCellularPlans{
|
||||
EsimServerUrl: pbc.GetEsimServerUrl(),
|
||||
}
|
||||
}
|
||||
return &cmd
|
||||
}
|
||||
|
||||
12
tools/api/commands/refresh_cellular_plans
Normal file
12
tools/api/commands/refresh_cellular_plans
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
source $MICROMDM_ENV_PATH
|
||||
endpoint="v1/commands"
|
||||
jq -n \
|
||||
--arg request_type "RefreshCellularPlans" \
|
||||
--arg udid "$1" \
|
||||
--arg esim_server_url $2 \
|
||||
'.udid = $udid
|
||||
|.esim_server_url = $esim_server_url
|
||||
|.request_type = $request_type
|
||||
'|\
|
||||
curl $CURL_OPTS -K <(cat <<< "-u micromdm:$API_TOKEN") "$SERVER_URL/$endpoint" -d@-
|
||||
Reference in New Issue
Block a user