func originFromAPI(apiRec params.LogStreamRecord, controllerUUID string) (logfwd.Origin, error) { var origin logfwd.Origin tag, err := names.ParseTag(apiRec.Entity) if err != nil { return origin, errors.Annotate(err, "invalid entity") } ver, err := version.Parse(apiRec.Version) if err != nil { return origin, errors.Annotatef(err, "invalid version %q", apiRec.Version) } switch tag := tag.(type) { case names.MachineTag: origin = logfwd.OriginForMachineAgent(tag, controllerUUID, apiRec.ModelUUID, ver) case names.UnitTag: origin = logfwd.OriginForUnitAgent(tag, controllerUUID, apiRec.ModelUUID, ver) default: origin, err = logfwd.OriginForJuju(tag, controllerUUID, apiRec.ModelUUID, ver) if err != nil { return origin, errors.Annotate(err, "could not extract origin") } } return origin, nil }
func (s *OriginSuite) TestOriginForJuju(c *gc.C) { tag := names.NewUserTag("bob") origin, err := logfwd.OriginForJuju(tag, validOrigin.ControllerUUID, validOrigin.ModelUUID, validOrigin.Software.Version) c.Assert(err, jc.ErrorIsNil) c.Check(origin, jc.DeepEquals, logfwd.Origin{ ControllerUUID: validOrigin.ControllerUUID, ModelUUID: validOrigin.ModelUUID, Hostname: "", Type: logfwd.OriginTypeUser, Name: "bob", Software: logfwd.Software{ PrivateEnterpriseNumber: 28978, Name: "juju", Version: version.MustParse("2.0.1"), }, }) }