func fetchUpdateCheck(server string, appID string, groupID string, clientID string, version string, debug bool) (*omaha.UpdateCheck, error) { client := &http.Client{} // TODO: Fill out the OS field correctly based on /etc/os-release request := omaha.NewRequest("lsb", "CoreOS", "", "") app := request.AddApp(fmt.Sprintf("{%s}", appID), version) app.AddUpdateCheck() app.MachineID = clientID app.BootId = uuid.New() app.Track = groupID event := app.AddEvent() event.Type = "1" event.Result = "0" raw, err := xml.MarshalIndent(request, "", " ") if err != nil { fmt.Fprintln(os.Stderr, err) return nil, err } if debug { fmt.Fprintf(os.Stderr, "Request: %s%s\n", xml.Header, raw) } resp, err := client.Post(server+"/v1/update/", "text/xml", bytes.NewReader(raw)) if err != nil { fmt.Fprintln(os.Stderr, err) return nil, err } body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Fprintln(os.Stderr, err) return nil, err } if debug { fmt.Fprintf(os.Stderr, "Response: %s%s\n", xml.Header, string(body)) } oresp := &omaha.Response{} err = xml.Unmarshal(body, oresp) if err != nil { fmt.Fprintln(os.Stderr, err) return nil, err } return oresp.Apps[0].UpdateCheck, nil }
func (c *Client) OmahaRequest(otype, result string, updateCheck, isPing bool) *omaha.Request { req := omaha.NewRequest("lsb", "CoreOS", "", "") app := req.AddApp(c.AppId, c.Version) app.MachineID = c.Id app.BootId = c.SessionId app.Track = c.Track app.OEM = instanceFlags.OEM if c.forceUpdate { req.InstallSource = "ondemandupdate" } else { req.InstallSource = "scheduler" } if updateCheck { app.AddUpdateCheck() } if isPing { app.AddPing() app.Ping.LastReportDays = "1" app.Ping.Status = "1" } if otype != "" { event := app.AddEvent() event.Type = otype event.Result = result if result == "0" { event.ErrorCode = "2000" } else { event.ErrorCode = "" } } return req }