Exemplo n.º 1
0
func (h *Handler) buildOmahaResponse(omahaReq *omahaSpec.Request, ip string) (*omahaSpec.Response, error) {
	omahaResp := omahaSpec.NewResponse("coreroller")

	for _, reqApp := range omahaReq.Apps {
		respApp := omahaResp.AddApp(reqApp.Id)
		respApp.Status = "ok"
		respApp.Track = reqApp.Track
		respApp.Version = reqApp.Version

		// Use Track field as the group to ask CR for updates. For the CoreOS
		// app, map group name to its id if available.
		group := reqApp.Track
		if reqAppUUID, err := uuid.FromString(reqApp.Id); err == nil {
			if reqAppUUID.String() == coreosAppID {
				if coreosGroupID, ok := coreosGroups[group]; ok {
					group = coreosGroupID
				}
			}
		}

		if reqApp.Events != nil {
			for _, event := range reqApp.Events {
				if err := h.processEvent(reqApp.MachineID, reqApp.Id, group, event); err != nil {
					logger.Warn("processEvent", "error", err.Error())
				}
				respEvent := respApp.AddEvent()
				respEvent.Status = "ok"
			}
		}

		if reqApp.Ping != nil {
			if _, err := h.crApi.RegisterInstance(reqApp.MachineID, ip, reqApp.Version, reqApp.Id, group); err != nil {
				logger.Warn("processPing", "error", err.Error())
			}
			respPing := respApp.AddPing()
			respPing.Status = "ok"
		}

		if reqApp.UpdateCheck != nil {
			pkg, err := h.crApi.GetUpdatePackage(reqApp.MachineID, ip, reqApp.Version, reqApp.Id, group)
			if err != nil && err != api.ErrNoUpdatePackageAvailable {
				respApp.Status = h.getStatusMessage(err)
			} else {
				respApp.UpdateCheck = h.prepareUpdateCheck(pkg)
			}
		}
	}

	return omahaResp, nil
}
Exemplo n.º 2
0
func buildOmahaResponse(a *api.API, omahaReq *omahaSpec.Request, ip string) (*omahaSpec.Response, error) {
	omahaResp := omahaSpec.NewResponse("coreroller")

	for _, reqApp := range omahaReq.Apps {

		respApp := omahaResp.AddApp(reqApp.Id)
		respApp.Status = "ok"

		// Let's add the track and version again in the response (as we got from request)
		respApp.Track = reqApp.Track
		respApp.Version = reqApp.Version

		// Get group
		group := getGroup(reqApp.Id, reqApp.Track)

		// If it has an event tag, we process it first.
		if reqApp.Events != nil {
			for _, event := range reqApp.Events {
				if err := processEvent(a, reqApp.MachineID, reqApp.Id, group, event); err != nil {
					logger.Warn("processEvent", "error", err.Error())
				}
				// Always acknowledge the event
				respEvent := respApp.AddEvent()
				respEvent.Status = "ok"
			}
		}

		// If it has an updatechek tag
		if reqApp.UpdateCheck != nil {
			appPackage, err := a.GetUpdatePackage(reqApp.MachineID, ip, reqApp.Version, reqApp.Id, group)
			if err != nil && err != api.ErrNoUpdatePackageAvailable {
				// If there is an error, we return it
				respApp.Status = getStatusMesssageFromRollerdResponse(err)
			} else {
				u := respApp.AddUpdateCheck()
				processUpdateCheck(a, appPackage, u)
			}
		}
	}

	return omahaResp, nil
}