forked from micromdm/micromdm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_dep_profiles.go
96 lines (83 loc) · 2.21 KB
/
get_dep_profiles.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"os"
"strings"
"text/tabwriter"
)
type depProfilesTableOutput struct{ w *tabwriter.Writer }
func (out *depProfilesTableOutput) BasicHeader() {
fmt.Fprintf(out.w, "Name\tMandatory\tRemovable\tAwaitConfigured\tSkippedItems\n")
}
func (out *depProfilesTableOutput) BasicFooter() {
out.w.Flush()
}
const noUUIDText = `The DEP API does not support listing profiles.
A UUID flag must be specified. To get currently assigned profile UUIDs run
mdmctl get dep-devices -serials=serial1,serial2,serial3
The output of the dep-devices response will contain the profile UUIDs.
`
func (cmd *getCommand) getDEPProfiles(args []string) error {
flagset := flag.NewFlagSet("dep-profiles", flag.ExitOnError)
var (
flProfilePath = flagset.String("f", "", "filename of DEP profile to apply")
flUUID = flagset.String("uuid", "", "DEP Profile UUID(required)")
)
flagset.Usage = usageFor(flagset, "mdmctl get dep-profiles [flags]")
if err := flagset.Parse(args); err != nil {
return err
}
if *flUUID == "" {
fmt.Println(noUUIDText)
flagset.Usage()
os.Exit(1)
}
ctx := context.Background()
resp, err := cmd.list.GetDEPProfile(ctx, *flUUID)
if err != nil {
return err
}
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
}