mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-12 04:55:39 +08:00
Make DEP profile CLI like profiles and blueprints (#195)
This commit is contained in:
committed by
Victor Vrantchan
parent
b1a26b7761
commit
b3a600c5bc
@@ -66,17 +66,25 @@ func (cmd *applyCommand) applyDEPProfile(args []string) error {
|
||||
|
||||
if *flProfilePath == "" {
|
||||
flagset.Usage()
|
||||
return errors.New("bad input: must provide -f parameter")
|
||||
return errors.New("bad input: must provide -f or -template parameter ")
|
||||
}
|
||||
|
||||
pf, err := os.Open(*flProfilePath)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "opening DEP profile file")
|
||||
var output *os.File
|
||||
{
|
||||
if *flProfilePath == "-" {
|
||||
output = os.Stdin
|
||||
} else {
|
||||
var err error
|
||||
output, err = os.Open(*flProfilePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer output.Close()
|
||||
}
|
||||
}
|
||||
defer pf.Close()
|
||||
|
||||
var profile dep.Profile
|
||||
if err := json.NewDecoder(pf).Decode(&profile); err != nil {
|
||||
if err := json.NewDecoder(output).Decode(&profile); err != nil {
|
||||
return errors.Wrap(err, "decode DEP Profile JSON")
|
||||
}
|
||||
|
||||
@@ -108,8 +116,7 @@ func printDEPProfileTemplate(anchorCerts []*x509.Certificate) error {
|
||||
anchorCertStr = string(jsonBytes)
|
||||
}
|
||||
|
||||
resp := fmt.Sprintf(`
|
||||
{
|
||||
resp := fmt.Sprintf(`{
|
||||
"profile_name": "(Required) Human readable name",
|
||||
"url": "https://mymdm.example.org/mdm/enroll",
|
||||
"allow_pairing": true,
|
||||
@@ -126,8 +133,7 @@ func printDEPProfileTemplate(anchorCerts []*x509.Certificate) error {
|
||||
"skip_setup_items": ["AppleID", "Android"],
|
||||
"department": "(Optional) support@example.com",
|
||||
"devices": ["SERIAL1","SERIAL2"]
|
||||
}
|
||||
`, anchorCertStr)
|
||||
}`, anchorCertStr)
|
||||
fmt.Println(resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -21,27 +22,61 @@ func (out *depProfilesTableOutput) BasicFooter() {
|
||||
|
||||
func (cmd *getCommand) getDEPProfiles(args []string) error {
|
||||
flagset := flag.NewFlagSet("dep-profiles", flag.ExitOnError)
|
||||
flProfilePath := flagset.String("f", "", "filename of DEP profile to apply")
|
||||
flUUID := flagset.String("uuid", "", "DEP Profile UUID")
|
||||
flagset.Usage = usageFor(flagset, "mdmctl get dep-profiles [flags]")
|
||||
if err := flagset.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
w := tabwriter.NewWriter(os.Stderr, 0, 4, 2, ' ', 0)
|
||||
out := &depProfilesTableOutput{w}
|
||||
out.BasicHeader()
|
||||
defer out.BasicFooter()
|
||||
|
||||
ctx := context.Background()
|
||||
resp, err := cmd.list.GetDEPProfile(ctx, *flUUID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(out.w, "%s\t%v\t%v\t%v\t%s\n",
|
||||
resp.ProfileName,
|
||||
resp.IsMandatory,
|
||||
resp.IsMDMRemovable,
|
||||
resp.AwaitDeviceConfigured,
|
||||
strings.Join(resp.SkipSetupItems, ","),
|
||||
)
|
||||
|
||||
if *flProfilePath == "" {
|
||||
w := tabwriter.NewWriter(os.Stderr, 0, 4, 2, ' ', 0)
|
||||
out := &depProfilesTableOutput{w}
|
||||
out.BasicHeader()
|
||||
defer out.BasicFooter()
|
||||
|
||||
fmt.Fprintf(out.w, "%s\t%v\t%v\t%v\t%s\n",
|
||||
resp.ProfileName,
|
||||
resp.IsMandatory,
|
||||
resp.IsMDMRemovable,
|
||||
resp.AwaitDeviceConfigured,
|
||||
strings.Join(resp.SkipSetupItems, ","),
|
||||
)
|
||||
} else {
|
||||
var output *os.File
|
||||
{
|
||||
if *flProfilePath == "-" {
|
||||
output = os.Stdout
|
||||
} else {
|
||||
var err error
|
||||
output, err = os.Create(*flProfilePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer output.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: perhaps we want to store the raw DEP profile for storage
|
||||
// as we may have problems with default/non-default values getting
|
||||
// omitted in the marshalled JSON
|
||||
enc := json.NewEncoder(output)
|
||||
enc.SetIndent("", " ")
|
||||
err = enc.Encode(resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if *flProfilePath != "-" {
|
||||
fmt.Printf("wrote DEP profile %s to: %s\n", *flUUID, *flProfilePath)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user