// NewFactory returns a Factory capable of creating execution contexts backed // by the supplied unit's supplied API connection. func NewFactory( state *uniter.State, unitTag names.UnitTag, tracker leadership.Tracker, getRelationInfos RelationsFunc, storage StorageContextAccessor, paths Paths, ) ( Factory, error, ) { unit, err := state.Unit(unitTag) if err != nil { return nil, errors.Trace(err) } service, err := state.Service(unit.ServiceTag()) if err != nil { return nil, errors.Trace(err) } ownerTag, err := service.OwnerTag() if err != nil { return nil, errors.Trace(err) } machineTag, err := unit.AssignedMachine() if err != nil { return nil, errors.Trace(err) } environment, err := state.Environment() if err != nil { return nil, errors.Trace(err) } return &factory{ unit: unit, state: state, tracker: tracker, paths: paths, envUUID: environment.UUID(), envName: environment.Name(), machineTag: machineTag, ownerTag: ownerTag, getRelationInfos: getRelationInfos, relationCaches: map[int]*RelationCache{}, storage: storage, rand: rand.New(rand.NewSource(time.Now().Unix())), }, nil }