update generate blueprint command to print to stdout (#173)

For #162

* add applyAt
This commit is contained in:
Victor Vrantchan
2017-05-28 12:56:24 -04:00
committed by GitHub
parent 0a5bd31694
commit 5b18fa6a2f

View File

@@ -3,7 +3,6 @@ package main
import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
"io/ioutil"
@@ -15,6 +14,7 @@ import (
"github.com/micromdm/micromdm/blueprint"
"github.com/micromdm/micromdm/core/apply"
"github.com/micromdm/micromdm/profile"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
)
@@ -89,16 +89,36 @@ Examples:
func (cmd *applyCommand) applyBlueprint(args []string) error {
flagset := flag.NewFlagSet("blueprints", flag.ExitOnError)
var (
flBlueprintPath = flagset.String("f", "", "filename of blueprint JSON to apply")
flNewBlueprintPath = flagset.String("generate-blueprint", "", "filename of new template blueprint JSON to create")
flBlueprintPath = flagset.String("f", "", "filename of blueprint JSON to apply")
flTemplate = flagset.Bool("template", false, "print a new blueprint template")
)
flagset.Usage = usageFor(flagset, "mdmctl apply blueprints [flags]")
if err := flagset.Parse(args); err != nil {
return err
}
if *flBlueprintPath == "" && *flNewBlueprintPath == "" {
return errors.New("must provide -f or -generate-blueprint parameter")
if *flTemplate {
newBlueprint := &blueprint.Blueprint{
Name: "exampleName",
UUID: uuid.NewV4().String(),
ApplicationURLs: []string{cmd.config.ServerURL + "repo/exampleAppManifest.plist"},
ProfileIdentifiers: []string{"com.example.my.profile"},
ApplyAt: []string{"Enroll"},
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
if err := enc.Encode(newBlueprint); err != nil {
return errors.Wrap(err, "encode blueprint template")
}
return nil
}
if *flBlueprintPath == "" {
flagset.Usage()
return errors.New("bad input: must provide -f flag")
}
if *flBlueprintPath != "" {
if _, err := os.Stat(*flBlueprintPath); os.IsNotExist(err) {
return err
@@ -120,28 +140,7 @@ func (cmd *applyCommand) applyBlueprint(args []string) error {
fmt.Println("applied blueprint", *flBlueprintPath)
return nil
}
if *flNewBlueprintPath != "" {
newBlueprintFile, err := os.Create(*flNewBlueprintPath)
if err != nil {
return err
}
defer newBlueprintFile.Close()
newBlueprint := new(blueprint.Blueprint)
newBlueprint.Name = "exampleName"
newBlueprint.UUID = uuid.NewV4().String()
newBlueprint.ApplicationURLs = []string{cmd.config.ServerURL + "repo/exampleAppManifest.plist"}
newBlueprint.ProfileIdentifiers = []string{"com.example.my.profile"}
enc := json.NewEncoder(newBlueprintFile)
enc.SetIndent("", " ")
err = enc.Encode(newBlueprint)
if err != nil {
return err
}
fmt.Println("wrote", *flNewBlueprintPath)
}
return nil
}
@@ -209,6 +208,6 @@ func (cmd *applyCommand) applyProfile(args []string) error {
return err
}
fmt.Println(fmt.Sprintf("applied blueprint id %s from %s", p.Identifier, *flProfilePath))
fmt.Printf("applied profile id %s from %s\n", p.Identifier, *flProfilePath)
return nil
}