Add --check flag to mdmproxy (#21094)
This can be used to check the migration status for a given UDID. See the README updates for more.
This commit is contained in:
@@ -25,4 +25,18 @@ Usage of ./mdmproxy:
|
||||
### Example invocation
|
||||
```
|
||||
mdmproxy --migrate-udids '' --auth-token foo --existing-url https://3.14.233.249 --existing-hostname micromdm.example.com --fleet-url https://example.cloud.fleetdm.com --migrate-percentage 0
|
||||
```
|
||||
```
|
||||
|
||||
### Check migration status
|
||||
|
||||
To check the migration status for a given UDID, provide the `--migrate-udids` and
|
||||
`--migrate-percentage` flags with the `--check` flag:
|
||||
|
||||
```
|
||||
$ go run . --migrate-percentage=50 --check E5C6DBBA-D5CC-4DB6-9560-995F17FB7A59
|
||||
E5C6DBBA-D5CC-4DB6-9560-995F17FB7A59 IS NOT migrated
|
||||
$ go run . --migrate-percentage=50 --check 575424CB-09D7-4CAD-8A7A-D3511FE8A7E2
|
||||
575424CB-09D7-4CAD-8A7A-D3511FE8A7E2 IS migrated
|
||||
```
|
||||
|
||||
When the `--check` flag is used, the program prints the migration status and exits. The server is not started.
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -321,35 +322,13 @@ func main() {
|
||||
serverAddr := flag.String("server-address", ":8080", "Address for server to listen on")
|
||||
debug := flag.Bool("debug", false, "Enable debug logging")
|
||||
logSkipped := flag.Bool("log-skipped", false, "Log skipped requests (usually from web scanners)")
|
||||
check := flag.String("check", "", "Print whether the specified UDID is migrated with the current configuration, then exit")
|
||||
flag.Parse()
|
||||
|
||||
// Check required flags
|
||||
if *existingURL == "" {
|
||||
log.Fatal("--existing-url must be set")
|
||||
}
|
||||
if *existingHostname == "" {
|
||||
log.Fatal("--existing-hostname must be set")
|
||||
}
|
||||
if *fleetURL == "" {
|
||||
log.Fatal("--fleet-url must be set")
|
||||
}
|
||||
|
||||
udids, err := processUDIDs(bytes.NewBufferString(*migrateUDIDs))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Printf("--migrate-udids set: %v", udids)
|
||||
log.Printf("--migrate-percentage set: %d", *migratePercentage)
|
||||
log.Printf("--existing-url set: %s", *existingURL)
|
||||
log.Printf("--existing-hostname set: %s", *existingHostname)
|
||||
log.Printf("--fleet-url set: %s", *fleetURL)
|
||||
log.Printf("--debug set: %v", *debug)
|
||||
log.Printf("--log-skipped set: %v", *logSkipped)
|
||||
if *authToken != "" {
|
||||
log.Printf("--auth-token set. Remote configuration enabled.")
|
||||
} else {
|
||||
log.Printf("--auth-token is empty. Remote configuration disabled.")
|
||||
}
|
||||
|
||||
proxy := mdmProxy{
|
||||
token: *authToken,
|
||||
@@ -364,6 +343,39 @@ func main() {
|
||||
logSkipped: *logSkipped,
|
||||
}
|
||||
|
||||
if len(*check) > 0 {
|
||||
if proxy.isUDIDMigrated(*check) {
|
||||
fmt.Printf("%s IS migrated\n", *check)
|
||||
} else {
|
||||
fmt.Printf("%s IS NOT migrated\n", *check)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Check required flags
|
||||
if *existingURL == "" {
|
||||
log.Fatal("--existing-url must be set")
|
||||
}
|
||||
if *existingHostname == "" {
|
||||
log.Fatal("--existing-hostname must be set")
|
||||
}
|
||||
if *fleetURL == "" {
|
||||
log.Fatal("--fleet-url must be set")
|
||||
}
|
||||
|
||||
log.Printf("--migrate-udids set: %v", udids)
|
||||
log.Printf("--migrate-percentage set: %d", *migratePercentage)
|
||||
log.Printf("--existing-url set: %s", *existingURL)
|
||||
log.Printf("--existing-hostname set: %s", *existingHostname)
|
||||
log.Printf("--fleet-url set: %s", *fleetURL)
|
||||
log.Printf("--debug set: %v", *debug)
|
||||
log.Printf("--log-skipped set: %v", *logSkipped)
|
||||
if *authToken != "" {
|
||||
log.Printf("--auth-token set. Remote configuration enabled.")
|
||||
} else {
|
||||
log.Printf("--auth-token is empty. Remote configuration disabled.")
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
// Health check endpoint used for load balancers
|
||||
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user